📄 xmlschemastypes.c.svn-base
字号:
/* * schemastypes.c : implementation of the XML Schema Datatypes * definition and validity checking * * See Copyright for the status of this software. * * Daniel Veillard <veillard@redhat.com> */#define IN_LIBXML#include "libxml.h"#ifdef LIBXML_SCHEMAS_ENABLED#include <string.h>#include <libxml/xmlmemory.h>#include <libxml/parser.h>#include <libxml/parserInternals.h>#include <libxml/hash.h>#include <libxml/valid.h>#include <libxml/xpath.h>#include <libxml/uri.h>#include <libxml/xmlschemas.h>#include <libxml/schemasInternals.h>#include <libxml/xmlschemastypes.h>#ifdef HAVE_MATH_H#include <math.h>#endif#define DEBUG#define TODO \ xmlGenericError(xmlGenericErrorContext, \ "Unimplemented block at %s:%d\n", \ __FILE__, __LINE__);#define XML_SCHEMAS_NAMESPACE_NAME \ (const xmlChar *)"http://www.w3.org/2001/XMLSchema"typedef enum { XML_SCHEMAS_UNKNOWN = 0, XML_SCHEMAS_STRING, XML_SCHEMAS_NORMSTRING, XML_SCHEMAS_DECIMAL, XML_SCHEMAS_TIME, XML_SCHEMAS_GDAY, XML_SCHEMAS_GMONTH, XML_SCHEMAS_GMONTHDAY, XML_SCHEMAS_GYEAR, XML_SCHEMAS_GYEARMONTH, XML_SCHEMAS_DATE, XML_SCHEMAS_DATETIME, XML_SCHEMAS_DURATION, XML_SCHEMAS_FLOAT, XML_SCHEMAS_DOUBLE, XML_SCHEMAS_BOOLEAN, XML_SCHEMAS_TOKEN, XML_SCHEMAS_LANGUAGE, XML_SCHEMAS_NMTOKEN, XML_SCHEMAS_NMTOKENS, XML_SCHEMAS_NAME, XML_SCHEMAS_QNAME, XML_SCHEMAS_NCNAME, XML_SCHEMAS_ID, XML_SCHEMAS_IDREF, XML_SCHEMAS_IDREFS, XML_SCHEMAS_ENTITY, XML_SCHEMAS_ENTITIES, XML_SCHEMAS_NOTATION, XML_SCHEMAS_ANYURI, XML_SCHEMAS_INTEGER, XML_SCHEMAS_NPINTEGER, XML_SCHEMAS_NINTEGER, XML_SCHEMAS_NNINTEGER, XML_SCHEMAS_PINTEGER, XML_SCHEMAS_INT, XML_SCHEMAS_UINT, XML_SCHEMAS_LONG, XML_SCHEMAS_ULONG, XML_SCHEMAS_SHORT, XML_SCHEMAS_USHORT, XML_SCHEMAS_BYTE, XML_SCHEMAS_UBYTE, XML_SCHEMAS_HEXBINARY, XML_SCHEMAS_BASE64BINARY} xmlSchemaValType;static unsigned long powten[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000L, 100000000L, 1000000000L};/* Date value */typedef struct _xmlSchemaValDate xmlSchemaValDate;typedef xmlSchemaValDate *xmlSchemaValDatePtr;struct _xmlSchemaValDate { long year; unsigned int mon :4; /* 1 <= mon <= 12 */ unsigned int day :5; /* 1 <= day <= 31 */ unsigned int hour :5; /* 0 <= hour <= 23 */ unsigned int min :6; /* 0 <= min <= 59 */ double sec; unsigned int tz_flag :1; /* is tzo explicitely set? */ int tzo :11; /* -1440 <= tzo <= 1440 */};/* Duration value */typedef struct _xmlSchemaValDuration xmlSchemaValDuration;typedef xmlSchemaValDuration *xmlSchemaValDurationPtr;struct _xmlSchemaValDuration { long mon; /* mon stores years also */ long day; double sec; /* sec stores min and hour also */};typedef struct _xmlSchemaValDecimal xmlSchemaValDecimal;typedef xmlSchemaValDecimal *xmlSchemaValDecimalPtr;struct _xmlSchemaValDecimal { /* would use long long but not portable */ unsigned long lo; unsigned long mi; unsigned long hi; unsigned int extra; unsigned int sign:1; unsigned int frac:7; unsigned int total:8;};typedef struct _xmlSchemaValQName xmlSchemaValQName;typedef xmlSchemaValQName *xmlSchemaValQNamePtr;struct _xmlSchemaValQName { xmlChar *name; xmlChar *uri;};typedef struct _xmlSchemaValHex xmlSchemaValHex;typedef xmlSchemaValHex *xmlSchemaValHexPtr;struct _xmlSchemaValHex { xmlChar *str; unsigned int total;};typedef struct _xmlSchemaValBase64 xmlSchemaValBase64;typedef xmlSchemaValBase64 *xmlSchemaValBase64Ptr;struct _xmlSchemaValBase64 { xmlChar *str; unsigned int total;};struct _xmlSchemaVal { xmlSchemaValType type; union { xmlSchemaValDecimal decimal; xmlSchemaValDate date; xmlSchemaValDuration dur; xmlSchemaValQName qname; xmlSchemaValHex hex; xmlSchemaValBase64 base64; float f; double d; int b; xmlChar *str; } value;};static int xmlSchemaTypesInitialized = 0;static xmlHashTablePtr xmlSchemaTypesBank = NULL;/* * Basic types */static xmlSchemaTypePtr xmlSchemaTypeStringDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeAnyTypeDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeAnySimpleTypeDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDecimalDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDatetimeDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDateDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeTimeDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGYearDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGYearMonthDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGDayDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGMonthDayDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeGMonthDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDurationDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeFloatDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeBooleanDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeDoubleDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeHexBinaryDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeBase64BinaryDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeAnyURIDef = NULL;/* * Derived types */static xmlSchemaTypePtr xmlSchemaTypePositiveIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNonPositiveIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNegativeIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNonNegativeIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIntegerDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeLongDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIntDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeShortDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeByteDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeUnsignedLongDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeUnsignedIntDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeUnsignedShortDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeUnsignedByteDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNormStringDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeTokenDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeLanguageDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNameDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeQNameDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNCNameDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIdDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIdrefDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeIdrefsDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeEntityDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeEntitiesDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNotationDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNmtokenDef = NULL;static xmlSchemaTypePtr xmlSchemaTypeNmtokensDef = NULL;/************************************************************************ * * * Datatype error handlers * * * ************************************************************************//** * xmlSchemaTypeErrMemory: * @extra: extra informations * * Handle an out of memory condition */static voidxmlSchemaTypeErrMemory(xmlNodePtr node, const char *extra){ __xmlSimpleError(XML_FROM_DATATYPE, XML_ERR_NO_MEMORY, node, NULL, extra);}/************************************************************************ * * * Base types support * * * ************************************************************************//* * xmlSchemaInitBasicType: * @name: the type name * @type: the value type associated * * Initialize one default type */static xmlSchemaTypePtrxmlSchemaInitBasicType(const char *name, xmlSchemaValType type) { xmlSchemaTypePtr ret; ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); if (ret == NULL) { xmlSchemaTypeErrMemory(NULL, "could not initialize basic types"); return(NULL); } memset(ret, 0, sizeof(xmlSchemaType)); ret->name = (const xmlChar *)name; ret->type = XML_SCHEMA_TYPE_BASIC; ret->flags = type; ret->contentType = XML_SCHEMA_CONTENT_BASIC; xmlHashAddEntry2(xmlSchemaTypesBank, ret->name, XML_SCHEMAS_NAMESPACE_NAME, ret); return(ret);}/* * xmlSchemaInitTypes: * * Initialize the default XML Schemas type library */voidxmlSchemaInitTypes(void){ if (xmlSchemaTypesInitialized != 0) return; xmlSchemaTypesBank = xmlHashCreate(40); /* * primitive datatypes */ xmlSchemaTypeStringDef = xmlSchemaInitBasicType("string", XML_SCHEMAS_STRING); xmlSchemaTypeAnyTypeDef = xmlSchemaInitBasicType("anyType", XML_SCHEMAS_UNKNOWN); xmlSchemaTypeAnySimpleTypeDef = xmlSchemaInitBasicType("anySimpleType", XML_SCHEMAS_UNKNOWN); xmlSchemaTypeDecimalDef = xmlSchemaInitBasicType("decimal", XML_SCHEMAS_DECIMAL); xmlSchemaTypeDateDef = xmlSchemaInitBasicType("date", XML_SCHEMAS_DATE); xmlSchemaTypeDatetimeDef = xmlSchemaInitBasicType("dateTime", XML_SCHEMAS_DATETIME); xmlSchemaTypeTimeDef = xmlSchemaInitBasicType("time", XML_SCHEMAS_TIME); xmlSchemaTypeGYearDef = xmlSchemaInitBasicType("gYear", XML_SCHEMAS_GYEAR); xmlSchemaTypeGYearMonthDef = xmlSchemaInitBasicType("gYearMonth", XML_SCHEMAS_GYEARMONTH); xmlSchemaTypeGMonthDef = xmlSchemaInitBasicType("gMonth", XML_SCHEMAS_GMONTH); xmlSchemaTypeGMonthDayDef = xmlSchemaInitBasicType("gMonthDay", XML_SCHEMAS_GMONTHDAY); xmlSchemaTypeGDayDef = xmlSchemaInitBasicType("gDay", XML_SCHEMAS_GDAY); xmlSchemaTypeDurationDef = xmlSchemaInitBasicType("duration", XML_SCHEMAS_DURATION); xmlSchemaTypeFloatDef = xmlSchemaInitBasicType("float", XML_SCHEMAS_FLOAT); xmlSchemaTypeDoubleDef = xmlSchemaInitBasicType("double", XML_SCHEMAS_DOUBLE); xmlSchemaTypeBooleanDef = xmlSchemaInitBasicType("boolean", XML_SCHEMAS_BOOLEAN); xmlSchemaTypeAnyURIDef = xmlSchemaInitBasicType("anyURI", XML_SCHEMAS_ANYURI); xmlSchemaTypeHexBinaryDef = xmlSchemaInitBasicType("hexBinary", XML_SCHEMAS_HEXBINARY); xmlSchemaTypeBase64BinaryDef = xmlSchemaInitBasicType("base64Binary", XML_SCHEMAS_BASE64BINARY); /* * derived datatypes */ xmlSchemaTypeIntegerDef = xmlSchemaInitBasicType("integer", XML_SCHEMAS_INTEGER);; xmlSchemaTypeNonPositiveIntegerDef = xmlSchemaInitBasicType("nonPositiveInteger", XML_SCHEMAS_NPINTEGER);; xmlSchemaTypeNegativeIntegerDef = xmlSchemaInitBasicType("negativeInteger", XML_SCHEMAS_NINTEGER);; xmlSchemaTypeLongDef = xmlSchemaInitBasicType("long", XML_SCHEMAS_LONG);; xmlSchemaTypeIntDef = xmlSchemaInitBasicType("int", XML_SCHEMAS_INT);; xmlSchemaTypeShortDef = xmlSchemaInitBasicType("short", XML_SCHEMAS_SHORT);; xmlSchemaTypeByteDef = xmlSchemaInitBasicType("byte", XML_SCHEMAS_BYTE);; xmlSchemaTypeNonNegativeIntegerDef = xmlSchemaInitBasicType("nonNegativeInteger", XML_SCHEMAS_NNINTEGER); xmlSchemaTypeUnsignedLongDef = xmlSchemaInitBasicType("unsignedLong", XML_SCHEMAS_ULONG);; xmlSchemaTypeUnsignedIntDef = xmlSchemaInitBasicType("unsignedInt", XML_SCHEMAS_UINT);; xmlSchemaTypeUnsignedShortDef = xmlSchemaInitBasicType("unsignedShort", XML_SCHEMAS_USHORT);; xmlSchemaTypeUnsignedByteDef = xmlSchemaInitBasicType("unsignedByte", XML_SCHEMAS_UBYTE);; xmlSchemaTypePositiveIntegerDef = xmlSchemaInitBasicType("positiveInteger", XML_SCHEMAS_PINTEGER); xmlSchemaTypeNormStringDef = xmlSchemaInitBasicType("normalizedString", XML_SCHEMAS_NORMSTRING); xmlSchemaTypeTokenDef = xmlSchemaInitBasicType("token", XML_SCHEMAS_TOKEN); xmlSchemaTypeLanguageDef = xmlSchemaInitBasicType("language", XML_SCHEMAS_LANGUAGE); xmlSchemaTypeIdDef = xmlSchemaInitBasicType("ID", XML_SCHEMAS_ID); xmlSchemaTypeIdrefDef = xmlSchemaInitBasicType("IDREF", XML_SCHEMAS_IDREF); xmlSchemaTypeIdrefsDef = xmlSchemaInitBasicType("IDREFS", XML_SCHEMAS_IDREFS); xmlSchemaTypeEntityDef = xmlSchemaInitBasicType("ENTITY", XML_SCHEMAS_ENTITY); xmlSchemaTypeEntitiesDef = xmlSchemaInitBasicType("ENTITIES", XML_SCHEMAS_ENTITIES); xmlSchemaTypeNotationDef = xmlSchemaInitBasicType("NOTATION", XML_SCHEMAS_NOTATION); xmlSchemaTypeNameDef = xmlSchemaInitBasicType("Name", XML_SCHEMAS_NAME); xmlSchemaTypeQNameDef = xmlSchemaInitBasicType("QName", XML_SCHEMAS_QNAME); xmlSchemaTypeNCNameDef = xmlSchemaInitBasicType("NCName", XML_SCHEMAS_NCNAME); xmlSchemaTypeNmtokenDef = xmlSchemaInitBasicType("NMTOKEN", XML_SCHEMAS_NMTOKEN); xmlSchemaTypeNmtokensDef = xmlSchemaInitBasicType("NMTOKENS", XML_SCHEMAS_NMTOKENS); xmlSchemaTypesInitialized = 1;}/** * xmlSchemaCleanupTypes: * * Cleanup the default XML Schemas type library */void xmlSchemaCleanupTypes(void) { if (xmlSchemaTypesInitialized == 0) return; xmlHashFree(xmlSchemaTypesBank, (xmlHashDeallocator) xmlSchemaFreeType); xmlSchemaTypesInitialized = 0;}/** * xmlSchemaNewValue: * @type: the value type * * Allocate a new simple type value * * Returns a pointer to the new value or NULL in case of error */static xmlSchemaValPtrxmlSchemaNewValue(xmlSchemaValType type) { xmlSchemaValPtr value; value = (xmlSchemaValPtr) xmlMalloc(sizeof(xmlSchemaVal)); if (value == NULL) { return(NULL); } memset(value, 0, sizeof(xmlSchemaVal)); value->type = type; return(value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -