Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * schemastypes.c : implementation of the XML Schema Datatypes |
| 3 | * definition and validity checking |
| 4 | * |
| 5 | * See Copyright for the status of this software. |
| 6 | * |
| 7 | * Daniel Veillard <veillard@redhat.com> |
| 8 | */ |
| 9 | |
| 10 | #define IN_LIBXML |
| 11 | #include "libxml.h" |
| 12 | |
| 13 | #ifdef LIBXML_SCHEMAS_ENABLED |
| 14 | |
| 15 | #include <string.h> |
| 16 | #include <libxml/xmlmemory.h> |
| 17 | #include <libxml/parser.h> |
| 18 | #include <libxml/parserInternals.h> |
| 19 | #include <libxml/hash.h> |
| 20 | #include <libxml/valid.h> |
Daniel Veillard | 96a4b25 | 2003-02-06 08:22:32 +0000 | [diff] [blame] | 21 | #include <libxml/xpath.h> |
| 22 | #include <libxml/uri.h> |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 23 | |
| 24 | #include <libxml/xmlschemas.h> |
| 25 | #include <libxml/schemasInternals.h> |
| 26 | #include <libxml/xmlschemastypes.h> |
| 27 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 28 | #ifdef HAVE_MATH_H |
| 29 | #include <math.h> |
| 30 | #endif |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 31 | #ifdef HAVE_FLOAT_H |
| 32 | #include <float.h> |
| 33 | #endif |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 34 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 35 | #define DEBUG |
| 36 | |
Daniel Veillard | d0cf7f6 | 2004-11-09 16:17:02 +0000 | [diff] [blame] | 37 | #ifndef LIBXML_XPATH_ENABLED |
| 38 | extern double xmlXPathNAN; |
| 39 | extern double xmlXPathPINF; |
| 40 | extern double xmlXPathNINF; |
| 41 | #endif |
| 42 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 43 | #define TODO \ |
| 44 | xmlGenericError(xmlGenericErrorContext, \ |
| 45 | "Unimplemented block at %s:%d\n", \ |
| 46 | __FILE__, __LINE__); |
| 47 | |
| 48 | #define XML_SCHEMAS_NAMESPACE_NAME \ |
| 49 | (const xmlChar *)"http://www.w3.org/2001/XMLSchema" |
| 50 | |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 51 | #define IS_WSP_REPLACE_CH(c) ((((c) == 0x9) || ((c) == 0xa)) || \ |
| 52 | ((c) == 0xd)) |
| 53 | |
| 54 | #define IS_WSP_SPACE_CH(c) ((c) == 0x20) |
| 55 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 56 | #define IS_WSP_BLANK_CH(c) IS_BLANK_CH(c) |
| 57 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 58 | /* Date value */ |
| 59 | typedef struct _xmlSchemaValDate xmlSchemaValDate; |
| 60 | typedef xmlSchemaValDate *xmlSchemaValDatePtr; |
| 61 | struct _xmlSchemaValDate { |
| 62 | long year; |
| 63 | unsigned int mon :4; /* 1 <= mon <= 12 */ |
| 64 | unsigned int day :5; /* 1 <= day <= 31 */ |
| 65 | unsigned int hour :5; /* 0 <= hour <= 23 */ |
| 66 | unsigned int min :6; /* 0 <= min <= 59 */ |
| 67 | double sec; |
Daniel Veillard | a77cf71 | 2003-05-09 23:09:55 +0000 | [diff] [blame] | 68 | unsigned int tz_flag :1; /* is tzo explicitely set? */ |
Kasimier T. Buchcik | 285b367 | 2005-05-12 13:10:22 +0000 | [diff] [blame] | 69 | signed int tzo :12; /* -1440 <= tzo <= 1440; |
| 70 | currently only -840 to +840 are needed */ |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | /* Duration value */ |
| 74 | typedef struct _xmlSchemaValDuration xmlSchemaValDuration; |
| 75 | typedef xmlSchemaValDuration *xmlSchemaValDurationPtr; |
| 76 | struct _xmlSchemaValDuration { |
| 77 | long mon; /* mon stores years also */ |
| 78 | long day; |
| 79 | double sec; /* sec stores min and hour also */ |
| 80 | }; |
| 81 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 82 | typedef struct _xmlSchemaValDecimal xmlSchemaValDecimal; |
| 83 | typedef xmlSchemaValDecimal *xmlSchemaValDecimalPtr; |
| 84 | struct _xmlSchemaValDecimal { |
| 85 | /* would use long long but not portable */ |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 86 | unsigned long lo; |
| 87 | unsigned long mi; |
| 88 | unsigned long hi; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 89 | unsigned int extra; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 90 | unsigned int sign:1; |
William M. Brack | c193956 | 2003-08-05 15:52:22 +0000 | [diff] [blame] | 91 | unsigned int frac:7; |
| 92 | unsigned int total:8; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 95 | typedef struct _xmlSchemaValQName xmlSchemaValQName; |
| 96 | typedef xmlSchemaValQName *xmlSchemaValQNamePtr; |
| 97 | struct _xmlSchemaValQName { |
| 98 | xmlChar *name; |
| 99 | xmlChar *uri; |
| 100 | }; |
| 101 | |
Daniel Veillard | 70bcb0e | 2003-08-08 14:00:28 +0000 | [diff] [blame] | 102 | typedef struct _xmlSchemaValHex xmlSchemaValHex; |
| 103 | typedef xmlSchemaValHex *xmlSchemaValHexPtr; |
| 104 | struct _xmlSchemaValHex { |
| 105 | xmlChar *str; |
| 106 | unsigned int total; |
| 107 | }; |
| 108 | |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 109 | typedef struct _xmlSchemaValBase64 xmlSchemaValBase64; |
| 110 | typedef xmlSchemaValBase64 *xmlSchemaValBase64Ptr; |
| 111 | struct _xmlSchemaValBase64 { |
| 112 | xmlChar *str; |
| 113 | unsigned int total; |
| 114 | }; |
| 115 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 116 | struct _xmlSchemaVal { |
| 117 | xmlSchemaValType type; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 118 | struct _xmlSchemaVal *next; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 119 | union { |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 120 | xmlSchemaValDecimal decimal; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 121 | xmlSchemaValDate date; |
| 122 | xmlSchemaValDuration dur; |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 123 | xmlSchemaValQName qname; |
Daniel Veillard | 70bcb0e | 2003-08-08 14:00:28 +0000 | [diff] [blame] | 124 | xmlSchemaValHex hex; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 125 | xmlSchemaValBase64 base64; |
Daniel Veillard | 84d70a4 | 2002-09-16 10:51:38 +0000 | [diff] [blame] | 126 | float f; |
| 127 | double d; |
Daniel Veillard | c5a70f2 | 2003-02-06 23:41:59 +0000 | [diff] [blame] | 128 | int b; |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 129 | xmlChar *str; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 130 | } value; |
| 131 | }; |
| 132 | |
| 133 | static int xmlSchemaTypesInitialized = 0; |
| 134 | static xmlHashTablePtr xmlSchemaTypesBank = NULL; |
| 135 | |
Daniel Veillard | c6e997c | 2003-01-27 12:35:42 +0000 | [diff] [blame] | 136 | /* |
| 137 | * Basic types |
| 138 | */ |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 139 | static xmlSchemaTypePtr xmlSchemaTypeStringDef = NULL; |
| 140 | static xmlSchemaTypePtr xmlSchemaTypeAnyTypeDef = NULL; |
| 141 | static xmlSchemaTypePtr xmlSchemaTypeAnySimpleTypeDef = NULL; |
| 142 | static xmlSchemaTypePtr xmlSchemaTypeDecimalDef = NULL; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 143 | static xmlSchemaTypePtr xmlSchemaTypeDatetimeDef = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 144 | static xmlSchemaTypePtr xmlSchemaTypeDateDef = NULL; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 145 | static xmlSchemaTypePtr xmlSchemaTypeTimeDef = NULL; |
| 146 | static xmlSchemaTypePtr xmlSchemaTypeGYearDef = NULL; |
| 147 | static xmlSchemaTypePtr xmlSchemaTypeGYearMonthDef = NULL; |
| 148 | static xmlSchemaTypePtr xmlSchemaTypeGDayDef = NULL; |
| 149 | static xmlSchemaTypePtr xmlSchemaTypeGMonthDayDef = NULL; |
| 150 | static xmlSchemaTypePtr xmlSchemaTypeGMonthDef = NULL; |
| 151 | static xmlSchemaTypePtr xmlSchemaTypeDurationDef = NULL; |
Daniel Veillard | 84d70a4 | 2002-09-16 10:51:38 +0000 | [diff] [blame] | 152 | static xmlSchemaTypePtr xmlSchemaTypeFloatDef = NULL; |
Daniel Veillard | c5a70f2 | 2003-02-06 23:41:59 +0000 | [diff] [blame] | 153 | static xmlSchemaTypePtr xmlSchemaTypeBooleanDef = NULL; |
Daniel Veillard | 84d70a4 | 2002-09-16 10:51:38 +0000 | [diff] [blame] | 154 | static xmlSchemaTypePtr xmlSchemaTypeDoubleDef = NULL; |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 155 | static xmlSchemaTypePtr xmlSchemaTypeHexBinaryDef = NULL; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 156 | static xmlSchemaTypePtr xmlSchemaTypeBase64BinaryDef = NULL; |
Daniel Veillard | e5b110b | 2003-02-04 14:43:39 +0000 | [diff] [blame] | 157 | static xmlSchemaTypePtr xmlSchemaTypeAnyURIDef = NULL; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 158 | |
| 159 | /* |
Daniel Veillard | c6e997c | 2003-01-27 12:35:42 +0000 | [diff] [blame] | 160 | * Derived types |
| 161 | */ |
| 162 | static xmlSchemaTypePtr xmlSchemaTypePositiveIntegerDef = NULL; |
| 163 | static xmlSchemaTypePtr xmlSchemaTypeNonPositiveIntegerDef = NULL; |
| 164 | static xmlSchemaTypePtr xmlSchemaTypeNegativeIntegerDef = NULL; |
| 165 | static xmlSchemaTypePtr xmlSchemaTypeNonNegativeIntegerDef = NULL; |
| 166 | static xmlSchemaTypePtr xmlSchemaTypeIntegerDef = NULL; |
| 167 | static xmlSchemaTypePtr xmlSchemaTypeLongDef = NULL; |
| 168 | static xmlSchemaTypePtr xmlSchemaTypeIntDef = NULL; |
| 169 | static xmlSchemaTypePtr xmlSchemaTypeShortDef = NULL; |
| 170 | static xmlSchemaTypePtr xmlSchemaTypeByteDef = NULL; |
| 171 | static xmlSchemaTypePtr xmlSchemaTypeUnsignedLongDef = NULL; |
| 172 | static xmlSchemaTypePtr xmlSchemaTypeUnsignedIntDef = NULL; |
| 173 | static xmlSchemaTypePtr xmlSchemaTypeUnsignedShortDef = NULL; |
| 174 | static xmlSchemaTypePtr xmlSchemaTypeUnsignedByteDef = NULL; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 175 | static xmlSchemaTypePtr xmlSchemaTypeNormStringDef = NULL; |
| 176 | static xmlSchemaTypePtr xmlSchemaTypeTokenDef = NULL; |
| 177 | static xmlSchemaTypePtr xmlSchemaTypeLanguageDef = NULL; |
| 178 | static xmlSchemaTypePtr xmlSchemaTypeNameDef = NULL; |
| 179 | static xmlSchemaTypePtr xmlSchemaTypeQNameDef = NULL; |
Daniel Veillard | e5b110b | 2003-02-04 14:43:39 +0000 | [diff] [blame] | 180 | static xmlSchemaTypePtr xmlSchemaTypeNCNameDef = NULL; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 181 | static xmlSchemaTypePtr xmlSchemaTypeIdDef = NULL; |
| 182 | static xmlSchemaTypePtr xmlSchemaTypeIdrefDef = NULL; |
| 183 | static xmlSchemaTypePtr xmlSchemaTypeIdrefsDef = NULL; |
Daniel Veillard | a1a9d04 | 2003-03-18 16:53:17 +0000 | [diff] [blame] | 184 | static xmlSchemaTypePtr xmlSchemaTypeEntityDef = NULL; |
| 185 | static xmlSchemaTypePtr xmlSchemaTypeEntitiesDef = NULL; |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 186 | static xmlSchemaTypePtr xmlSchemaTypeNotationDef = NULL; |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 187 | static xmlSchemaTypePtr xmlSchemaTypeNmtokenDef = NULL; |
| 188 | static xmlSchemaTypePtr xmlSchemaTypeNmtokensDef = NULL; |
Daniel Veillard | c6e997c | 2003-01-27 12:35:42 +0000 | [diff] [blame] | 189 | |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 190 | /************************************************************************ |
| 191 | * * |
| 192 | * Datatype error handlers * |
| 193 | * * |
| 194 | ************************************************************************/ |
| 195 | /** |
| 196 | * xmlSchemaTypeErrMemory: |
| 197 | * @extra: extra informations |
| 198 | * |
| 199 | * Handle an out of memory condition |
| 200 | */ |
| 201 | static void |
| 202 | xmlSchemaTypeErrMemory(xmlNodePtr node, const char *extra) |
| 203 | { |
| 204 | __xmlSimpleError(XML_FROM_DATATYPE, XML_ERR_NO_MEMORY, node, NULL, extra); |
| 205 | } |
| 206 | |
| 207 | /************************************************************************ |
| 208 | * * |
| 209 | * Base types support * |
| 210 | * * |
| 211 | ************************************************************************/ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 212 | |
| 213 | /** |
| 214 | * xmlSchemaNewValue: |
| 215 | * @type: the value type |
| 216 | * |
| 217 | * Allocate a new simple type value |
| 218 | * |
| 219 | * Returns a pointer to the new value or NULL in case of error |
| 220 | */ |
| 221 | static xmlSchemaValPtr |
| 222 | xmlSchemaNewValue(xmlSchemaValType type) { |
| 223 | xmlSchemaValPtr value; |
| 224 | |
| 225 | value = (xmlSchemaValPtr) xmlMalloc(sizeof(xmlSchemaVal)); |
| 226 | if (value == NULL) { |
| 227 | return(NULL); |
| 228 | } |
| 229 | memset(value, 0, sizeof(xmlSchemaVal)); |
| 230 | value->type = type; |
| 231 | return(value); |
| 232 | } |
| 233 | |
| 234 | static xmlSchemaFacetPtr |
| 235 | xmlSchemaNewMinLengthFacet(int value) |
| 236 | { |
| 237 | xmlSchemaFacetPtr ret; |
| 238 | |
| 239 | ret = xmlSchemaNewFacet(); |
| 240 | ret->type = XML_SCHEMA_FACET_MINLENGTH; |
| 241 | ret->val = xmlSchemaNewValue(XML_SCHEMAS_NNINTEGER); |
| 242 | ret->val->value.decimal.lo = value; |
| 243 | return (ret); |
| 244 | } |
| 245 | |
Daniel Veillard | c6e997c | 2003-01-27 12:35:42 +0000 | [diff] [blame] | 246 | /* |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 247 | * xmlSchemaInitBasicType: |
| 248 | * @name: the type name |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 249 | * @type: the value type associated |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 250 | * |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 251 | * Initialize one primitive built-in type |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 252 | */ |
| 253 | static xmlSchemaTypePtr |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 254 | xmlSchemaInitBasicType(const char *name, xmlSchemaValType type, |
| 255 | xmlSchemaTypePtr baseType) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 256 | xmlSchemaTypePtr ret; |
| 257 | |
| 258 | ret = (xmlSchemaTypePtr) xmlMalloc(sizeof(xmlSchemaType)); |
| 259 | if (ret == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 260 | xmlSchemaTypeErrMemory(NULL, "could not initialize basic types"); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 261 | return(NULL); |
| 262 | } |
| 263 | memset(ret, 0, sizeof(xmlSchemaType)); |
Daniel Veillard | be9c632 | 2003-11-22 20:37:51 +0000 | [diff] [blame] | 264 | ret->name = (const xmlChar *)name; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 265 | ret->targetNamespace = XML_SCHEMAS_NAMESPACE_NAME; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 266 | ret->type = XML_SCHEMA_TYPE_BASIC; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 267 | ret->baseType = baseType; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 268 | ret->contentType = XML_SCHEMA_CONTENT_BASIC; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 269 | /* |
| 270 | * Primitive types. |
| 271 | */ |
| 272 | switch (type) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 273 | case XML_SCHEMAS_STRING: |
| 274 | case XML_SCHEMAS_DECIMAL: |
| 275 | case XML_SCHEMAS_DATE: |
| 276 | case XML_SCHEMAS_DATETIME: |
| 277 | case XML_SCHEMAS_TIME: |
| 278 | case XML_SCHEMAS_GYEAR: |
| 279 | case XML_SCHEMAS_GYEARMONTH: |
| 280 | case XML_SCHEMAS_GMONTH: |
| 281 | case XML_SCHEMAS_GMONTHDAY: |
| 282 | case XML_SCHEMAS_GDAY: |
| 283 | case XML_SCHEMAS_DURATION: |
| 284 | case XML_SCHEMAS_FLOAT: |
| 285 | case XML_SCHEMAS_DOUBLE: |
| 286 | case XML_SCHEMAS_BOOLEAN: |
| 287 | case XML_SCHEMAS_ANYURI: |
| 288 | case XML_SCHEMAS_HEXBINARY: |
| 289 | case XML_SCHEMAS_BASE64BINARY: |
| 290 | case XML_SCHEMAS_QNAME: |
| 291 | case XML_SCHEMAS_NOTATION: |
| 292 | ret->flags |= XML_SCHEMAS_TYPE_BUILTIN_PRIMITIVE; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 293 | break; |
William M. Brack | 96d2eff | 2004-06-30 11:48:47 +0000 | [diff] [blame] | 294 | default: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 295 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 296 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 297 | /* |
| 298 | * Set variety. |
| 299 | */ |
| 300 | switch (type) { |
| 301 | case XML_SCHEMAS_ANYTYPE: |
| 302 | case XML_SCHEMAS_ANYSIMPLETYPE: |
| 303 | break; |
| 304 | case XML_SCHEMAS_IDREFS: |
| 305 | case XML_SCHEMAS_NMTOKENS: |
| 306 | case XML_SCHEMAS_ENTITIES: |
| 307 | ret->flags |= XML_SCHEMAS_TYPE_VARIETY_LIST; |
| 308 | ret->facets = xmlSchemaNewMinLengthFacet(1); |
| 309 | ret->flags |= XML_SCHEMAS_TYPE_HAS_FACETS; |
| 310 | break; |
| 311 | default: |
| 312 | ret->flags |= XML_SCHEMAS_TYPE_VARIETY_ATOMIC; |
| 313 | break; |
| 314 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 315 | xmlHashAddEntry2(xmlSchemaTypesBank, ret->name, |
| 316 | XML_SCHEMAS_NAMESPACE_NAME, ret); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 317 | ret->builtInType = type; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 318 | return(ret); |
| 319 | } |
| 320 | |
| 321 | /* |
| 322 | * xmlSchemaInitTypes: |
| 323 | * |
| 324 | * Initialize the default XML Schemas type library |
| 325 | */ |
| 326 | void |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 327 | xmlSchemaInitTypes(void) |
| 328 | { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 329 | if (xmlSchemaTypesInitialized != 0) |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 330 | return; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 331 | xmlSchemaTypesBank = xmlHashCreate(40); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 332 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 333 | |
Daniel Veillard | c6e997c | 2003-01-27 12:35:42 +0000 | [diff] [blame] | 334 | /* |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 335 | * 3.4.7 Built-in Complex Type Definition |
| 336 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 337 | xmlSchemaTypeAnyTypeDef = xmlSchemaInitBasicType("anyType", |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 338 | XML_SCHEMAS_ANYTYPE, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 339 | NULL); |
| 340 | xmlSchemaTypeAnyTypeDef->baseType = xmlSchemaTypeAnyTypeDef; |
| 341 | xmlSchemaTypeAnyTypeDef->contentType = XML_SCHEMA_CONTENT_MIXED; |
| 342 | { |
| 343 | xmlSchemaWildcardPtr wild; |
| 344 | |
| 345 | wild = (xmlSchemaWildcardPtr) xmlMalloc(sizeof(xmlSchemaWildcard)); |
| 346 | if (wild == NULL) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 347 | xmlSchemaTypeErrMemory(NULL, "could not create an attribute wildcard on anyType"); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 348 | return; |
| 349 | } |
| 350 | memset(wild, 0, sizeof(xmlSchemaWildcard)); |
| 351 | wild->any = 1; |
| 352 | wild->processContents = XML_SCHEMAS_ANY_LAX; |
| 353 | wild->minOccurs = 1; |
| 354 | wild->maxOccurs = 1; |
| 355 | xmlSchemaTypeAnyTypeDef->attributeWildcard = wild; |
| 356 | } |
| 357 | xmlSchemaTypeAnySimpleTypeDef = xmlSchemaInitBasicType("anySimpleType", |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 358 | XML_SCHEMAS_ANYSIMPLETYPE, |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 359 | xmlSchemaTypeAnyTypeDef); |
| 360 | /* |
| 361 | * primitive datatypes |
| 362 | */ |
| 363 | xmlSchemaTypeStringDef = xmlSchemaInitBasicType("string", |
| 364 | XML_SCHEMAS_STRING, |
| 365 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 366 | xmlSchemaTypeDecimalDef = xmlSchemaInitBasicType("decimal", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 367 | XML_SCHEMAS_DECIMAL, |
| 368 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 369 | xmlSchemaTypeDateDef = xmlSchemaInitBasicType("date", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 370 | XML_SCHEMAS_DATE, |
| 371 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 372 | xmlSchemaTypeDatetimeDef = xmlSchemaInitBasicType("dateTime", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 373 | XML_SCHEMAS_DATETIME, |
| 374 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 375 | xmlSchemaTypeTimeDef = xmlSchemaInitBasicType("time", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 376 | XML_SCHEMAS_TIME, |
| 377 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 378 | xmlSchemaTypeGYearDef = xmlSchemaInitBasicType("gYear", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 379 | XML_SCHEMAS_GYEAR, |
| 380 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 381 | xmlSchemaTypeGYearMonthDef = xmlSchemaInitBasicType("gYearMonth", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 382 | XML_SCHEMAS_GYEARMONTH, |
| 383 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 384 | xmlSchemaTypeGMonthDef = xmlSchemaInitBasicType("gMonth", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 385 | XML_SCHEMAS_GMONTH, |
| 386 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 387 | xmlSchemaTypeGMonthDayDef = xmlSchemaInitBasicType("gMonthDay", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 388 | XML_SCHEMAS_GMONTHDAY, |
| 389 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 390 | xmlSchemaTypeGDayDef = xmlSchemaInitBasicType("gDay", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 391 | XML_SCHEMAS_GDAY, |
| 392 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 393 | xmlSchemaTypeDurationDef = xmlSchemaInitBasicType("duration", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 394 | XML_SCHEMAS_DURATION, |
| 395 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 396 | xmlSchemaTypeFloatDef = xmlSchemaInitBasicType("float", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 397 | XML_SCHEMAS_FLOAT, |
| 398 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 399 | xmlSchemaTypeDoubleDef = xmlSchemaInitBasicType("double", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 400 | XML_SCHEMAS_DOUBLE, |
| 401 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 402 | xmlSchemaTypeBooleanDef = xmlSchemaInitBasicType("boolean", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 403 | XML_SCHEMAS_BOOLEAN, |
| 404 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 405 | xmlSchemaTypeAnyURIDef = xmlSchemaInitBasicType("anyURI", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 406 | XML_SCHEMAS_ANYURI, |
| 407 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 408 | xmlSchemaTypeHexBinaryDef = xmlSchemaInitBasicType("hexBinary", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 409 | XML_SCHEMAS_HEXBINARY, |
| 410 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 411 | xmlSchemaTypeBase64BinaryDef |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 412 | = xmlSchemaInitBasicType("base64Binary", XML_SCHEMAS_BASE64BINARY, |
| 413 | xmlSchemaTypeAnySimpleTypeDef); |
| 414 | xmlSchemaTypeNotationDef = xmlSchemaInitBasicType("NOTATION", |
| 415 | XML_SCHEMAS_NOTATION, |
| 416 | xmlSchemaTypeAnySimpleTypeDef); |
| 417 | xmlSchemaTypeQNameDef = xmlSchemaInitBasicType("QName", |
| 418 | XML_SCHEMAS_QNAME, |
| 419 | xmlSchemaTypeAnySimpleTypeDef); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 420 | |
Daniel Veillard | c6e997c | 2003-01-27 12:35:42 +0000 | [diff] [blame] | 421 | /* |
| 422 | * derived datatypes |
| 423 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 424 | xmlSchemaTypeIntegerDef = xmlSchemaInitBasicType("integer", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 425 | XML_SCHEMAS_INTEGER, |
| 426 | xmlSchemaTypeDecimalDef); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 427 | xmlSchemaTypeNonPositiveIntegerDef = |
| 428 | xmlSchemaInitBasicType("nonPositiveInteger", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 429 | XML_SCHEMAS_NPINTEGER, |
| 430 | xmlSchemaTypeIntegerDef); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 431 | xmlSchemaTypeNegativeIntegerDef = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 432 | xmlSchemaInitBasicType("negativeInteger", XML_SCHEMAS_NINTEGER, |
| 433 | xmlSchemaTypeNonPositiveIntegerDef); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 434 | xmlSchemaTypeLongDef = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 435 | xmlSchemaInitBasicType("long", XML_SCHEMAS_LONG, |
| 436 | xmlSchemaTypeIntegerDef); |
| 437 | xmlSchemaTypeIntDef = xmlSchemaInitBasicType("int", XML_SCHEMAS_INT, |
| 438 | xmlSchemaTypeLongDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 439 | xmlSchemaTypeShortDef = xmlSchemaInitBasicType("short", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 440 | XML_SCHEMAS_SHORT, |
| 441 | xmlSchemaTypeIntDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 442 | xmlSchemaTypeByteDef = xmlSchemaInitBasicType("byte", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 443 | XML_SCHEMAS_BYTE, |
| 444 | xmlSchemaTypeShortDef); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 445 | xmlSchemaTypeNonNegativeIntegerDef = |
| 446 | xmlSchemaInitBasicType("nonNegativeInteger", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 447 | XML_SCHEMAS_NNINTEGER, |
| 448 | xmlSchemaTypeIntegerDef); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 449 | xmlSchemaTypeUnsignedLongDef = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 450 | xmlSchemaInitBasicType("unsignedLong", XML_SCHEMAS_ULONG, |
| 451 | xmlSchemaTypeNonNegativeIntegerDef); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 452 | xmlSchemaTypeUnsignedIntDef = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 453 | xmlSchemaInitBasicType("unsignedInt", XML_SCHEMAS_UINT, |
| 454 | xmlSchemaTypeUnsignedLongDef); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 455 | xmlSchemaTypeUnsignedShortDef = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 456 | xmlSchemaInitBasicType("unsignedShort", XML_SCHEMAS_USHORT, |
| 457 | xmlSchemaTypeUnsignedIntDef); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 458 | xmlSchemaTypeUnsignedByteDef = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 459 | xmlSchemaInitBasicType("unsignedByte", XML_SCHEMAS_UBYTE, |
| 460 | xmlSchemaTypeUnsignedShortDef); |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 461 | xmlSchemaTypePositiveIntegerDef = |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 462 | xmlSchemaInitBasicType("positiveInteger", XML_SCHEMAS_PINTEGER, |
| 463 | xmlSchemaTypeNonNegativeIntegerDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 464 | xmlSchemaTypeNormStringDef = xmlSchemaInitBasicType("normalizedString", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 465 | XML_SCHEMAS_NORMSTRING, |
| 466 | xmlSchemaTypeStringDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 467 | xmlSchemaTypeTokenDef = xmlSchemaInitBasicType("token", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 468 | XML_SCHEMAS_TOKEN, |
| 469 | xmlSchemaTypeNormStringDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 470 | xmlSchemaTypeLanguageDef = xmlSchemaInitBasicType("language", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 471 | XML_SCHEMAS_LANGUAGE, |
| 472 | xmlSchemaTypeTokenDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 473 | xmlSchemaTypeNameDef = xmlSchemaInitBasicType("Name", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 474 | XML_SCHEMAS_NAME, |
| 475 | xmlSchemaTypeTokenDef); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 476 | xmlSchemaTypeNmtokenDef = xmlSchemaInitBasicType("NMTOKEN", |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 477 | XML_SCHEMAS_NMTOKEN, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 478 | xmlSchemaTypeTokenDef); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 479 | xmlSchemaTypeNCNameDef = xmlSchemaInitBasicType("NCName", |
| 480 | XML_SCHEMAS_NCNAME, |
| 481 | xmlSchemaTypeNameDef); |
| 482 | xmlSchemaTypeIdDef = xmlSchemaInitBasicType("ID", XML_SCHEMAS_ID, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 483 | xmlSchemaTypeNCNameDef); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 484 | xmlSchemaTypeIdrefDef = xmlSchemaInitBasicType("IDREF", |
| 485 | XML_SCHEMAS_IDREF, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 486 | xmlSchemaTypeNCNameDef); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 487 | xmlSchemaTypeEntityDef = xmlSchemaInitBasicType("ENTITY", |
| 488 | XML_SCHEMAS_ENTITY, |
| 489 | xmlSchemaTypeNCNameDef); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 490 | /* |
| 491 | * Derived list types. |
| 492 | */ |
| 493 | /* ENTITIES */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 494 | xmlSchemaTypeEntitiesDef = xmlSchemaInitBasicType("ENTITIES", |
| 495 | XML_SCHEMAS_ENTITIES, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 496 | xmlSchemaTypeAnySimpleTypeDef); |
| 497 | xmlSchemaTypeEntitiesDef->subtypes = xmlSchemaTypeEntityDef; |
| 498 | /* IDREFS */ |
| 499 | xmlSchemaTypeIdrefsDef = xmlSchemaInitBasicType("IDREFS", |
| 500 | XML_SCHEMAS_IDREFS, |
| 501 | xmlSchemaTypeAnySimpleTypeDef); |
| 502 | xmlSchemaTypeIdrefsDef->subtypes = xmlSchemaTypeIdrefDef; |
| 503 | |
| 504 | /* NMTOKENS */ |
| 505 | xmlSchemaTypeNmtokensDef = xmlSchemaInitBasicType("NMTOKENS", |
| 506 | XML_SCHEMAS_NMTOKENS, |
| 507 | xmlSchemaTypeAnySimpleTypeDef); |
| 508 | xmlSchemaTypeNmtokensDef->subtypes = xmlSchemaTypeNmtokenDef; |
| 509 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 510 | xmlSchemaTypesInitialized = 1; |
| 511 | } |
| 512 | |
| 513 | /** |
| 514 | * xmlSchemaCleanupTypes: |
| 515 | * |
| 516 | * Cleanup the default XML Schemas type library |
| 517 | */ |
| 518 | void |
| 519 | xmlSchemaCleanupTypes(void) { |
| 520 | if (xmlSchemaTypesInitialized == 0) |
| 521 | return; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 522 | xmlSchemaFreeWildcard(xmlSchemaTypeAnyTypeDef->attributeWildcard); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 523 | xmlHashFree(xmlSchemaTypesBank, (xmlHashDeallocator) xmlSchemaFreeType); |
| 524 | xmlSchemaTypesInitialized = 0; |
| 525 | } |
| 526 | |
| 527 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 528 | * xmlSchemaIsBuiltInTypeFacet: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 529 | * @type: the built-in type |
| 530 | * @facetType: the facet type |
| 531 | * |
| 532 | * Evaluates if a specific facet can be |
| 533 | * used in conjunction with a type. |
| 534 | * |
| 535 | * Returns 1 if the facet can be used with the given built-in type, |
| 536 | * 0 otherwise and -1 in case the type is not a built-in type. |
| 537 | */ |
| 538 | int |
| 539 | xmlSchemaIsBuiltInTypeFacet(xmlSchemaTypePtr type, int facetType) |
| 540 | { |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 541 | if (type == NULL) |
| 542 | return (-1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 543 | if (type->type != XML_SCHEMA_TYPE_BASIC) |
| 544 | return (-1); |
| 545 | switch (type->builtInType) { |
| 546 | case XML_SCHEMAS_BOOLEAN: |
| 547 | if ((facetType == XML_SCHEMA_FACET_PATTERN) || |
| 548 | (facetType == XML_SCHEMA_FACET_WHITESPACE)) |
| 549 | return (1); |
| 550 | else |
| 551 | return (0); |
| 552 | case XML_SCHEMAS_STRING: |
| 553 | case XML_SCHEMAS_NOTATION: |
| 554 | case XML_SCHEMAS_QNAME: |
| 555 | case XML_SCHEMAS_ANYURI: |
| 556 | case XML_SCHEMAS_BASE64BINARY: |
| 557 | case XML_SCHEMAS_HEXBINARY: |
| 558 | if ((facetType == XML_SCHEMA_FACET_LENGTH) || |
| 559 | (facetType == XML_SCHEMA_FACET_MINLENGTH) || |
| 560 | (facetType == XML_SCHEMA_FACET_MAXLENGTH) || |
| 561 | (facetType == XML_SCHEMA_FACET_PATTERN) || |
| 562 | (facetType == XML_SCHEMA_FACET_ENUMERATION) || |
| 563 | (facetType == XML_SCHEMA_FACET_WHITESPACE)) |
| 564 | return (1); |
| 565 | else |
| 566 | return (0); |
| 567 | case XML_SCHEMAS_DECIMAL: |
| 568 | if ((facetType == XML_SCHEMA_FACET_TOTALDIGITS) || |
| 569 | (facetType == XML_SCHEMA_FACET_FRACTIONDIGITS) || |
| 570 | (facetType == XML_SCHEMA_FACET_PATTERN) || |
| 571 | (facetType == XML_SCHEMA_FACET_WHITESPACE) || |
| 572 | (facetType == XML_SCHEMA_FACET_ENUMERATION) || |
| 573 | (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) || |
| 574 | (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) || |
| 575 | (facetType == XML_SCHEMA_FACET_MININCLUSIVE) || |
| 576 | (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE)) |
| 577 | return (1); |
| 578 | else |
| 579 | return (0); |
| 580 | case XML_SCHEMAS_TIME: |
| 581 | case XML_SCHEMAS_GDAY: |
| 582 | case XML_SCHEMAS_GMONTH: |
| 583 | case XML_SCHEMAS_GMONTHDAY: |
| 584 | case XML_SCHEMAS_GYEAR: |
| 585 | case XML_SCHEMAS_GYEARMONTH: |
| 586 | case XML_SCHEMAS_DATE: |
| 587 | case XML_SCHEMAS_DATETIME: |
| 588 | case XML_SCHEMAS_DURATION: |
| 589 | case XML_SCHEMAS_FLOAT: |
| 590 | case XML_SCHEMAS_DOUBLE: |
| 591 | if ((facetType == XML_SCHEMA_FACET_PATTERN) || |
| 592 | (facetType == XML_SCHEMA_FACET_ENUMERATION) || |
| 593 | (facetType == XML_SCHEMA_FACET_WHITESPACE) || |
| 594 | (facetType == XML_SCHEMA_FACET_MAXINCLUSIVE) || |
| 595 | (facetType == XML_SCHEMA_FACET_MAXEXCLUSIVE) || |
| 596 | (facetType == XML_SCHEMA_FACET_MININCLUSIVE) || |
| 597 | (facetType == XML_SCHEMA_FACET_MINEXCLUSIVE)) |
| 598 | return (1); |
| 599 | else |
| 600 | return (0); |
| 601 | default: |
Daniel Veillard | c7e3cc4 | 2004-09-28 12:33:52 +0000 | [diff] [blame] | 602 | break; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 603 | } |
| 604 | return (0); |
| 605 | } |
| 606 | |
| 607 | /** |
| 608 | * xmlSchemaGetBuiltInType: |
| 609 | * @type: the type of the built in type |
| 610 | * |
| 611 | * Gives you the type struct for a built-in |
| 612 | * type by its type id. |
| 613 | * |
| 614 | * Returns the type if found, NULL otherwise. |
| 615 | */ |
| 616 | xmlSchemaTypePtr |
| 617 | xmlSchemaGetBuiltInType(xmlSchemaValType type) |
| 618 | { |
| 619 | if (xmlSchemaTypesInitialized == 0) |
| 620 | xmlSchemaInitTypes(); |
| 621 | switch (type) { |
| 622 | |
| 623 | case XML_SCHEMAS_ANYSIMPLETYPE: |
| 624 | return (xmlSchemaTypeAnySimpleTypeDef); |
| 625 | case XML_SCHEMAS_STRING: |
| 626 | return (xmlSchemaTypeStringDef); |
| 627 | case XML_SCHEMAS_NORMSTRING: |
| 628 | return (xmlSchemaTypeNormStringDef); |
| 629 | case XML_SCHEMAS_DECIMAL: |
| 630 | return (xmlSchemaTypeDecimalDef); |
| 631 | case XML_SCHEMAS_TIME: |
| 632 | return (xmlSchemaTypeTimeDef); |
| 633 | case XML_SCHEMAS_GDAY: |
| 634 | return (xmlSchemaTypeGDayDef); |
| 635 | case XML_SCHEMAS_GMONTH: |
| 636 | return (xmlSchemaTypeGMonthDef); |
| 637 | case XML_SCHEMAS_GMONTHDAY: |
| 638 | return (xmlSchemaTypeGMonthDayDef); |
| 639 | case XML_SCHEMAS_GYEAR: |
| 640 | return (xmlSchemaTypeGYearDef); |
| 641 | case XML_SCHEMAS_GYEARMONTH: |
| 642 | return (xmlSchemaTypeGYearMonthDef); |
| 643 | case XML_SCHEMAS_DATE: |
| 644 | return (xmlSchemaTypeDateDef); |
| 645 | case XML_SCHEMAS_DATETIME: |
| 646 | return (xmlSchemaTypeDatetimeDef); |
| 647 | case XML_SCHEMAS_DURATION: |
| 648 | return (xmlSchemaTypeDurationDef); |
| 649 | case XML_SCHEMAS_FLOAT: |
| 650 | return (xmlSchemaTypeFloatDef); |
| 651 | case XML_SCHEMAS_DOUBLE: |
| 652 | return (xmlSchemaTypeDoubleDef); |
| 653 | case XML_SCHEMAS_BOOLEAN: |
| 654 | return (xmlSchemaTypeBooleanDef); |
| 655 | case XML_SCHEMAS_TOKEN: |
| 656 | return (xmlSchemaTypeTokenDef); |
| 657 | case XML_SCHEMAS_LANGUAGE: |
| 658 | return (xmlSchemaTypeLanguageDef); |
| 659 | case XML_SCHEMAS_NMTOKEN: |
| 660 | return (xmlSchemaTypeNmtokenDef); |
| 661 | case XML_SCHEMAS_NMTOKENS: |
| 662 | return (xmlSchemaTypeNmtokensDef); |
| 663 | case XML_SCHEMAS_NAME: |
| 664 | return (xmlSchemaTypeNameDef); |
| 665 | case XML_SCHEMAS_QNAME: |
| 666 | return (xmlSchemaTypeQNameDef); |
| 667 | case XML_SCHEMAS_NCNAME: |
| 668 | return (xmlSchemaTypeNCNameDef); |
| 669 | case XML_SCHEMAS_ID: |
| 670 | return (xmlSchemaTypeIdDef); |
| 671 | case XML_SCHEMAS_IDREF: |
| 672 | return (xmlSchemaTypeIdrefDef); |
| 673 | case XML_SCHEMAS_IDREFS: |
| 674 | return (xmlSchemaTypeIdrefsDef); |
| 675 | case XML_SCHEMAS_ENTITY: |
| 676 | return (xmlSchemaTypeEntityDef); |
| 677 | case XML_SCHEMAS_ENTITIES: |
| 678 | return (xmlSchemaTypeEntitiesDef); |
| 679 | case XML_SCHEMAS_NOTATION: |
| 680 | return (xmlSchemaTypeNotationDef); |
| 681 | case XML_SCHEMAS_ANYURI: |
| 682 | return (xmlSchemaTypeAnyURIDef); |
| 683 | case XML_SCHEMAS_INTEGER: |
| 684 | return (xmlSchemaTypeIntegerDef); |
| 685 | case XML_SCHEMAS_NPINTEGER: |
| 686 | return (xmlSchemaTypeNonPositiveIntegerDef); |
| 687 | case XML_SCHEMAS_NINTEGER: |
| 688 | return (xmlSchemaTypeNegativeIntegerDef); |
| 689 | case XML_SCHEMAS_NNINTEGER: |
| 690 | return (xmlSchemaTypeNonNegativeIntegerDef); |
| 691 | case XML_SCHEMAS_PINTEGER: |
| 692 | return (xmlSchemaTypePositiveIntegerDef); |
| 693 | case XML_SCHEMAS_INT: |
| 694 | return (xmlSchemaTypeIntDef); |
| 695 | case XML_SCHEMAS_UINT: |
| 696 | return (xmlSchemaTypeUnsignedIntDef); |
| 697 | case XML_SCHEMAS_LONG: |
| 698 | return (xmlSchemaTypeLongDef); |
| 699 | case XML_SCHEMAS_ULONG: |
| 700 | return (xmlSchemaTypeUnsignedLongDef); |
| 701 | case XML_SCHEMAS_SHORT: |
| 702 | return (xmlSchemaTypeShortDef); |
| 703 | case XML_SCHEMAS_USHORT: |
| 704 | return (xmlSchemaTypeUnsignedShortDef); |
| 705 | case XML_SCHEMAS_BYTE: |
| 706 | return (xmlSchemaTypeByteDef); |
| 707 | case XML_SCHEMAS_UBYTE: |
| 708 | return (xmlSchemaTypeUnsignedByteDef); |
| 709 | case XML_SCHEMAS_HEXBINARY: |
| 710 | return (xmlSchemaTypeHexBinaryDef); |
| 711 | case XML_SCHEMAS_BASE64BINARY: |
| 712 | return (xmlSchemaTypeBase64BinaryDef); |
| 713 | case XML_SCHEMAS_ANYTYPE: |
| 714 | return (xmlSchemaTypeAnyTypeDef); |
| 715 | default: |
| 716 | return (NULL); |
| 717 | } |
| 718 | } |
| 719 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 720 | int |
| 721 | xmlSchemaValueAppend(xmlSchemaValPtr prev, xmlSchemaValPtr cur) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 722 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 723 | if ((prev == NULL) || (cur == NULL)) |
| 724 | return (-1); |
| 725 | prev->next = cur; |
| 726 | return (0); |
| 727 | } |
| 728 | |
| 729 | xmlSchemaValPtr |
| 730 | xmlSchemaValueGetNext(xmlSchemaValPtr cur) { |
| 731 | |
| 732 | if (cur == NULL) |
| 733 | return (NULL); |
| 734 | return (cur->next); |
| 735 | } |
| 736 | |
| 737 | const xmlChar * |
| 738 | xmlSchemaValueGetAsString(xmlSchemaValPtr val) |
| 739 | { |
| 740 | if (val == NULL) |
| 741 | return (NULL); |
| 742 | switch (val->type) { |
| 743 | case XML_SCHEMAS_STRING: |
| 744 | case XML_SCHEMAS_NORMSTRING: |
| 745 | case XML_SCHEMAS_ANYSIMPLETYPE: |
| 746 | case XML_SCHEMAS_TOKEN: |
| 747 | case XML_SCHEMAS_LANGUAGE: |
| 748 | case XML_SCHEMAS_NMTOKEN: |
| 749 | case XML_SCHEMAS_NAME: |
| 750 | case XML_SCHEMAS_NCNAME: |
| 751 | case XML_SCHEMAS_ID: |
| 752 | case XML_SCHEMAS_IDREF: |
| 753 | case XML_SCHEMAS_ENTITY: |
| 754 | case XML_SCHEMAS_ANYURI: |
| 755 | return (BAD_CAST val->value.str); |
| 756 | default: |
| 757 | break; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 758 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 759 | return (NULL); |
| 760 | } |
| 761 | |
| 762 | int |
| 763 | xmlSchemaValueGetAsBoolean(xmlSchemaValPtr val) |
| 764 | { |
| 765 | if ((val == NULL) || (val->type != XML_SCHEMAS_BOOLEAN)) |
| 766 | return (0); |
| 767 | return (val->value.b); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | /** |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 771 | * xmlSchemaNewStringValue: |
| 772 | * @type: the value type |
Daniel Veillard | b5839c3 | 2005-02-19 18:27:14 +0000 | [diff] [blame] | 773 | * @value: the value |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 774 | * |
| 775 | * Allocate a new simple type value. The type can be |
Kasimier T. Buchcik | 2ee855d | 2005-03-07 11:14:14 +0000 | [diff] [blame] | 776 | * of XML_SCHEMAS_STRING. |
| 777 | * WARNING: This one is intended to be expanded for other |
| 778 | * string based types. We need this for anySimpleType as well. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 779 | * The given value is consumed and freed with the struct. |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 780 | * |
| 781 | * Returns a pointer to the new value or NULL in case of error |
| 782 | */ |
| 783 | xmlSchemaValPtr |
| 784 | xmlSchemaNewStringValue(xmlSchemaValType type, |
| 785 | const xmlChar *value) |
| 786 | { |
| 787 | xmlSchemaValPtr val; |
| 788 | |
| 789 | if (type != XML_SCHEMAS_STRING) |
| 790 | return(NULL); |
| 791 | val = (xmlSchemaValPtr) xmlMalloc(sizeof(xmlSchemaVal)); |
| 792 | if (val == NULL) { |
| 793 | return(NULL); |
| 794 | } |
| 795 | memset(val, 0, sizeof(xmlSchemaVal)); |
| 796 | val->type = type; |
| 797 | val->value.str = (xmlChar *) value; |
| 798 | return(val); |
| 799 | } |
| 800 | |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 801 | /** |
| 802 | * xmlSchemaNewNOTATIONValue: |
Daniel Veillard | b5839c3 | 2005-02-19 18:27:14 +0000 | [diff] [blame] | 803 | * @name: the notation name |
| 804 | * @ns: the notation namespace name or NULL |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 805 | * |
| 806 | * Allocate a new NOTATION value. |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 807 | * The given values are consumed and freed with the struct. |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 808 | * |
| 809 | * Returns a pointer to the new value or NULL in case of error |
| 810 | */ |
| 811 | xmlSchemaValPtr |
| 812 | xmlSchemaNewNOTATIONValue(const xmlChar *name, |
| 813 | const xmlChar *ns) |
| 814 | { |
| 815 | xmlSchemaValPtr val; |
| 816 | |
| 817 | val = xmlSchemaNewValue(XML_SCHEMAS_NOTATION); |
| 818 | if (val == NULL) |
| 819 | return (NULL); |
| 820 | |
William M. Brack | 12d37ab | 2005-02-21 13:54:07 +0000 | [diff] [blame] | 821 | val->value.qname.name = (xmlChar *)name; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 822 | if (ns != NULL) |
William M. Brack | 12d37ab | 2005-02-21 13:54:07 +0000 | [diff] [blame] | 823 | val->value.qname.uri = (xmlChar *)ns; |
Kasimier T. Buchcik | b06b4de | 2005-02-17 19:00:23 +0000 | [diff] [blame] | 824 | return(val); |
| 825 | } |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 826 | |
| 827 | /** |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 828 | * xmlSchemaNewQNameValue: |
| 829 | * @namespaceName: the namespace name |
| 830 | * @localName: the local name |
| 831 | * |
| 832 | * Allocate a new QName value. |
| 833 | * The given values are consumed and freed with the struct. |
| 834 | * |
| 835 | * Returns a pointer to the new value or NULL in case of an error. |
| 836 | */ |
| 837 | xmlSchemaValPtr |
| 838 | xmlSchemaNewQNameValue(const xmlChar *namespaceName, |
| 839 | const xmlChar *localName) |
| 840 | { |
| 841 | xmlSchemaValPtr val; |
| 842 | |
| 843 | val = xmlSchemaNewValue(XML_SCHEMAS_QNAME); |
| 844 | if (val == NULL) |
| 845 | return (NULL); |
| 846 | |
| 847 | val->value.qname.name = (xmlChar *) localName; |
| 848 | val->value.qname.uri = (xmlChar *) namespaceName; |
| 849 | return(val); |
| 850 | } |
| 851 | |
| 852 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 853 | * xmlSchemaFreeValue: |
| 854 | * @value: the value to free |
| 855 | * |
| 856 | * Cleanup the default XML Schemas type library |
| 857 | */ |
| 858 | void |
| 859 | xmlSchemaFreeValue(xmlSchemaValPtr value) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 860 | xmlSchemaValPtr prev; |
| 861 | |
| 862 | while (value != NULL) { |
| 863 | switch (value->type) { |
| 864 | case XML_SCHEMAS_STRING: |
| 865 | case XML_SCHEMAS_NORMSTRING: |
| 866 | case XML_SCHEMAS_TOKEN: |
| 867 | case XML_SCHEMAS_LANGUAGE: |
| 868 | case XML_SCHEMAS_NMTOKEN: |
| 869 | case XML_SCHEMAS_NMTOKENS: |
| 870 | case XML_SCHEMAS_NAME: |
| 871 | case XML_SCHEMAS_NCNAME: |
| 872 | case XML_SCHEMAS_ID: |
| 873 | case XML_SCHEMAS_IDREF: |
| 874 | case XML_SCHEMAS_IDREFS: |
| 875 | case XML_SCHEMAS_ENTITY: |
| 876 | case XML_SCHEMAS_ENTITIES: |
| 877 | case XML_SCHEMAS_ANYURI: |
| 878 | case XML_SCHEMAS_ANYSIMPLETYPE: |
| 879 | if (value->value.str != NULL) |
| 880 | xmlFree(value->value.str); |
| 881 | break; |
| 882 | case XML_SCHEMAS_NOTATION: |
| 883 | case XML_SCHEMAS_QNAME: |
| 884 | if (value->value.qname.uri != NULL) |
| 885 | xmlFree(value->value.qname.uri); |
| 886 | if (value->value.qname.name != NULL) |
| 887 | xmlFree(value->value.qname.name); |
| 888 | break; |
| 889 | case XML_SCHEMAS_HEXBINARY: |
| 890 | if (value->value.hex.str != NULL) |
| 891 | xmlFree(value->value.hex.str); |
| 892 | break; |
| 893 | case XML_SCHEMAS_BASE64BINARY: |
| 894 | if (value->value.base64.str != NULL) |
| 895 | xmlFree(value->value.base64.str); |
| 896 | break; |
| 897 | default: |
| 898 | break; |
| 899 | } |
| 900 | prev = value; |
| 901 | value = value->next; |
| 902 | xmlFree(prev); |
| 903 | } |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /** |
| 907 | * xmlSchemaGetPredefinedType: |
| 908 | * @name: the type name |
| 909 | * @ns: the URI of the namespace usually "http://www.w3.org/2001/XMLSchema" |
| 910 | * |
| 911 | * Lookup a type in the default XML Schemas type library |
| 912 | * |
| 913 | * Returns the type if found, NULL otherwise |
| 914 | */ |
| 915 | xmlSchemaTypePtr |
| 916 | xmlSchemaGetPredefinedType(const xmlChar *name, const xmlChar *ns) { |
| 917 | if (xmlSchemaTypesInitialized == 0) |
| 918 | xmlSchemaInitTypes(); |
| 919 | if (name == NULL) |
| 920 | return(NULL); |
| 921 | return((xmlSchemaTypePtr) xmlHashLookup2(xmlSchemaTypesBank, name, ns)); |
| 922 | } |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 923 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 924 | /** |
| 925 | * xmlSchemaGetBuiltInListSimpleTypeItemType: |
| 926 | * @type: the built-in simple type. |
| 927 | * |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 928 | * Lookup function |
| 929 | * |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 930 | * Returns the item type of @type as defined by the built-in datatype |
| 931 | * hierarchy of XML Schema Part 2: Datatypes, or NULL in case of an error. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 932 | */ |
| 933 | xmlSchemaTypePtr |
| 934 | xmlSchemaGetBuiltInListSimpleTypeItemType(xmlSchemaTypePtr type) |
| 935 | { |
Daniel Veillard | 4259532 | 2004-11-08 10:52:06 +0000 | [diff] [blame] | 936 | if ((type == NULL) || (type->type != XML_SCHEMA_TYPE_BASIC)) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 937 | return (NULL); |
| 938 | switch (type->builtInType) { |
| 939 | case XML_SCHEMAS_NMTOKENS: |
| 940 | return (xmlSchemaTypeNmtokenDef ); |
| 941 | case XML_SCHEMAS_IDREFS: |
| 942 | return (xmlSchemaTypeIdrefDef); |
| 943 | case XML_SCHEMAS_ENTITIES: |
| 944 | return (xmlSchemaTypeEntityDef); |
| 945 | default: |
| 946 | return (NULL); |
| 947 | } |
| 948 | } |
| 949 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 950 | /**************************************************************** |
| 951 | * * |
| 952 | * Convenience macros and functions * |
| 953 | * * |
| 954 | ****************************************************************/ |
| 955 | |
| 956 | #define IS_TZO_CHAR(c) \ |
| 957 | ((c == 0) || (c == 'Z') || (c == '+') || (c == '-')) |
| 958 | |
| 959 | #define VALID_YEAR(yr) (yr != 0) |
| 960 | #define VALID_MONTH(mon) ((mon >= 1) && (mon <= 12)) |
| 961 | /* VALID_DAY should only be used when month is unknown */ |
| 962 | #define VALID_DAY(day) ((day >= 1) && (day <= 31)) |
| 963 | #define VALID_HOUR(hr) ((hr >= 0) && (hr <= 23)) |
| 964 | #define VALID_MIN(min) ((min >= 0) && (min <= 59)) |
| 965 | #define VALID_SEC(sec) ((sec >= 0) && (sec < 60)) |
Kasimier T. Buchcik | 690a680 | 2005-05-12 13:16:01 +0000 | [diff] [blame] | 966 | #define VALID_TZO(tzo) ((tzo > -840) && (tzo < 840)) |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 967 | #define IS_LEAP(y) \ |
| 968 | (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) |
| 969 | |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 970 | static const unsigned int daysInMonth[12] = |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 971 | { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 972 | static const unsigned int daysInMonthLeap[12] = |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 973 | { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; |
| 974 | |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 975 | #define MAX_DAYINMONTH(yr,mon) \ |
| 976 | (IS_LEAP(yr) ? daysInMonthLeap[mon - 1] : daysInMonth[mon - 1]) |
| 977 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 978 | #define VALID_MDAY(dt) \ |
| 979 | (IS_LEAP(dt->year) ? \ |
| 980 | (dt->day <= daysInMonthLeap[dt->mon - 1]) : \ |
| 981 | (dt->day <= daysInMonth[dt->mon - 1])) |
| 982 | |
| 983 | #define VALID_DATE(dt) \ |
| 984 | (VALID_YEAR(dt->year) && VALID_MONTH(dt->mon) && VALID_MDAY(dt)) |
| 985 | |
| 986 | #define VALID_TIME(dt) \ |
| 987 | (VALID_HOUR(dt->hour) && VALID_MIN(dt->min) && \ |
| 988 | VALID_SEC(dt->sec) && VALID_TZO(dt->tzo)) |
| 989 | |
| 990 | #define VALID_DATETIME(dt) \ |
| 991 | (VALID_DATE(dt) && VALID_TIME(dt)) |
| 992 | |
| 993 | #define SECS_PER_MIN (60) |
| 994 | #define SECS_PER_HOUR (60 * SECS_PER_MIN) |
| 995 | #define SECS_PER_DAY (24 * SECS_PER_HOUR) |
| 996 | |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 997 | static const long dayInYearByMonth[12] = |
| 998 | { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; |
| 999 | static const long dayInLeapYearByMonth[12] = |
| 1000 | { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 }; |
| 1001 | |
| 1002 | #define DAY_IN_YEAR(day, month, year) \ |
| 1003 | ((IS_LEAP(year) ? \ |
| 1004 | dayInLeapYearByMonth[month - 1] : \ |
| 1005 | dayInYearByMonth[month - 1]) + day) |
| 1006 | |
| 1007 | #ifdef DEBUG |
| 1008 | #define DEBUG_DATE(dt) \ |
| 1009 | xmlGenericError(xmlGenericErrorContext, \ |
| 1010 | "type=%o %04ld-%02u-%02uT%02u:%02u:%03f", \ |
| 1011 | dt->type,dt->value.date.year,dt->value.date.mon, \ |
| 1012 | dt->value.date.day,dt->value.date.hour,dt->value.date.min, \ |
| 1013 | dt->value.date.sec); \ |
| 1014 | if (dt->value.date.tz_flag) \ |
| 1015 | if (dt->value.date.tzo != 0) \ |
| 1016 | xmlGenericError(xmlGenericErrorContext, \ |
| 1017 | "%+05d\n",dt->value.date.tzo); \ |
| 1018 | else \ |
| 1019 | xmlGenericError(xmlGenericErrorContext, "Z\n"); \ |
| 1020 | else \ |
| 1021 | xmlGenericError(xmlGenericErrorContext,"\n") |
| 1022 | #else |
| 1023 | #define DEBUG_DATE(dt) |
| 1024 | #endif |
| 1025 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1026 | /** |
| 1027 | * _xmlSchemaParseGYear: |
| 1028 | * @dt: pointer to a date structure |
| 1029 | * @str: pointer to the string to analyze |
| 1030 | * |
| 1031 | * Parses a xs:gYear without time zone and fills in the appropriate |
| 1032 | * field of the @dt structure. @str is updated to point just after the |
| 1033 | * xs:gYear. It is supposed that @dt->year is big enough to contain |
| 1034 | * the year. |
| 1035 | * |
| 1036 | * Returns 0 or the error code |
| 1037 | */ |
| 1038 | static int |
| 1039 | _xmlSchemaParseGYear (xmlSchemaValDatePtr dt, const xmlChar **str) { |
| 1040 | const xmlChar *cur = *str, *firstChar; |
| 1041 | int isneg = 0, digcnt = 0; |
| 1042 | |
| 1043 | if (((*cur < '0') || (*cur > '9')) && |
| 1044 | (*cur != '-') && (*cur != '+')) |
| 1045 | return -1; |
| 1046 | |
| 1047 | if (*cur == '-') { |
| 1048 | isneg = 1; |
| 1049 | cur++; |
| 1050 | } |
| 1051 | |
| 1052 | firstChar = cur; |
| 1053 | |
| 1054 | while ((*cur >= '0') && (*cur <= '9')) { |
| 1055 | dt->year = dt->year * 10 + (*cur - '0'); |
| 1056 | cur++; |
| 1057 | digcnt++; |
| 1058 | } |
| 1059 | |
| 1060 | /* year must be at least 4 digits (CCYY); over 4 |
| 1061 | * digits cannot have a leading zero. */ |
| 1062 | if ((digcnt < 4) || ((digcnt > 4) && (*firstChar == '0'))) |
| 1063 | return 1; |
| 1064 | |
| 1065 | if (isneg) |
| 1066 | dt->year = - dt->year; |
| 1067 | |
| 1068 | if (!VALID_YEAR(dt->year)) |
| 1069 | return 2; |
| 1070 | |
| 1071 | *str = cur; |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | /** |
| 1076 | * PARSE_2_DIGITS: |
| 1077 | * @num: the integer to fill in |
| 1078 | * @cur: an #xmlChar * |
| 1079 | * @invalid: an integer |
| 1080 | * |
| 1081 | * Parses a 2-digits integer and updates @num with the value. @cur is |
| 1082 | * updated to point just after the integer. |
| 1083 | * In case of error, @invalid is set to %TRUE, values of @num and |
| 1084 | * @cur are undefined. |
| 1085 | */ |
| 1086 | #define PARSE_2_DIGITS(num, cur, invalid) \ |
| 1087 | if ((cur[0] < '0') || (cur[0] > '9') || \ |
| 1088 | (cur[1] < '0') || (cur[1] > '9')) \ |
| 1089 | invalid = 1; \ |
| 1090 | else \ |
| 1091 | num = (cur[0] - '0') * 10 + (cur[1] - '0'); \ |
| 1092 | cur += 2; |
| 1093 | |
| 1094 | /** |
| 1095 | * PARSE_FLOAT: |
| 1096 | * @num: the double to fill in |
| 1097 | * @cur: an #xmlChar * |
| 1098 | * @invalid: an integer |
| 1099 | * |
| 1100 | * Parses a float and updates @num with the value. @cur is |
| 1101 | * updated to point just after the float. The float must have a |
| 1102 | * 2-digits integer part and may or may not have a decimal part. |
| 1103 | * In case of error, @invalid is set to %TRUE, values of @num and |
| 1104 | * @cur are undefined. |
| 1105 | */ |
| 1106 | #define PARSE_FLOAT(num, cur, invalid) \ |
| 1107 | PARSE_2_DIGITS(num, cur, invalid); \ |
| 1108 | if (!invalid && (*cur == '.')) { \ |
| 1109 | double mult = 1; \ |
| 1110 | cur++; \ |
| 1111 | if ((*cur < '0') || (*cur > '9')) \ |
| 1112 | invalid = 1; \ |
| 1113 | while ((*cur >= '0') && (*cur <= '9')) { \ |
| 1114 | mult /= 10; \ |
| 1115 | num += (*cur - '0') * mult; \ |
| 1116 | cur++; \ |
| 1117 | } \ |
| 1118 | } |
| 1119 | |
| 1120 | /** |
| 1121 | * _xmlSchemaParseGMonth: |
| 1122 | * @dt: pointer to a date structure |
| 1123 | * @str: pointer to the string to analyze |
| 1124 | * |
| 1125 | * Parses a xs:gMonth without time zone and fills in the appropriate |
| 1126 | * field of the @dt structure. @str is updated to point just after the |
| 1127 | * xs:gMonth. |
| 1128 | * |
| 1129 | * Returns 0 or the error code |
| 1130 | */ |
| 1131 | static int |
| 1132 | _xmlSchemaParseGMonth (xmlSchemaValDatePtr dt, const xmlChar **str) { |
| 1133 | const xmlChar *cur = *str; |
| 1134 | int ret = 0; |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1135 | unsigned int value = 0; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1136 | |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1137 | PARSE_2_DIGITS(value, cur, ret); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1138 | if (ret != 0) |
| 1139 | return ret; |
| 1140 | |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1141 | if (!VALID_MONTH(value)) |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1142 | return 2; |
| 1143 | |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1144 | dt->mon = value; |
| 1145 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1146 | *str = cur; |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
| 1150 | /** |
| 1151 | * _xmlSchemaParseGDay: |
| 1152 | * @dt: pointer to a date structure |
| 1153 | * @str: pointer to the string to analyze |
| 1154 | * |
| 1155 | * Parses a xs:gDay without time zone and fills in the appropriate |
| 1156 | * field of the @dt structure. @str is updated to point just after the |
| 1157 | * xs:gDay. |
| 1158 | * |
| 1159 | * Returns 0 or the error code |
| 1160 | */ |
| 1161 | static int |
| 1162 | _xmlSchemaParseGDay (xmlSchemaValDatePtr dt, const xmlChar **str) { |
| 1163 | const xmlChar *cur = *str; |
| 1164 | int ret = 0; |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1165 | unsigned int value = 0; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1166 | |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1167 | PARSE_2_DIGITS(value, cur, ret); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1168 | if (ret != 0) |
| 1169 | return ret; |
| 1170 | |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1171 | if (!VALID_DAY(value)) |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1172 | return 2; |
| 1173 | |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1174 | dt->day = value; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1175 | *str = cur; |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | /** |
| 1180 | * _xmlSchemaParseTime: |
| 1181 | * @dt: pointer to a date structure |
| 1182 | * @str: pointer to the string to analyze |
| 1183 | * |
| 1184 | * Parses a xs:time without time zone and fills in the appropriate |
| 1185 | * fields of the @dt structure. @str is updated to point just after the |
| 1186 | * xs:time. |
| 1187 | * In case of error, values of @dt fields are undefined. |
| 1188 | * |
| 1189 | * Returns 0 or the error code |
| 1190 | */ |
| 1191 | static int |
| 1192 | _xmlSchemaParseTime (xmlSchemaValDatePtr dt, const xmlChar **str) { |
Kasimier T. Buchcik | 285b367 | 2005-05-12 13:10:22 +0000 | [diff] [blame] | 1193 | const xmlChar *cur = *str; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1194 | int ret = 0; |
Kasimier T. Buchcik | 285b367 | 2005-05-12 13:10:22 +0000 | [diff] [blame] | 1195 | int value = 0; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1196 | |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1197 | PARSE_2_DIGITS(value, cur, ret); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1198 | if (ret != 0) |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1199 | return ret; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1200 | if (*cur != ':') |
| 1201 | return 1; |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1202 | if (!VALID_HOUR(value)) |
| 1203 | return 2; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1204 | cur++; |
| 1205 | |
| 1206 | /* the ':' insures this string is xs:time */ |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1207 | dt->hour = value; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1208 | |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1209 | PARSE_2_DIGITS(value, cur, ret); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1210 | if (ret != 0) |
| 1211 | return ret; |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1212 | if (!VALID_MIN(value)) |
| 1213 | return 2; |
| 1214 | dt->min = value; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1215 | |
| 1216 | if (*cur != ':') |
| 1217 | return 1; |
| 1218 | cur++; |
| 1219 | |
| 1220 | PARSE_FLOAT(dt->sec, cur, ret); |
| 1221 | if (ret != 0) |
| 1222 | return ret; |
| 1223 | |
Kasimier T. Buchcik | 64dc4d2 | 2005-04-19 15:58:31 +0000 | [diff] [blame] | 1224 | if ((!VALID_SEC(dt->sec)) || (!VALID_TZO(dt->tzo))) |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1225 | return 2; |
| 1226 | |
| 1227 | *str = cur; |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
| 1231 | /** |
| 1232 | * _xmlSchemaParseTimeZone: |
| 1233 | * @dt: pointer to a date structure |
| 1234 | * @str: pointer to the string to analyze |
| 1235 | * |
| 1236 | * Parses a time zone without time zone and fills in the appropriate |
| 1237 | * field of the @dt structure. @str is updated to point just after the |
| 1238 | * time zone. |
| 1239 | * |
| 1240 | * Returns 0 or the error code |
| 1241 | */ |
| 1242 | static int |
| 1243 | _xmlSchemaParseTimeZone (xmlSchemaValDatePtr dt, const xmlChar **str) { |
| 1244 | const xmlChar *cur = *str; |
| 1245 | int ret = 0; |
| 1246 | |
| 1247 | if (str == NULL) |
| 1248 | return -1; |
| 1249 | |
| 1250 | switch (*cur) { |
| 1251 | case 0: |
| 1252 | dt->tz_flag = 0; |
| 1253 | dt->tzo = 0; |
| 1254 | break; |
| 1255 | |
| 1256 | case 'Z': |
| 1257 | dt->tz_flag = 1; |
| 1258 | dt->tzo = 0; |
| 1259 | cur++; |
| 1260 | break; |
| 1261 | |
| 1262 | case '+': |
| 1263 | case '-': { |
| 1264 | int isneg = 0, tmp = 0; |
| 1265 | isneg = (*cur == '-'); |
| 1266 | |
| 1267 | cur++; |
| 1268 | |
| 1269 | PARSE_2_DIGITS(tmp, cur, ret); |
| 1270 | if (ret != 0) |
| 1271 | return ret; |
| 1272 | if (!VALID_HOUR(tmp)) |
| 1273 | return 2; |
| 1274 | |
| 1275 | if (*cur != ':') |
| 1276 | return 1; |
| 1277 | cur++; |
| 1278 | |
| 1279 | dt->tzo = tmp * 60; |
| 1280 | |
| 1281 | PARSE_2_DIGITS(tmp, cur, ret); |
| 1282 | if (ret != 0) |
| 1283 | return ret; |
| 1284 | if (!VALID_MIN(tmp)) |
| 1285 | return 2; |
| 1286 | |
| 1287 | dt->tzo += tmp; |
| 1288 | if (isneg) |
| 1289 | dt->tzo = - dt->tzo; |
| 1290 | |
| 1291 | if (!VALID_TZO(dt->tzo)) |
| 1292 | return 2; |
| 1293 | |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 1294 | dt->tz_flag = 1; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1295 | break; |
| 1296 | } |
| 1297 | default: |
| 1298 | return 1; |
| 1299 | } |
| 1300 | |
| 1301 | *str = cur; |
| 1302 | return 0; |
| 1303 | } |
| 1304 | |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 1305 | /** |
| 1306 | * _xmlSchemaBase64Decode: |
| 1307 | * @ch: a character |
| 1308 | * |
| 1309 | * Converts a base64 encoded character to its base 64 value. |
| 1310 | * |
| 1311 | * Returns 0-63 (value), 64 (pad), or -1 (not recognized) |
| 1312 | */ |
| 1313 | static int |
| 1314 | _xmlSchemaBase64Decode (const xmlChar ch) { |
| 1315 | if (('A' <= ch) && (ch <= 'Z')) return ch - 'A'; |
| 1316 | if (('a' <= ch) && (ch <= 'z')) return ch - 'a' + 26; |
| 1317 | if (('0' <= ch) && (ch <= '9')) return ch - '0' + 52; |
| 1318 | if ('+' == ch) return 62; |
| 1319 | if ('/' == ch) return 63; |
| 1320 | if ('=' == ch) return 64; |
| 1321 | return -1; |
| 1322 | } |
| 1323 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1324 | /**************************************************************** |
| 1325 | * * |
| 1326 | * XML Schema Dates/Times Datatypes Handling * |
| 1327 | * * |
| 1328 | ****************************************************************/ |
| 1329 | |
| 1330 | /** |
| 1331 | * PARSE_DIGITS: |
| 1332 | * @num: the integer to fill in |
| 1333 | * @cur: an #xmlChar * |
| 1334 | * @num_type: an integer flag |
| 1335 | * |
| 1336 | * Parses a digits integer and updates @num with the value. @cur is |
| 1337 | * updated to point just after the integer. |
| 1338 | * In case of error, @num_type is set to -1, values of @num and |
| 1339 | * @cur are undefined. |
| 1340 | */ |
| 1341 | #define PARSE_DIGITS(num, cur, num_type) \ |
| 1342 | if ((*cur < '0') || (*cur > '9')) \ |
| 1343 | num_type = -1; \ |
| 1344 | else \ |
| 1345 | while ((*cur >= '0') && (*cur <= '9')) { \ |
| 1346 | num = num * 10 + (*cur - '0'); \ |
| 1347 | cur++; \ |
| 1348 | } |
| 1349 | |
| 1350 | /** |
| 1351 | * PARSE_NUM: |
| 1352 | * @num: the double to fill in |
| 1353 | * @cur: an #xmlChar * |
| 1354 | * @num_type: an integer flag |
| 1355 | * |
| 1356 | * Parses a float or integer and updates @num with the value. @cur is |
| 1357 | * updated to point just after the number. If the number is a float, |
| 1358 | * then it must have an integer part and a decimal part; @num_type will |
| 1359 | * be set to 1. If there is no decimal part, @num_type is set to zero. |
| 1360 | * In case of error, @num_type is set to -1, values of @num and |
| 1361 | * @cur are undefined. |
| 1362 | */ |
| 1363 | #define PARSE_NUM(num, cur, num_type) \ |
| 1364 | num = 0; \ |
| 1365 | PARSE_DIGITS(num, cur, num_type); \ |
| 1366 | if (!num_type && (*cur == '.')) { \ |
| 1367 | double mult = 1; \ |
| 1368 | cur++; \ |
| 1369 | if ((*cur < '0') || (*cur > '9')) \ |
| 1370 | num_type = -1; \ |
| 1371 | else \ |
| 1372 | num_type = 1; \ |
| 1373 | while ((*cur >= '0') && (*cur <= '9')) { \ |
| 1374 | mult /= 10; \ |
| 1375 | num += (*cur - '0') * mult; \ |
| 1376 | cur++; \ |
| 1377 | } \ |
| 1378 | } |
| 1379 | |
| 1380 | /** |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 1381 | * xmlSchemaValidateDates: |
Daniel Veillard | 455cc07 | 2003-03-31 10:13:23 +0000 | [diff] [blame] | 1382 | * @type: the expected type or XML_SCHEMAS_UNKNOWN |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1383 | * @dateTime: string to analyze |
| 1384 | * @val: the return computed value |
| 1385 | * |
| 1386 | * Check that @dateTime conforms to the lexical space of one of the date types. |
| 1387 | * if true a value is computed and returned in @val. |
| 1388 | * |
| 1389 | * Returns 0 if this validates, a positive error code number otherwise |
| 1390 | * and -1 in case of internal or API error. |
| 1391 | */ |
| 1392 | static int |
Daniel Veillard | 455cc07 | 2003-03-31 10:13:23 +0000 | [diff] [blame] | 1393 | xmlSchemaValidateDates (xmlSchemaValType type, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1394 | const xmlChar *dateTime, xmlSchemaValPtr *val, |
| 1395 | int collapse) { |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1396 | xmlSchemaValPtr dt; |
| 1397 | int ret; |
| 1398 | const xmlChar *cur = dateTime; |
| 1399 | |
| 1400 | #define RETURN_TYPE_IF_VALID(t) \ |
| 1401 | if (IS_TZO_CHAR(*cur)) { \ |
| 1402 | ret = _xmlSchemaParseTimeZone(&(dt->value.date), &cur); \ |
| 1403 | if (ret == 0) { \ |
| 1404 | if (*cur != 0) \ |
| 1405 | goto error; \ |
| 1406 | dt->type = t; \ |
Daniel Veillard | 455cc07 | 2003-03-31 10:13:23 +0000 | [diff] [blame] | 1407 | goto done; \ |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1408 | } \ |
| 1409 | } |
| 1410 | |
| 1411 | if (dateTime == NULL) |
| 1412 | return -1; |
| 1413 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1414 | if (collapse) |
| 1415 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 1416 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1417 | if ((*cur != '-') && (*cur < '0') && (*cur > '9')) |
| 1418 | return 1; |
| 1419 | |
| 1420 | dt = xmlSchemaNewValue(XML_SCHEMAS_UNKNOWN); |
| 1421 | if (dt == NULL) |
| 1422 | return -1; |
| 1423 | |
| 1424 | if ((cur[0] == '-') && (cur[1] == '-')) { |
| 1425 | /* |
| 1426 | * It's an incomplete date (xs:gMonthDay, xs:gMonth or |
| 1427 | * xs:gDay) |
| 1428 | */ |
| 1429 | cur += 2; |
| 1430 | |
| 1431 | /* is it an xs:gDay? */ |
| 1432 | if (*cur == '-') { |
Daniel Veillard | 455cc07 | 2003-03-31 10:13:23 +0000 | [diff] [blame] | 1433 | if (type == XML_SCHEMAS_GMONTH) |
| 1434 | goto error; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1435 | ++cur; |
| 1436 | ret = _xmlSchemaParseGDay(&(dt->value.date), &cur); |
| 1437 | if (ret != 0) |
| 1438 | goto error; |
| 1439 | |
| 1440 | RETURN_TYPE_IF_VALID(XML_SCHEMAS_GDAY); |
| 1441 | |
| 1442 | goto error; |
| 1443 | } |
| 1444 | |
| 1445 | /* |
| 1446 | * it should be an xs:gMonthDay or xs:gMonth |
| 1447 | */ |
| 1448 | ret = _xmlSchemaParseGMonth(&(dt->value.date), &cur); |
| 1449 | if (ret != 0) |
| 1450 | goto error; |
| 1451 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 1452 | /* |
| 1453 | * a '-' char could indicate this type is xs:gMonthDay or |
| 1454 | * a negative time zone offset. Check for xs:gMonthDay first. |
| 1455 | * Also the first three char's of a negative tzo (-MM:SS) can |
| 1456 | * appear to be a valid day; so even if the day portion |
| 1457 | * of the xs:gMonthDay verifies, we must insure it was not |
| 1458 | * a tzo. |
| 1459 | */ |
| 1460 | if (*cur == '-') { |
| 1461 | const xmlChar *rewnd = cur; |
| 1462 | cur++; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1463 | |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 1464 | ret = _xmlSchemaParseGDay(&(dt->value.date), &cur); |
| 1465 | if ((ret == 0) && ((*cur == 0) || (*cur != ':'))) { |
| 1466 | |
| 1467 | /* |
| 1468 | * we can use the VALID_MDAY macro to validate the month |
| 1469 | * and day because the leap year test will flag year zero |
| 1470 | * as a leap year (even though zero is an invalid year). |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1471 | * FUTURE TODO: Zero will become valid in XML Schema 1.1 |
| 1472 | * probably. |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 1473 | */ |
| 1474 | if (VALID_MDAY((&(dt->value.date)))) { |
| 1475 | |
| 1476 | RETURN_TYPE_IF_VALID(XML_SCHEMAS_GMONTHDAY); |
| 1477 | |
| 1478 | goto error; |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | /* |
| 1483 | * not xs:gMonthDay so rewind and check if just xs:gMonth |
| 1484 | * with an optional time zone. |
| 1485 | */ |
| 1486 | cur = rewnd; |
| 1487 | } |
| 1488 | |
| 1489 | RETURN_TYPE_IF_VALID(XML_SCHEMAS_GMONTH); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1490 | |
| 1491 | goto error; |
| 1492 | } |
| 1493 | |
| 1494 | /* |
| 1495 | * It's a right-truncated date or an xs:time. |
| 1496 | * Try to parse an xs:time then fallback on right-truncated dates. |
| 1497 | */ |
| 1498 | if ((*cur >= '0') && (*cur <= '9')) { |
| 1499 | ret = _xmlSchemaParseTime(&(dt->value.date), &cur); |
| 1500 | if (ret == 0) { |
| 1501 | /* it's an xs:time */ |
| 1502 | RETURN_TYPE_IF_VALID(XML_SCHEMAS_TIME); |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | /* fallback on date parsing */ |
| 1507 | cur = dateTime; |
| 1508 | |
| 1509 | ret = _xmlSchemaParseGYear(&(dt->value.date), &cur); |
| 1510 | if (ret != 0) |
| 1511 | goto error; |
| 1512 | |
| 1513 | /* is it an xs:gYear? */ |
| 1514 | RETURN_TYPE_IF_VALID(XML_SCHEMAS_GYEAR); |
| 1515 | |
| 1516 | if (*cur != '-') |
| 1517 | goto error; |
| 1518 | cur++; |
| 1519 | |
| 1520 | ret = _xmlSchemaParseGMonth(&(dt->value.date), &cur); |
| 1521 | if (ret != 0) |
| 1522 | goto error; |
| 1523 | |
| 1524 | /* is it an xs:gYearMonth? */ |
| 1525 | RETURN_TYPE_IF_VALID(XML_SCHEMAS_GYEARMONTH); |
| 1526 | |
| 1527 | if (*cur != '-') |
| 1528 | goto error; |
| 1529 | cur++; |
| 1530 | |
| 1531 | ret = _xmlSchemaParseGDay(&(dt->value.date), &cur); |
| 1532 | if ((ret != 0) || !VALID_DATE((&(dt->value.date)))) |
| 1533 | goto error; |
| 1534 | |
| 1535 | /* is it an xs:date? */ |
| 1536 | RETURN_TYPE_IF_VALID(XML_SCHEMAS_DATE); |
| 1537 | |
| 1538 | if (*cur != 'T') |
| 1539 | goto error; |
| 1540 | cur++; |
| 1541 | |
| 1542 | /* it should be an xs:dateTime */ |
| 1543 | ret = _xmlSchemaParseTime(&(dt->value.date), &cur); |
| 1544 | if (ret != 0) |
| 1545 | goto error; |
| 1546 | |
| 1547 | ret = _xmlSchemaParseTimeZone(&(dt->value.date), &cur); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1548 | if (collapse) |
| 1549 | while IS_WSP_BLANK_CH(*cur) cur++; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1550 | if ((ret != 0) || (*cur != 0) || !VALID_DATETIME((&(dt->value.date)))) |
| 1551 | goto error; |
| 1552 | |
Daniel Veillard | 455cc07 | 2003-03-31 10:13:23 +0000 | [diff] [blame] | 1553 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1554 | dt->type = XML_SCHEMAS_DATETIME; |
| 1555 | |
Daniel Veillard | 455cc07 | 2003-03-31 10:13:23 +0000 | [diff] [blame] | 1556 | done: |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 1557 | #if 1 |
| 1558 | if ((type != XML_SCHEMAS_UNKNOWN) && (type != dt->type)) |
| 1559 | goto error; |
| 1560 | #else |
| 1561 | /* |
| 1562 | * insure the parsed type is equal to or less significant (right |
| 1563 | * truncated) than the desired type. |
| 1564 | */ |
| 1565 | if ((type != XML_SCHEMAS_UNKNOWN) && (type != dt->type)) { |
| 1566 | |
| 1567 | /* time only matches time */ |
| 1568 | if ((type == XML_SCHEMAS_TIME) && (dt->type == XML_SCHEMAS_TIME)) |
| 1569 | goto error; |
| 1570 | |
| 1571 | if ((type == XML_SCHEMAS_DATETIME) && |
| 1572 | ((dt->type != XML_SCHEMAS_DATE) || |
| 1573 | (dt->type != XML_SCHEMAS_GYEARMONTH) || |
| 1574 | (dt->type != XML_SCHEMAS_GYEAR))) |
| 1575 | goto error; |
| 1576 | |
| 1577 | if ((type == XML_SCHEMAS_DATE) && |
| 1578 | ((dt->type != XML_SCHEMAS_GYEAR) || |
| 1579 | (dt->type != XML_SCHEMAS_GYEARMONTH))) |
| 1580 | goto error; |
| 1581 | |
| 1582 | if ((type == XML_SCHEMAS_GYEARMONTH) && (dt->type != XML_SCHEMAS_GYEAR)) |
| 1583 | goto error; |
| 1584 | |
| 1585 | if ((type == XML_SCHEMAS_GMONTHDAY) && (dt->type != XML_SCHEMAS_GMONTH)) |
| 1586 | goto error; |
| 1587 | } |
Daniel Veillard | 455cc07 | 2003-03-31 10:13:23 +0000 | [diff] [blame] | 1588 | #endif |
| 1589 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1590 | if (val != NULL) |
| 1591 | *val = dt; |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 1592 | else |
| 1593 | xmlSchemaFreeValue(dt); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1594 | |
| 1595 | return 0; |
| 1596 | |
| 1597 | error: |
| 1598 | if (dt != NULL) |
| 1599 | xmlSchemaFreeValue(dt); |
| 1600 | return 1; |
| 1601 | } |
| 1602 | |
| 1603 | /** |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 1604 | * xmlSchemaValidateDuration: |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1605 | * @type: the predefined type |
| 1606 | * @duration: string to analyze |
| 1607 | * @val: the return computed value |
| 1608 | * |
| 1609 | * Check that @duration conforms to the lexical space of the duration type. |
| 1610 | * if true a value is computed and returned in @val. |
| 1611 | * |
| 1612 | * Returns 0 if this validates, a positive error code number otherwise |
| 1613 | * and -1 in case of internal or API error. |
| 1614 | */ |
| 1615 | static int |
Daniel Veillard | dda8f1b | 2002-09-26 09:47:36 +0000 | [diff] [blame] | 1616 | xmlSchemaValidateDuration (xmlSchemaTypePtr type ATTRIBUTE_UNUSED, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1617 | const xmlChar *duration, xmlSchemaValPtr *val, |
| 1618 | int collapse) { |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1619 | const xmlChar *cur = duration; |
| 1620 | xmlSchemaValPtr dur; |
| 1621 | int isneg = 0; |
| 1622 | unsigned int seq = 0; |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 1623 | double num; |
| 1624 | int num_type = 0; /* -1 = invalid, 0 = int, 1 = floating */ |
| 1625 | const xmlChar desig[] = {'Y', 'M', 'D', 'H', 'M', 'S'}; |
| 1626 | const double multi[] = { 0.0, 0.0, 86400.0, 3600.0, 60.0, 1.0, 0.0}; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1627 | |
| 1628 | if (duration == NULL) |
| 1629 | return -1; |
| 1630 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1631 | if (collapse) |
| 1632 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 1633 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1634 | if (*cur == '-') { |
| 1635 | isneg = 1; |
| 1636 | cur++; |
| 1637 | } |
| 1638 | |
| 1639 | /* duration must start with 'P' (after sign) */ |
| 1640 | if (*cur++ != 'P') |
| 1641 | return 1; |
| 1642 | |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 1643 | if (*cur == 0) |
| 1644 | return 1; |
| 1645 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1646 | dur = xmlSchemaNewValue(XML_SCHEMAS_DURATION); |
| 1647 | if (dur == NULL) |
| 1648 | return -1; |
| 1649 | |
| 1650 | while (*cur != 0) { |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1651 | |
| 1652 | /* input string should be empty or invalid date/time item */ |
| 1653 | if (seq >= sizeof(desig)) |
| 1654 | goto error; |
| 1655 | |
| 1656 | /* T designator must be present for time items */ |
| 1657 | if (*cur == 'T') { |
| 1658 | if (seq <= 3) { |
| 1659 | seq = 3; |
| 1660 | cur++; |
| 1661 | } else |
| 1662 | return 1; |
| 1663 | } else if (seq == 3) |
| 1664 | goto error; |
| 1665 | |
| 1666 | /* parse the number portion of the item */ |
| 1667 | PARSE_NUM(num, cur, num_type); |
| 1668 | |
| 1669 | if ((num_type == -1) || (*cur == 0)) |
| 1670 | goto error; |
| 1671 | |
| 1672 | /* update duration based on item type */ |
| 1673 | while (seq < sizeof(desig)) { |
| 1674 | if (*cur == desig[seq]) { |
| 1675 | |
| 1676 | /* verify numeric type; only seconds can be float */ |
| 1677 | if ((num_type != 0) && (seq < (sizeof(desig)-1))) |
| 1678 | goto error; |
| 1679 | |
| 1680 | switch (seq) { |
| 1681 | case 0: |
| 1682 | dur->value.dur.mon = (long)num * 12; |
| 1683 | break; |
| 1684 | case 1: |
| 1685 | dur->value.dur.mon += (long)num; |
| 1686 | break; |
| 1687 | default: |
| 1688 | /* convert to seconds using multiplier */ |
| 1689 | dur->value.dur.sec += num * multi[seq]; |
| 1690 | seq++; |
| 1691 | break; |
| 1692 | } |
| 1693 | |
| 1694 | break; /* exit loop */ |
| 1695 | } |
| 1696 | /* no date designators found? */ |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 1697 | if ((++seq == 3) || (seq == 6)) |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1698 | goto error; |
| 1699 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1700 | cur++; |
| 1701 | if (collapse) |
| 1702 | while IS_WSP_BLANK_CH(*cur) cur++; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | if (isneg) { |
| 1706 | dur->value.dur.mon = -dur->value.dur.mon; |
| 1707 | dur->value.dur.day = -dur->value.dur.day; |
| 1708 | dur->value.dur.sec = -dur->value.dur.sec; |
| 1709 | } |
| 1710 | |
| 1711 | if (val != NULL) |
| 1712 | *val = dur; |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 1713 | else |
| 1714 | xmlSchemaFreeValue(dur); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 1715 | |
| 1716 | return 0; |
| 1717 | |
| 1718 | error: |
| 1719 | if (dur != NULL) |
| 1720 | xmlSchemaFreeValue(dur); |
| 1721 | return 1; |
| 1722 | } |
| 1723 | |
Daniel Veillard | a1a9d04 | 2003-03-18 16:53:17 +0000 | [diff] [blame] | 1724 | /** |
| 1725 | * xmlSchemaStrip: |
| 1726 | * @value: a value |
| 1727 | * |
| 1728 | * Removes the leading and ending spaces of a string |
| 1729 | * |
| 1730 | * Returns the new string or NULL if no change was required. |
| 1731 | */ |
| 1732 | static xmlChar * |
| 1733 | xmlSchemaStrip(const xmlChar *value) { |
| 1734 | const xmlChar *start = value, *end, *f; |
| 1735 | |
| 1736 | if (value == NULL) return(NULL); |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1737 | while ((*start != 0) && (IS_BLANK_CH(*start))) start++; |
Daniel Veillard | a1a9d04 | 2003-03-18 16:53:17 +0000 | [diff] [blame] | 1738 | end = start; |
| 1739 | while (*end != 0) end++; |
| 1740 | f = end; |
| 1741 | end--; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1742 | while ((end > start) && (IS_BLANK_CH(*end))) end--; |
Daniel Veillard | a1a9d04 | 2003-03-18 16:53:17 +0000 | [diff] [blame] | 1743 | end++; |
| 1744 | if ((start == value) && (f == end)) return(NULL); |
| 1745 | return(xmlStrndup(start, end - start)); |
| 1746 | } |
Daniel Veillard | 96a4b25 | 2003-02-06 08:22:32 +0000 | [diff] [blame] | 1747 | |
| 1748 | /** |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 1749 | * xmlSchemaWhiteSpaceReplace: |
| 1750 | * @value: a value |
| 1751 | * |
| 1752 | * Replaces 0xd, 0x9 and 0xa with a space. |
| 1753 | * |
| 1754 | * Returns the new string or NULL if no change was required. |
| 1755 | */ |
| 1756 | xmlChar * |
| 1757 | xmlSchemaWhiteSpaceReplace(const xmlChar *value) { |
| 1758 | const xmlChar *cur = value; |
| 1759 | xmlChar *ret = NULL, *mcur; |
| 1760 | |
| 1761 | if (value == NULL) |
| 1762 | return(NULL); |
| 1763 | |
| 1764 | while ((*cur != 0) && |
| 1765 | (((*cur) != 0xd) && ((*cur) != 0x9) && ((*cur) != 0xa))) { |
| 1766 | cur++; |
| 1767 | } |
| 1768 | if (*cur == 0) |
| 1769 | return (NULL); |
| 1770 | ret = xmlStrdup(value); |
| 1771 | /* TODO FIXME: I guess gcc will bark at this. */ |
| 1772 | mcur = (xmlChar *) (ret + (cur - value)); |
| 1773 | do { |
| 1774 | if ( ((*mcur) == 0xd) || ((*mcur) == 0x9) || ((*mcur) == 0xa) ) |
| 1775 | *mcur = ' '; |
| 1776 | mcur++; |
| 1777 | } while (*mcur != 0); |
| 1778 | return(ret); |
| 1779 | } |
| 1780 | |
| 1781 | /** |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1782 | * xmlSchemaCollapseString: |
| 1783 | * @value: a value |
| 1784 | * |
| 1785 | * Removes and normalize white spaces in the string |
| 1786 | * |
| 1787 | * Returns the new string or NULL if no change was required. |
| 1788 | */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 1789 | xmlChar * |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1790 | xmlSchemaCollapseString(const xmlChar *value) { |
| 1791 | const xmlChar *start = value, *end, *f; |
| 1792 | xmlChar *g; |
| 1793 | int col = 0; |
| 1794 | |
| 1795 | if (value == NULL) return(NULL); |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1796 | while ((*start != 0) && (IS_BLANK_CH(*start))) start++; |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1797 | end = start; |
| 1798 | while (*end != 0) { |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1799 | if ((*end == ' ') && (IS_BLANK_CH(end[1]))) { |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1800 | col = end - start; |
| 1801 | break; |
| 1802 | } else if ((*end == 0xa) || (*end == 0x9) || (*end == 0xd)) { |
| 1803 | col = end - start; |
| 1804 | break; |
| 1805 | } |
| 1806 | end++; |
| 1807 | } |
| 1808 | if (col == 0) { |
| 1809 | f = end; |
| 1810 | end--; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1811 | while ((end > start) && (IS_BLANK_CH(*end))) end--; |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1812 | end++; |
| 1813 | if ((start == value) && (f == end)) return(NULL); |
| 1814 | return(xmlStrndup(start, end - start)); |
| 1815 | } |
| 1816 | start = xmlStrdup(start); |
| 1817 | if (start == NULL) return(NULL); |
| 1818 | g = (xmlChar *) (start + col); |
| 1819 | end = g; |
| 1820 | while (*end != 0) { |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1821 | if (IS_BLANK_CH(*end)) { |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1822 | end++; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1823 | while (IS_BLANK_CH(*end)) end++; |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1824 | if (*end != 0) |
| 1825 | *g++ = ' '; |
| 1826 | } else |
| 1827 | *g++ = *end++; |
| 1828 | } |
| 1829 | *g = 0; |
| 1830 | return((xmlChar *) start); |
| 1831 | } |
| 1832 | |
| 1833 | /** |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1834 | * xmlSchemaValAtomicListNode: |
| 1835 | * @type: the predefined atomic type for a token in the list |
| 1836 | * @value: the list value to check |
| 1837 | * @ret: the return computed value |
| 1838 | * @node: the node containing the value |
| 1839 | * |
| 1840 | * Check that a value conforms to the lexical space of the predefined |
| 1841 | * list type. if true a value is computed and returned in @ret. |
| 1842 | * |
Daniel Veillard | a1a9d04 | 2003-03-18 16:53:17 +0000 | [diff] [blame] | 1843 | * Returns the number of items if this validates, a negative error code |
| 1844 | * number otherwise |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1845 | */ |
| 1846 | static int |
| 1847 | xmlSchemaValAtomicListNode(xmlSchemaTypePtr type, const xmlChar *value, |
| 1848 | xmlSchemaValPtr *ret, xmlNodePtr node) { |
| 1849 | xmlChar *val, *cur, *endval; |
| 1850 | int nb_values = 0; |
Daniel Veillard | 580ced8 | 2003-03-21 21:22:48 +0000 | [diff] [blame] | 1851 | int tmp = 0; |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1852 | |
| 1853 | if (value == NULL) { |
| 1854 | return(-1); |
| 1855 | } |
| 1856 | val = xmlStrdup(value); |
| 1857 | if (val == NULL) { |
| 1858 | return(-1); |
| 1859 | } |
Daniel Veillard | 6fc5db0 | 2005-01-16 00:05:58 +0000 | [diff] [blame] | 1860 | if (ret != NULL) { |
| 1861 | *ret = NULL; |
| 1862 | } |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1863 | cur = val; |
| 1864 | /* |
| 1865 | * Split the list |
| 1866 | */ |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1867 | while (IS_BLANK_CH(*cur)) *cur++ = 0; |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1868 | while (*cur != 0) { |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1869 | if (IS_BLANK_CH(*cur)) { |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1870 | *cur = 0; |
| 1871 | cur++; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1872 | while (IS_BLANK_CH(*cur)) *cur++ = 0; |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1873 | } else { |
| 1874 | nb_values++; |
| 1875 | cur++; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 1876 | while ((*cur != 0) && (!IS_BLANK_CH(*cur))) cur++; |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1877 | } |
| 1878 | } |
| 1879 | if (nb_values == 0) { |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1880 | xmlFree(val); |
Daniel Veillard | a1a9d04 | 2003-03-18 16:53:17 +0000 | [diff] [blame] | 1881 | return(nb_values); |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1882 | } |
| 1883 | endval = cur; |
| 1884 | cur = val; |
| 1885 | while ((*cur == 0) && (cur != endval)) cur++; |
| 1886 | while (cur != endval) { |
| 1887 | tmp = xmlSchemaValPredefTypeNode(type, cur, NULL, node); |
| 1888 | if (tmp != 0) |
| 1889 | break; |
| 1890 | while (*cur != 0) cur++; |
| 1891 | while ((*cur == 0) && (cur != endval)) cur++; |
| 1892 | } |
Daniel Veillard | 6fc5db0 | 2005-01-16 00:05:58 +0000 | [diff] [blame] | 1893 | /* TODO what return value ? c.f. bug #158628 |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1894 | if (ret != NULL) { |
| 1895 | TODO |
Daniel Veillard | 6fc5db0 | 2005-01-16 00:05:58 +0000 | [diff] [blame] | 1896 | } */ |
| 1897 | xmlFree(val); |
Daniel Veillard | a1a9d04 | 2003-03-18 16:53:17 +0000 | [diff] [blame] | 1898 | if (tmp == 0) |
| 1899 | return(nb_values); |
| 1900 | return(-1); |
Daniel Veillard | 28c52ab | 2003-03-18 11:39:17 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | /** |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 1904 | * xmlSchemaParseUInt: |
| 1905 | * @str: pointer to the string R/W |
| 1906 | * @llo: pointer to the low result |
| 1907 | * @lmi: pointer to the mid result |
| 1908 | * @lhi: pointer to the high result |
| 1909 | * |
| 1910 | * Parse an unsigned long into 3 fields. |
| 1911 | * |
William M. Brack | ec3b4b7 | 2005-03-15 15:50:17 +0000 | [diff] [blame] | 1912 | * Returns the number of significant digits in the number or |
| 1913 | * -1 if overflow of the capacity |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 1914 | */ |
| 1915 | static int |
| 1916 | xmlSchemaParseUInt(const xmlChar **str, unsigned long *llo, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1917 | unsigned long *lmi, unsigned long *lhi) { |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 1918 | unsigned long lo = 0, mi = 0, hi = 0; |
| 1919 | const xmlChar *tmp, *cur = *str; |
| 1920 | int ret = 0, i = 0; |
| 1921 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1922 | while (*cur == '0') { /* ignore leading zeroes */ |
| 1923 | cur++; |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 1924 | } |
| 1925 | tmp = cur; |
| 1926 | while ((*tmp != 0) && (*tmp >= '0') && (*tmp <= '9')) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1927 | i++;tmp++;ret++; |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 1928 | } |
| 1929 | if (i > 24) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1930 | *str = tmp; |
| 1931 | return(-1); |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 1932 | } |
| 1933 | while (i > 16) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1934 | hi = hi * 10 + (*cur++ - '0'); |
| 1935 | i--; |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 1936 | } |
| 1937 | while (i > 8) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1938 | mi = mi * 10 + (*cur++ - '0'); |
| 1939 | i--; |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 1940 | } |
| 1941 | while (i > 0) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 1942 | lo = lo * 10 + (*cur++ - '0'); |
| 1943 | i--; |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | *str = cur; |
| 1947 | *llo = lo; |
| 1948 | *lmi = mi; |
| 1949 | *lhi = hi; |
| 1950 | return(ret); |
| 1951 | } |
| 1952 | |
| 1953 | /** |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1954 | * xmlSchemaValAtomicType: |
| 1955 | * @type: the predefined type |
| 1956 | * @value: the value to check |
| 1957 | * @val: the return computed value |
| 1958 | * @node: the node containing the value |
| 1959 | * flags: flags to control the vlidation |
| 1960 | * |
| 1961 | * Check that a value conforms to the lexical space of the atomic type. |
| 1962 | * if true a value is computed and returned in @val. |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 1963 | * This checks the value space for list types as well (IDREFS, NMTOKENS). |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1964 | * |
| 1965 | * Returns 0 if this validates, a positive error code number otherwise |
| 1966 | * and -1 in case of internal or API error. |
| 1967 | */ |
| 1968 | static int |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 1969 | xmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value, |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 1970 | xmlSchemaValPtr * val, xmlNodePtr node, int flags, |
| 1971 | xmlSchemaWhitespaceValueType ws, |
| 1972 | int normOnTheFly, int applyNorm, int createStringValue) |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 1973 | { |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1974 | xmlSchemaValPtr v; |
| 1975 | xmlChar *norm = NULL; |
Daniel Veillard | d3b9cd8 | 2003-04-09 11:24:17 +0000 | [diff] [blame] | 1976 | int ret = 0; |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1977 | |
| 1978 | if (xmlSchemaTypesInitialized == 0) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 1979 | xmlSchemaInitTypes(); |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1980 | if (type == NULL) |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 1981 | return (-1); |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1982 | |
Daniel Veillard | eebd633 | 2004-08-26 10:30:44 +0000 | [diff] [blame] | 1983 | /* |
| 1984 | * validating a non existant text node is similar to validating |
| 1985 | * an empty one. |
| 1986 | */ |
| 1987 | if (value == NULL) |
| 1988 | value = BAD_CAST ""; |
| 1989 | |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1990 | if (val != NULL) |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 1991 | *val = NULL; |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 1992 | if ((flags == 0) && (value != NULL)) { |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 1993 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 1994 | if ((type->builtInType != XML_SCHEMAS_STRING) && |
Kasimier T. Buchcik | 91feaf8 | 2004-11-12 14:04:58 +0000 | [diff] [blame] | 1995 | (type->builtInType != XML_SCHEMAS_ANYTYPE) && |
| 1996 | (type->builtInType != XML_SCHEMAS_ANYSIMPLETYPE)) { |
| 1997 | if (type->builtInType == XML_SCHEMAS_NORMSTRING) |
| 1998 | norm = xmlSchemaWhiteSpaceReplace(value); |
| 1999 | else |
| 2000 | norm = xmlSchemaCollapseString(value); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2001 | if (norm != NULL) |
| 2002 | value = norm; |
| 2003 | } |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2006 | switch (type->builtInType) { |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2007 | case XML_SCHEMAS_UNKNOWN: |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2008 | goto error; |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2009 | case XML_SCHEMAS_ANYTYPE: |
| 2010 | case XML_SCHEMAS_ANYSIMPLETYPE: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2011 | if ((createStringValue) && (val != NULL)) { |
| 2012 | v = xmlSchemaNewValue(XML_SCHEMAS_ANYSIMPLETYPE); |
| 2013 | if (v != NULL) { |
| 2014 | v->value.str = xmlStrdup(value); |
| 2015 | *val = v; |
| 2016 | } else { |
| 2017 | goto error; |
| 2018 | } |
| 2019 | } |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 2020 | goto return0; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2021 | case XML_SCHEMAS_STRING: |
| 2022 | if (! normOnTheFly) { |
| 2023 | const xmlChar *cur = value; |
| 2024 | |
| 2025 | if (ws == XML_SCHEMA_WHITESPACE_REPLACE) { |
| 2026 | while (*cur != 0) { |
| 2027 | if ((*cur == 0xd) || (*cur == 0xa) || (*cur == 0x9)) { |
| 2028 | goto return1; |
| 2029 | } else { |
| 2030 | cur++; |
| 2031 | } |
| 2032 | } |
| 2033 | } else if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) { |
| 2034 | while (*cur != 0) { |
| 2035 | if ((*cur == 0xd) || (*cur == 0xa) || (*cur == 0x9)) { |
| 2036 | goto return1; |
| 2037 | } else if IS_WSP_SPACE_CH(*cur) { |
| 2038 | cur++; |
| 2039 | if IS_WSP_SPACE_CH(*cur) |
| 2040 | goto return1; |
| 2041 | } else { |
| 2042 | cur++; |
| 2043 | } |
| 2044 | } |
| 2045 | } |
| 2046 | } |
| 2047 | if (createStringValue && (val != NULL)) { |
| 2048 | if (applyNorm) { |
| 2049 | if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
| 2050 | norm = xmlSchemaCollapseString(value); |
| 2051 | else if (ws == XML_SCHEMA_WHITESPACE_REPLACE) |
| 2052 | norm = xmlSchemaWhiteSpaceReplace(value); |
| 2053 | if (norm != NULL) |
| 2054 | value = norm; |
| 2055 | } |
| 2056 | v = xmlSchemaNewValue(XML_SCHEMAS_STRING); |
| 2057 | if (v != NULL) { |
| 2058 | v->value.str = xmlStrdup(value); |
| 2059 | *val = v; |
| 2060 | } else { |
| 2061 | goto error; |
| 2062 | } |
| 2063 | } |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2064 | goto return0; |
Daniel Veillard | 1516d5b | 2004-01-22 07:27:45 +0000 | [diff] [blame] | 2065 | case XML_SCHEMAS_NORMSTRING:{ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2066 | if (normOnTheFly) { |
| 2067 | if (applyNorm) { |
| 2068 | if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
| 2069 | norm = xmlSchemaCollapseString(value); |
| 2070 | else |
| 2071 | norm = xmlSchemaWhiteSpaceReplace(value); |
| 2072 | if (norm != NULL) |
| 2073 | value = norm; |
| 2074 | } |
| 2075 | } else { |
| 2076 | const xmlChar *cur = value; |
| 2077 | while (*cur != 0) { |
| 2078 | if ((*cur == 0xd) || (*cur == 0xa) || (*cur == 0x9)) { |
| 2079 | goto return1; |
| 2080 | } else { |
| 2081 | cur++; |
| 2082 | } |
| 2083 | } |
| 2084 | } |
Daniel Veillard | 1516d5b | 2004-01-22 07:27:45 +0000 | [diff] [blame] | 2085 | if (val != NULL) { |
| 2086 | v = xmlSchemaNewValue(XML_SCHEMAS_NORMSTRING); |
| 2087 | if (v != NULL) { |
| 2088 | v->value.str = xmlStrdup(value); |
| 2089 | *val = v; |
| 2090 | } else { |
| 2091 | goto error; |
| 2092 | } |
| 2093 | } |
| 2094 | goto return0; |
| 2095 | } |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2096 | case XML_SCHEMAS_DECIMAL:{ |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2097 | const xmlChar *cur = value; |
| 2098 | unsigned int len, neg = 0; |
| 2099 | xmlChar cval[25]; |
| 2100 | xmlChar *cptr = cval; |
| 2101 | int dec = -1; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2102 | |
| 2103 | if (cur == NULL) |
| 2104 | goto return1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2105 | |
| 2106 | if (normOnTheFly) |
| 2107 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 2108 | |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2109 | /* First we handle an optional sign */ |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2110 | if (*cur == '+') |
| 2111 | cur++; |
| 2112 | else if (*cur == '-') { |
| 2113 | neg = 1; |
| 2114 | cur++; |
| 2115 | } |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2116 | /* |
| 2117 | * Next we "pre-parse" the number, in preparation for calling |
| 2118 | * the common routine xmlSchemaParseUInt. We get rid of any |
| 2119 | * leading zeroes (because we have reserved only 25 chars), |
| 2120 | * and note the position of any decimal point. |
| 2121 | */ |
| 2122 | len = 0; |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 2123 | /* |
| 2124 | * Skip leading zeroes. |
| 2125 | */ |
| 2126 | while (*cur == '0') |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2127 | cur++; |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 2128 | if (*cur != 0) { |
| 2129 | while (len < 24) { |
| 2130 | if ((*cur >= '0') && (*cur <= '9')) { |
| 2131 | *cptr++ = *cur++; |
| 2132 | len++; |
| 2133 | } else if (*cur == '.') { |
| 2134 | if (dec != -1) |
| 2135 | goto return1; /* multiple decimal points */ |
| 2136 | cur++; |
| 2137 | if ((*cur == 0) && (cur -1 == value)) |
| 2138 | goto return1; |
| 2139 | |
| 2140 | dec = len; |
| 2141 | while ((len < 24) && (*cur >= '0') && |
| 2142 | (*cur <= '9')) { |
| 2143 | *cptr++ = *cur++; |
| 2144 | len++; |
| 2145 | } |
| 2146 | break; |
| 2147 | } else |
| 2148 | break; |
| 2149 | } |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2150 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2151 | if (normOnTheFly) |
| 2152 | while IS_WSP_BLANK_CH(*cur) cur++; |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2153 | if (*cur != 0) |
| 2154 | goto return1; /* error if any extraneous chars */ |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2155 | if (val != NULL) { |
| 2156 | v = xmlSchemaNewValue(XML_SCHEMAS_DECIMAL); |
| 2157 | if (v != NULL) { |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2158 | /* |
| 2159 | * If a mixed decimal, get rid of trailing zeroes |
| 2160 | */ |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 2161 | if (dec != -1) { |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2162 | while ((cptr > cval) && (*(cptr-1) == '0')) { |
| 2163 | cptr--; |
| 2164 | len--; |
| 2165 | } |
| 2166 | } |
| 2167 | *cptr = 0; /* Terminate our (preparsed) string */ |
| 2168 | cptr = cval; |
| 2169 | /* |
| 2170 | * Now evaluate the significant digits of the number |
| 2171 | */ |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 2172 | if (*cptr != 0) |
| 2173 | xmlSchemaParseUInt((const xmlChar **)&cptr, |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2174 | &v->value.decimal.lo, |
| 2175 | &v->value.decimal.mi, |
| 2176 | &v->value.decimal.hi); |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 2177 | /* |
| 2178 | * Set the total digits to 1 if a zero value. |
| 2179 | */ |
| 2180 | if (len == 0) |
| 2181 | len++; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2182 | v->value.decimal.sign = neg; |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2183 | if (dec == -1) { |
| 2184 | v->value.decimal.frac = 0; |
| 2185 | v->value.decimal.total = len; |
| 2186 | } else { |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 2187 | v->value.decimal.frac = len - dec; |
| 2188 | v->value.decimal.total = len; |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 2189 | } |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2190 | *val = v; |
| 2191 | } |
| 2192 | } |
| 2193 | goto return0; |
| 2194 | } |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 2195 | case XML_SCHEMAS_TIME: |
| 2196 | case XML_SCHEMAS_GDAY: |
| 2197 | case XML_SCHEMAS_GMONTH: |
| 2198 | case XML_SCHEMAS_GMONTHDAY: |
| 2199 | case XML_SCHEMAS_GYEAR: |
| 2200 | case XML_SCHEMAS_GYEARMONTH: |
| 2201 | case XML_SCHEMAS_DATE: |
| 2202 | case XML_SCHEMAS_DATETIME: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2203 | ret = xmlSchemaValidateDates(type->builtInType, value, val, |
| 2204 | normOnTheFly); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2205 | break; |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 2206 | case XML_SCHEMAS_DURATION: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2207 | ret = xmlSchemaValidateDuration(type, value, val, |
| 2208 | normOnTheFly); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2209 | break; |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 2210 | case XML_SCHEMAS_FLOAT: |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2211 | case XML_SCHEMAS_DOUBLE:{ |
| 2212 | const xmlChar *cur = value; |
| 2213 | int neg = 0; |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 2214 | |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2215 | if (cur == NULL) |
Daniel Veillard | 70bcb0e | 2003-08-08 14:00:28 +0000 | [diff] [blame] | 2216 | goto return1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2217 | |
| 2218 | if (normOnTheFly) |
| 2219 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 2220 | |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2221 | if ((cur[0] == 'N') && (cur[1] == 'a') && (cur[2] == 'N')) { |
| 2222 | cur += 3; |
| 2223 | if (*cur != 0) |
| 2224 | goto return1; |
| 2225 | if (val != NULL) { |
| 2226 | if (type == xmlSchemaTypeFloatDef) { |
| 2227 | v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT); |
| 2228 | if (v != NULL) { |
| 2229 | v->value.f = (float) xmlXPathNAN; |
| 2230 | } else { |
| 2231 | xmlSchemaFreeValue(v); |
| 2232 | goto error; |
| 2233 | } |
| 2234 | } else { |
| 2235 | v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE); |
| 2236 | if (v != NULL) { |
| 2237 | v->value.d = xmlXPathNAN; |
| 2238 | } else { |
| 2239 | xmlSchemaFreeValue(v); |
| 2240 | goto error; |
| 2241 | } |
| 2242 | } |
| 2243 | *val = v; |
| 2244 | } |
| 2245 | goto return0; |
| 2246 | } |
| 2247 | if (*cur == '-') { |
| 2248 | neg = 1; |
| 2249 | cur++; |
| 2250 | } |
| 2251 | if ((cur[0] == 'I') && (cur[1] == 'N') && (cur[2] == 'F')) { |
| 2252 | cur += 3; |
| 2253 | if (*cur != 0) |
| 2254 | goto return1; |
| 2255 | if (val != NULL) { |
| 2256 | if (type == xmlSchemaTypeFloatDef) { |
| 2257 | v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT); |
| 2258 | if (v != NULL) { |
| 2259 | if (neg) |
| 2260 | v->value.f = (float) xmlXPathNINF; |
| 2261 | else |
| 2262 | v->value.f = (float) xmlXPathPINF; |
| 2263 | } else { |
| 2264 | xmlSchemaFreeValue(v); |
| 2265 | goto error; |
| 2266 | } |
| 2267 | } else { |
| 2268 | v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE); |
| 2269 | if (v != NULL) { |
| 2270 | if (neg) |
| 2271 | v->value.d = xmlXPathNINF; |
| 2272 | else |
| 2273 | v->value.d = xmlXPathPINF; |
| 2274 | } else { |
| 2275 | xmlSchemaFreeValue(v); |
| 2276 | goto error; |
| 2277 | } |
| 2278 | } |
| 2279 | *val = v; |
| 2280 | } |
| 2281 | goto return0; |
| 2282 | } |
| 2283 | if ((neg == 0) && (*cur == '+')) |
| 2284 | cur++; |
| 2285 | if ((cur[0] == 0) || (cur[0] == '+') || (cur[0] == '-')) |
| 2286 | goto return1; |
| 2287 | while ((*cur >= '0') && (*cur <= '9')) { |
| 2288 | cur++; |
| 2289 | } |
| 2290 | if (*cur == '.') { |
| 2291 | cur++; |
| 2292 | while ((*cur >= '0') && (*cur <= '9')) |
| 2293 | cur++; |
| 2294 | } |
| 2295 | if ((*cur == 'e') || (*cur == 'E')) { |
| 2296 | cur++; |
| 2297 | if ((*cur == '-') || (*cur == '+')) |
| 2298 | cur++; |
| 2299 | while ((*cur >= '0') && (*cur <= '9')) |
| 2300 | cur++; |
| 2301 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2302 | if (normOnTheFly) |
| 2303 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 2304 | |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2305 | if (*cur != 0) |
| 2306 | goto return1; |
| 2307 | if (val != NULL) { |
| 2308 | if (type == xmlSchemaTypeFloatDef) { |
| 2309 | v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT); |
| 2310 | if (v != NULL) { |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 2311 | /* |
| 2312 | * TODO: sscanf seems not to give the correct |
| 2313 | * value for extremely high/low values. |
| 2314 | * E.g. "1E-149" results in zero. |
| 2315 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2316 | if (sscanf((const char *) value, "%f", |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2317 | &(v->value.f)) == 1) { |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 2318 | *val = v; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2319 | } else { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2320 | xmlSchemaFreeValue(v); |
| 2321 | goto return1; |
| 2322 | } |
| 2323 | } else { |
| 2324 | goto error; |
| 2325 | } |
| 2326 | } else { |
| 2327 | v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE); |
| 2328 | if (v != NULL) { |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 2329 | /* |
| 2330 | * TODO: sscanf seems not to give the correct |
| 2331 | * value for extremely high/low values. |
| 2332 | */ |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2333 | if (sscanf((const char *) value, "%lf", |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2334 | &(v->value.d)) == 1) { |
| 2335 | *val = v; |
| 2336 | } else { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2337 | xmlSchemaFreeValue(v); |
| 2338 | goto return1; |
| 2339 | } |
| 2340 | } else { |
| 2341 | goto error; |
| 2342 | } |
| 2343 | } |
| 2344 | } |
| 2345 | goto return0; |
Daniel Veillard | 70bcb0e | 2003-08-08 14:00:28 +0000 | [diff] [blame] | 2346 | } |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2347 | case XML_SCHEMAS_BOOLEAN:{ |
| 2348 | const xmlChar *cur = value; |
| 2349 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2350 | if (normOnTheFly) { |
| 2351 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 2352 | if (*cur == '0') { |
| 2353 | ret = 0; |
| 2354 | cur++; |
| 2355 | } else if (*cur == '1') { |
| 2356 | ret = 1; |
| 2357 | cur++; |
| 2358 | } else if (*cur == 't') { |
| 2359 | cur++; |
| 2360 | if ((*cur++ == 'r') && (*cur++ == 'u') && |
| 2361 | (*cur++ == 'e')) { |
| 2362 | ret = 1; |
| 2363 | } else |
| 2364 | goto return1; |
| 2365 | } else if (*cur == 'f') { |
| 2366 | cur++; |
| 2367 | if ((*cur++ == 'a') && (*cur++ == 'l') && |
| 2368 | (*cur++ == 's') && (*cur++ == 'e')) { |
| 2369 | ret = 0; |
| 2370 | } else |
| 2371 | goto return1; |
| 2372 | } |
| 2373 | if (*cur != 0) { |
| 2374 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 2375 | if (*cur != 0) |
| 2376 | goto return1; |
| 2377 | } |
| 2378 | } else { |
| 2379 | if ((cur[0] == '0') && (cur[1] == 0)) |
| 2380 | ret = 0; |
| 2381 | else if ((cur[0] == '1') && (cur[1] == 0)) |
| 2382 | ret = 1; |
| 2383 | else if ((cur[0] == 't') && (cur[1] == 'r') |
| 2384 | && (cur[2] == 'u') && (cur[3] == 'e') |
| 2385 | && (cur[4] == 0)) |
| 2386 | ret = 1; |
| 2387 | else if ((cur[0] == 'f') && (cur[1] == 'a') |
| 2388 | && (cur[2] == 'l') && (cur[3] == 's') |
| 2389 | && (cur[4] == 'e') && (cur[5] == 0)) |
| 2390 | ret = 0; |
| 2391 | else |
| 2392 | goto return1; |
| 2393 | } |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2394 | if (val != NULL) { |
| 2395 | v = xmlSchemaNewValue(XML_SCHEMAS_BOOLEAN); |
| 2396 | if (v != NULL) { |
| 2397 | v->value.b = ret; |
| 2398 | *val = v; |
| 2399 | } else { |
| 2400 | goto error; |
| 2401 | } |
| 2402 | } |
| 2403 | goto return0; |
| 2404 | } |
| 2405 | case XML_SCHEMAS_TOKEN:{ |
| 2406 | const xmlChar *cur = value; |
| 2407 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2408 | if (! normOnTheFly) { |
| 2409 | while (*cur != 0) { |
| 2410 | if ((*cur == 0xd) || (*cur == 0xa) || (*cur == 0x9)) { |
| 2411 | goto return1; |
| 2412 | } else if (*cur == ' ') { |
| 2413 | cur++; |
| 2414 | if (*cur == 0) |
| 2415 | goto return1; |
| 2416 | if (*cur == ' ') |
| 2417 | goto return1; |
| 2418 | } else { |
| 2419 | cur++; |
| 2420 | } |
| 2421 | } |
| 2422 | } |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2423 | if (val != NULL) { |
| 2424 | v = xmlSchemaNewValue(XML_SCHEMAS_TOKEN); |
| 2425 | if (v != NULL) { |
| 2426 | v->value.str = xmlStrdup(value); |
| 2427 | *val = v; |
| 2428 | } else { |
| 2429 | goto error; |
| 2430 | } |
| 2431 | } |
| 2432 | goto return0; |
| 2433 | } |
| 2434 | case XML_SCHEMAS_LANGUAGE: |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2435 | if (normOnTheFly) { |
| 2436 | norm = xmlSchemaCollapseString(value); |
| 2437 | if (norm != NULL) |
| 2438 | value = norm; |
| 2439 | } |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2440 | if (xmlCheckLanguageID(value) == 1) { |
| 2441 | if (val != NULL) { |
| 2442 | v = xmlSchemaNewValue(XML_SCHEMAS_LANGUAGE); |
| 2443 | if (v != NULL) { |
| 2444 | v->value.str = xmlStrdup(value); |
| 2445 | *val = v; |
| 2446 | } else { |
| 2447 | goto error; |
| 2448 | } |
| 2449 | } |
| 2450 | goto return0; |
| 2451 | } |
| 2452 | goto return1; |
| 2453 | case XML_SCHEMAS_NMTOKEN: |
| 2454 | if (xmlValidateNMToken(value, 1) == 0) { |
| 2455 | if (val != NULL) { |
| 2456 | v = xmlSchemaNewValue(XML_SCHEMAS_NMTOKEN); |
| 2457 | if (v != NULL) { |
| 2458 | v->value.str = xmlStrdup(value); |
| 2459 | *val = v; |
| 2460 | } else { |
| 2461 | goto error; |
| 2462 | } |
| 2463 | } |
| 2464 | goto return0; |
| 2465 | } |
| 2466 | goto return1; |
| 2467 | case XML_SCHEMAS_NMTOKENS: |
| 2468 | ret = xmlSchemaValAtomicListNode(xmlSchemaTypeNmtokenDef, |
| 2469 | value, val, node); |
| 2470 | if (ret > 0) |
| 2471 | ret = 0; |
| 2472 | else |
| 2473 | ret = 1; |
| 2474 | goto done; |
| 2475 | case XML_SCHEMAS_NAME: |
| 2476 | ret = xmlValidateName(value, 1); |
Daniel Veillard | df292f7 | 2005-01-16 19:00:15 +0000 | [diff] [blame] | 2477 | if ((ret == 0) && (val != NULL) && (value != NULL)) { |
| 2478 | v = xmlSchemaNewValue(XML_SCHEMAS_NAME); |
| 2479 | if (v != NULL) { |
| 2480 | const xmlChar *start = value, *end; |
| 2481 | while (IS_BLANK_CH(*start)) start++; |
| 2482 | end = start; |
| 2483 | while ((*end != 0) && (!IS_BLANK_CH(*end))) end++; |
| 2484 | v->value.str = xmlStrndup(start, end - start); |
| 2485 | *val = v; |
| 2486 | } else { |
| 2487 | goto error; |
| 2488 | } |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2489 | } |
| 2490 | goto done; |
| 2491 | case XML_SCHEMAS_QNAME:{ |
| 2492 | xmlChar *uri = NULL; |
| 2493 | xmlChar *local = NULL; |
| 2494 | |
| 2495 | ret = xmlValidateQName(value, 1); |
| 2496 | if ((ret == 0) && (node != NULL)) { |
| 2497 | xmlChar *prefix; |
| 2498 | |
| 2499 | local = xmlSplitQName2(value, &prefix); |
| 2500 | if (prefix != NULL) { |
| 2501 | xmlNsPtr ns; |
| 2502 | |
| 2503 | ns = xmlSearchNs(node->doc, node, prefix); |
| 2504 | if (ns == NULL) |
| 2505 | ret = 1; |
| 2506 | else if (val != NULL) |
| 2507 | uri = xmlStrdup(ns->href); |
| 2508 | } |
| 2509 | if ((local != NULL) && ((val == NULL) || (ret != 0))) |
| 2510 | xmlFree(local); |
| 2511 | if (prefix != NULL) |
| 2512 | xmlFree(prefix); |
| 2513 | } |
| 2514 | if ((ret == 0) && (val != NULL)) { |
| 2515 | v = xmlSchemaNewValue(XML_SCHEMAS_QNAME); |
| 2516 | if (v != NULL) { |
| 2517 | if (local != NULL) |
| 2518 | v->value.qname.name = local; |
| 2519 | else |
| 2520 | v->value.qname.name = xmlStrdup(value); |
| 2521 | if (uri != NULL) |
| 2522 | v->value.qname.uri = uri; |
| 2523 | |
| 2524 | *val = v; |
| 2525 | } else { |
| 2526 | if (local != NULL) |
| 2527 | xmlFree(local); |
| 2528 | if (uri != NULL) |
| 2529 | xmlFree(uri); |
| 2530 | goto error; |
| 2531 | } |
| 2532 | } |
| 2533 | goto done; |
| 2534 | } |
| 2535 | case XML_SCHEMAS_NCNAME: |
| 2536 | ret = xmlValidateNCName(value, 1); |
| 2537 | if ((ret == 0) && (val != NULL)) { |
| 2538 | v = xmlSchemaNewValue(XML_SCHEMAS_NCNAME); |
| 2539 | if (v != NULL) { |
| 2540 | v->value.str = xmlStrdup(value); |
| 2541 | *val = v; |
| 2542 | } else { |
| 2543 | goto error; |
| 2544 | } |
| 2545 | } |
| 2546 | goto done; |
| 2547 | case XML_SCHEMAS_ID: |
| 2548 | ret = xmlValidateNCName(value, 1); |
| 2549 | if ((ret == 0) && (val != NULL)) { |
| 2550 | v = xmlSchemaNewValue(XML_SCHEMAS_ID); |
| 2551 | if (v != NULL) { |
| 2552 | v->value.str = xmlStrdup(value); |
| 2553 | *val = v; |
| 2554 | } else { |
| 2555 | goto error; |
| 2556 | } |
| 2557 | } |
| 2558 | if ((ret == 0) && (node != NULL) && |
| 2559 | (node->type == XML_ATTRIBUTE_NODE)) { |
| 2560 | xmlAttrPtr attr = (xmlAttrPtr) node; |
| 2561 | |
| 2562 | /* |
| 2563 | * NOTE: the IDness might have already be declared in the DTD |
| 2564 | */ |
| 2565 | if (attr->atype != XML_ATTRIBUTE_ID) { |
| 2566 | xmlIDPtr res; |
| 2567 | xmlChar *strip; |
| 2568 | |
| 2569 | strip = xmlSchemaStrip(value); |
| 2570 | if (strip != NULL) { |
| 2571 | res = xmlAddID(NULL, node->doc, strip, attr); |
| 2572 | xmlFree(strip); |
| 2573 | } else |
| 2574 | res = xmlAddID(NULL, node->doc, value, attr); |
| 2575 | if (res == NULL) { |
| 2576 | ret = 2; |
| 2577 | } else { |
| 2578 | attr->atype = XML_ATTRIBUTE_ID; |
| 2579 | } |
| 2580 | } |
| 2581 | } |
| 2582 | goto done; |
| 2583 | case XML_SCHEMAS_IDREF: |
| 2584 | ret = xmlValidateNCName(value, 1); |
| 2585 | if ((ret == 0) && (val != NULL)) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 2586 | v = xmlSchemaNewValue(XML_SCHEMAS_IDREF); |
| 2587 | if (v == NULL) |
| 2588 | goto error; |
| 2589 | v->value.str = xmlStrdup(value); |
| 2590 | *val = v; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2591 | } |
| 2592 | if ((ret == 0) && (node != NULL) && |
| 2593 | (node->type == XML_ATTRIBUTE_NODE)) { |
| 2594 | xmlAttrPtr attr = (xmlAttrPtr) node; |
| 2595 | xmlChar *strip; |
| 2596 | |
| 2597 | strip = xmlSchemaStrip(value); |
| 2598 | if (strip != NULL) { |
| 2599 | xmlAddRef(NULL, node->doc, strip, attr); |
| 2600 | xmlFree(strip); |
| 2601 | } else |
| 2602 | xmlAddRef(NULL, node->doc, value, attr); |
| 2603 | attr->atype = XML_ATTRIBUTE_IDREF; |
| 2604 | } |
| 2605 | goto done; |
| 2606 | case XML_SCHEMAS_IDREFS: |
| 2607 | ret = xmlSchemaValAtomicListNode(xmlSchemaTypeIdrefDef, |
| 2608 | value, val, node); |
| 2609 | if (ret < 0) |
| 2610 | ret = 2; |
| 2611 | else |
| 2612 | ret = 0; |
| 2613 | if ((ret == 0) && (node != NULL) && |
| 2614 | (node->type == XML_ATTRIBUTE_NODE)) { |
| 2615 | xmlAttrPtr attr = (xmlAttrPtr) node; |
| 2616 | |
| 2617 | attr->atype = XML_ATTRIBUTE_IDREFS; |
| 2618 | } |
| 2619 | goto done; |
| 2620 | case XML_SCHEMAS_ENTITY:{ |
| 2621 | xmlChar *strip; |
| 2622 | |
| 2623 | ret = xmlValidateNCName(value, 1); |
| 2624 | if ((node == NULL) || (node->doc == NULL)) |
| 2625 | ret = 3; |
| 2626 | if (ret == 0) { |
| 2627 | xmlEntityPtr ent; |
| 2628 | |
| 2629 | strip = xmlSchemaStrip(value); |
| 2630 | if (strip != NULL) { |
| 2631 | ent = xmlGetDocEntity(node->doc, strip); |
| 2632 | xmlFree(strip); |
| 2633 | } else { |
| 2634 | ent = xmlGetDocEntity(node->doc, value); |
| 2635 | } |
| 2636 | if ((ent == NULL) || |
| 2637 | (ent->etype != |
| 2638 | XML_EXTERNAL_GENERAL_UNPARSED_ENTITY)) |
| 2639 | ret = 4; |
| 2640 | } |
| 2641 | if ((ret == 0) && (val != NULL)) { |
| 2642 | TODO; |
| 2643 | } |
| 2644 | if ((ret == 0) && (node != NULL) && |
| 2645 | (node->type == XML_ATTRIBUTE_NODE)) { |
| 2646 | xmlAttrPtr attr = (xmlAttrPtr) node; |
| 2647 | |
| 2648 | attr->atype = XML_ATTRIBUTE_ENTITY; |
| 2649 | } |
| 2650 | goto done; |
| 2651 | } |
| 2652 | case XML_SCHEMAS_ENTITIES: |
| 2653 | if ((node == NULL) || (node->doc == NULL)) |
| 2654 | goto return3; |
| 2655 | ret = xmlSchemaValAtomicListNode(xmlSchemaTypeEntityDef, |
| 2656 | value, val, node); |
| 2657 | if (ret <= 0) |
| 2658 | ret = 1; |
| 2659 | else |
| 2660 | ret = 0; |
| 2661 | if ((ret == 0) && (node != NULL) && |
| 2662 | (node->type == XML_ATTRIBUTE_NODE)) { |
| 2663 | xmlAttrPtr attr = (xmlAttrPtr) node; |
| 2664 | |
| 2665 | attr->atype = XML_ATTRIBUTE_ENTITIES; |
| 2666 | } |
| 2667 | goto done; |
| 2668 | case XML_SCHEMAS_NOTATION:{ |
| 2669 | xmlChar *uri = NULL; |
| 2670 | xmlChar *local = NULL; |
| 2671 | |
| 2672 | ret = xmlValidateQName(value, 1); |
| 2673 | if ((ret == 0) && (node != NULL)) { |
| 2674 | xmlChar *prefix; |
| 2675 | |
| 2676 | local = xmlSplitQName2(value, &prefix); |
| 2677 | if (prefix != NULL) { |
| 2678 | xmlNsPtr ns; |
| 2679 | |
| 2680 | ns = xmlSearchNs(node->doc, node, prefix); |
| 2681 | if (ns == NULL) |
| 2682 | ret = 1; |
| 2683 | else if (val != NULL) |
| 2684 | uri = xmlStrdup(ns->href); |
| 2685 | } |
| 2686 | if ((local != NULL) && ((val == NULL) || (ret != 0))) |
| 2687 | xmlFree(local); |
| 2688 | if (prefix != NULL) |
| 2689 | xmlFree(prefix); |
| 2690 | } |
| 2691 | if ((node == NULL) || (node->doc == NULL)) |
| 2692 | ret = 3; |
| 2693 | if (ret == 0) { |
| 2694 | ret = xmlValidateNotationUse(NULL, node->doc, value); |
| 2695 | if (ret == 1) |
| 2696 | ret = 0; |
| 2697 | else |
| 2698 | ret = 1; |
| 2699 | } |
| 2700 | if ((ret == 0) && (val != NULL)) { |
| 2701 | v = xmlSchemaNewValue(XML_SCHEMAS_NOTATION); |
| 2702 | if (v != NULL) { |
| 2703 | if (local != NULL) |
| 2704 | v->value.qname.name = local; |
| 2705 | else |
| 2706 | v->value.qname.name = xmlStrdup(value); |
| 2707 | if (uri != NULL) |
| 2708 | v->value.qname.uri = uri; |
| 2709 | |
| 2710 | *val = v; |
| 2711 | } else { |
| 2712 | if (local != NULL) |
| 2713 | xmlFree(local); |
| 2714 | if (uri != NULL) |
| 2715 | xmlFree(uri); |
| 2716 | goto error; |
| 2717 | } |
| 2718 | } |
| 2719 | goto done; |
| 2720 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2721 | case XML_SCHEMAS_ANYURI:{ |
Daniel Veillard | 11c466a | 2004-03-14 12:20:15 +0000 | [diff] [blame] | 2722 | if (*value != 0) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2723 | xmlURIPtr uri; |
| 2724 | if (normOnTheFly) { |
| 2725 | norm = xmlSchemaCollapseString(value); |
| 2726 | if (norm != NULL) |
| 2727 | value = norm; |
| 2728 | } |
| 2729 | uri = xmlParseURI((const char *) value); |
Daniel Veillard | 11c466a | 2004-03-14 12:20:15 +0000 | [diff] [blame] | 2730 | if (uri == NULL) |
| 2731 | goto return1; |
| 2732 | xmlFreeURI(uri); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2733 | } |
Daniel Veillard | 11c466a | 2004-03-14 12:20:15 +0000 | [diff] [blame] | 2734 | |
| 2735 | if (val != NULL) { |
| 2736 | v = xmlSchemaNewValue(XML_SCHEMAS_ANYURI); |
| 2737 | if (v == NULL) |
| 2738 | goto error; |
| 2739 | v->value.str = xmlStrdup(value); |
| 2740 | *val = v; |
| 2741 | } |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2742 | goto return0; |
| 2743 | } |
| 2744 | case XML_SCHEMAS_HEXBINARY:{ |
| 2745 | const xmlChar *cur = value; |
| 2746 | xmlChar *base; |
| 2747 | int total, i = 0; |
| 2748 | |
Daniel Veillard | f34a20e | 2004-08-31 08:42:17 +0000 | [diff] [blame] | 2749 | if (cur == NULL) |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2750 | goto return1; |
| 2751 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2752 | if (normOnTheFly) |
| 2753 | while IS_WSP_BLANK_CH(*cur) cur++; |
| 2754 | |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2755 | while (((*cur >= '0') && (*cur <= '9')) || |
| 2756 | ((*cur >= 'A') && (*cur <= 'F')) || |
| 2757 | ((*cur >= 'a') && (*cur <= 'f'))) { |
| 2758 | i++; |
| 2759 | cur++; |
| 2760 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2761 | if (normOnTheFly) |
| 2762 | while IS_WSP_BLANK_CH(*cur) cur++; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2763 | |
| 2764 | if (*cur != 0) |
| 2765 | goto return1; |
| 2766 | if ((i % 2) != 0) |
| 2767 | goto return1; |
| 2768 | |
| 2769 | if (val != NULL) { |
| 2770 | |
| 2771 | v = xmlSchemaNewValue(XML_SCHEMAS_HEXBINARY); |
| 2772 | if (v == NULL) |
| 2773 | goto error; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2774 | /* |
| 2775 | * Copy only the normalized piece. |
| 2776 | * CRITICAL TODO: Check this. |
| 2777 | */ |
| 2778 | cur = xmlStrndup(cur, i); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2779 | if (cur == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2780 | xmlSchemaTypeErrMemory(node, "allocating hexbin data"); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2781 | xmlFree(v); |
| 2782 | goto return1; |
| 2783 | } |
| 2784 | |
| 2785 | total = i / 2; /* number of octets */ |
| 2786 | |
| 2787 | base = (xmlChar *) cur; |
| 2788 | while (i-- > 0) { |
| 2789 | if (*base >= 'a') |
| 2790 | *base = *base - ('a' - 'A'); |
| 2791 | base++; |
| 2792 | } |
| 2793 | |
| 2794 | v->value.hex.str = (xmlChar *) cur; |
| 2795 | v->value.hex.total = total; |
| 2796 | *val = v; |
| 2797 | } |
| 2798 | goto return0; |
| 2799 | } |
| 2800 | case XML_SCHEMAS_BASE64BINARY:{ |
| 2801 | /* ISSUE: |
| 2802 | * |
| 2803 | * Ignore all stray characters? (yes, currently) |
| 2804 | * Worry about long lines? (no, currently) |
| 2805 | * |
| 2806 | * rfc2045.txt: |
| 2807 | * |
| 2808 | * "The encoded output stream must be represented in lines of |
| 2809 | * no more than 76 characters each. All line breaks or other |
| 2810 | * characters not found in Table 1 must be ignored by decoding |
| 2811 | * software. In base64 data, characters other than those in |
| 2812 | * Table 1, line breaks, and other white space probably |
| 2813 | * indicate a transmission error, about which a warning |
| 2814 | * message or even a message rejection might be appropriate |
| 2815 | * under some circumstances." */ |
| 2816 | const xmlChar *cur = value; |
| 2817 | xmlChar *base; |
| 2818 | int total, i = 0, pad = 0; |
| 2819 | |
| 2820 | if (cur == NULL) |
| 2821 | goto return1; |
| 2822 | |
| 2823 | for (; *cur; ++cur) { |
| 2824 | int decc; |
| 2825 | |
| 2826 | decc = _xmlSchemaBase64Decode(*cur); |
| 2827 | if (decc < 0) ; |
| 2828 | else if (decc < 64) |
| 2829 | i++; |
| 2830 | else |
| 2831 | break; |
| 2832 | } |
| 2833 | for (; *cur; ++cur) { |
| 2834 | int decc; |
| 2835 | |
| 2836 | decc = _xmlSchemaBase64Decode(*cur); |
| 2837 | if (decc < 0) ; |
| 2838 | else if (decc < 64) |
| 2839 | goto return1; |
| 2840 | if (decc == 64) |
| 2841 | pad++; |
| 2842 | } |
| 2843 | |
| 2844 | /* rfc2045.txt: "Special processing is performed if fewer than |
| 2845 | * 24 bits are available at the end of the data being encoded. |
| 2846 | * A full encoding quantum is always completed at the end of a |
| 2847 | * body. When fewer than 24 input bits are available in an |
| 2848 | * input group, zero bits are added (on the right) to form an |
| 2849 | * integral number of 6-bit groups. Padding at the end of the |
| 2850 | * data is performed using the "=" character. Since all |
| 2851 | * base64 input is an integral number of octets, only the |
| 2852 | * following cases can arise: (1) the final quantum of |
| 2853 | * encoding input is an integral multiple of 24 bits; here, |
| 2854 | * the final unit of encoded output will be an integral |
| 2855 | * multiple ofindent: Standard input:701: Warning:old style |
| 2856 | * assignment ambiguity in "=*". Assuming "= *" 4 characters |
| 2857 | * with no "=" padding, (2) the final |
| 2858 | * quantum of encoding input is exactly 8 bits; here, the |
| 2859 | * final unit of encoded output will be two characters |
| 2860 | * followed by two "=" padding characters, or (3) the final |
| 2861 | * quantum of encoding input is exactly 16 bits; here, the |
| 2862 | * final unit of encoded output will be three characters |
| 2863 | * followed by one "=" padding character." */ |
| 2864 | |
| 2865 | total = 3 * (i / 4); |
| 2866 | if (pad == 0) { |
| 2867 | if (i % 4 != 0) |
| 2868 | goto return1; |
| 2869 | } else if (pad == 1) { |
| 2870 | int decc; |
| 2871 | |
| 2872 | if (i % 4 != 3) |
| 2873 | goto return1; |
| 2874 | for (decc = _xmlSchemaBase64Decode(*cur); |
| 2875 | (decc < 0) || (decc > 63); |
| 2876 | decc = _xmlSchemaBase64Decode(*cur)) |
| 2877 | --cur; |
| 2878 | /* 16bits in 24bits means 2 pad bits: nnnnnn nnmmmm mmmm00*/ |
| 2879 | /* 00111100 -> 0x3c */ |
| 2880 | if (decc & ~0x3c) |
| 2881 | goto return1; |
| 2882 | total += 2; |
| 2883 | } else if (pad == 2) { |
| 2884 | int decc; |
| 2885 | |
| 2886 | if (i % 4 != 2) |
| 2887 | goto return1; |
| 2888 | for (decc = _xmlSchemaBase64Decode(*cur); |
| 2889 | (decc < 0) || (decc > 63); |
| 2890 | decc = _xmlSchemaBase64Decode(*cur)) |
| 2891 | --cur; |
| 2892 | /* 8bits in 12bits means 4 pad bits: nnnnnn nn0000 */ |
| 2893 | /* 00110000 -> 0x30 */ |
| 2894 | if (decc & ~0x30) |
| 2895 | goto return1; |
| 2896 | total += 1; |
| 2897 | } else |
| 2898 | goto return1; |
| 2899 | |
| 2900 | if (val != NULL) { |
| 2901 | v = xmlSchemaNewValue(XML_SCHEMAS_BASE64BINARY); |
| 2902 | if (v == NULL) |
| 2903 | goto error; |
| 2904 | base = |
| 2905 | (xmlChar *) xmlMallocAtomic((i + pad + 1) * |
| 2906 | sizeof(xmlChar)); |
| 2907 | if (base == NULL) { |
Daniel Veillard | d0c9c32 | 2003-10-10 00:49:42 +0000 | [diff] [blame] | 2908 | xmlSchemaTypeErrMemory(node, "allocating base64 data"); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2909 | xmlFree(v); |
| 2910 | goto return1; |
| 2911 | } |
| 2912 | v->value.base64.str = base; |
| 2913 | for (cur = value; *cur; ++cur) |
| 2914 | if (_xmlSchemaBase64Decode(*cur) >= 0) { |
| 2915 | *base = *cur; |
| 2916 | ++base; |
| 2917 | } |
| 2918 | *base = 0; |
| 2919 | v->value.base64.total = total; |
| 2920 | *val = v; |
| 2921 | } |
| 2922 | goto return0; |
| 2923 | } |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 2924 | case XML_SCHEMAS_INTEGER: |
| 2925 | case XML_SCHEMAS_PINTEGER: |
| 2926 | case XML_SCHEMAS_NPINTEGER: |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 2927 | case XML_SCHEMAS_NINTEGER: |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2928 | case XML_SCHEMAS_NNINTEGER:{ |
| 2929 | const xmlChar *cur = value; |
| 2930 | unsigned long lo, mi, hi; |
William M. Brack | ec3b4b7 | 2005-03-15 15:50:17 +0000 | [diff] [blame] | 2931 | int sign = 0; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2932 | |
| 2933 | if (cur == NULL) |
| 2934 | goto return1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2935 | if (normOnTheFly) |
| 2936 | while IS_WSP_BLANK_CH(*cur) cur++; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2937 | if (*cur == '-') { |
| 2938 | sign = 1; |
| 2939 | cur++; |
| 2940 | } else if (*cur == '+') |
| 2941 | cur++; |
William M. Brack | ec3b4b7 | 2005-03-15 15:50:17 +0000 | [diff] [blame] | 2942 | ret = xmlSchemaParseUInt(&cur, &lo, &mi, &hi); |
| 2943 | if (ret == -1) |
| 2944 | goto return1; |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 2945 | if (normOnTheFly) |
| 2946 | while IS_WSP_BLANK_CH(*cur) cur++; |
William M. Brack | ec3b4b7 | 2005-03-15 15:50:17 +0000 | [diff] [blame] | 2947 | if (*cur != 0) |
| 2948 | goto return1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2949 | if (type->builtInType == XML_SCHEMAS_NPINTEGER) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2950 | if ((sign == 0) && |
| 2951 | ((hi != 0) || (mi != 0) || (lo != 0))) |
| 2952 | goto return1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2953 | } else if (type->builtInType == XML_SCHEMAS_PINTEGER) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2954 | if (sign == 1) |
| 2955 | goto return1; |
| 2956 | if ((hi == 0) && (mi == 0) && (lo == 0)) |
| 2957 | goto return1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2958 | } else if (type->builtInType == XML_SCHEMAS_NINTEGER) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2959 | if (sign == 0) |
| 2960 | goto return1; |
| 2961 | if ((hi == 0) && (mi == 0) && (lo == 0)) |
| 2962 | goto return1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2963 | } else if (type->builtInType == XML_SCHEMAS_NNINTEGER) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2964 | if ((sign == 1) && |
| 2965 | ((hi != 0) || (mi != 0) || (lo != 0))) |
| 2966 | goto return1; |
| 2967 | } |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 2968 | if (val != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 2969 | v = xmlSchemaNewValue(type->builtInType); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2970 | if (v != NULL) { |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 2971 | if (ret == 0) |
| 2972 | ret++; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2973 | v->value.decimal.lo = lo; |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 2974 | v->value.decimal.mi = mi; |
| 2975 | v->value.decimal.hi = hi; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2976 | v->value.decimal.sign = sign; |
| 2977 | v->value.decimal.frac = 0; |
William M. Brack | ec3b4b7 | 2005-03-15 15:50:17 +0000 | [diff] [blame] | 2978 | v->value.decimal.total = ret; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2979 | *val = v; |
| 2980 | } |
| 2981 | } |
| 2982 | goto return0; |
| 2983 | } |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 2984 | case XML_SCHEMAS_LONG: |
| 2985 | case XML_SCHEMAS_BYTE: |
| 2986 | case XML_SCHEMAS_SHORT: |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2987 | case XML_SCHEMAS_INT:{ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 2988 | const xmlChar *cur = value; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2989 | unsigned long lo, mi, hi; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 2990 | int sign = 0; |
| 2991 | |
| 2992 | if (cur == NULL) |
| 2993 | goto return1; |
| 2994 | if (*cur == '-') { |
| 2995 | sign = 1; |
| 2996 | cur++; |
| 2997 | } else if (*cur == '+') |
| 2998 | cur++; |
William M. Brack | ec3b4b7 | 2005-03-15 15:50:17 +0000 | [diff] [blame] | 2999 | ret = xmlSchemaParseUInt(&cur, &lo, &mi, &hi); |
| 3000 | if (ret < 0) |
| 3001 | goto return1; |
| 3002 | if (*cur != 0) |
| 3003 | goto return1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3004 | if (type->builtInType == XML_SCHEMAS_LONG) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3005 | if (hi >= 922) { |
| 3006 | if (hi > 922) |
| 3007 | goto return1; |
| 3008 | if (mi >= 33720368) { |
| 3009 | if (mi > 33720368) |
| 3010 | goto return1; |
| 3011 | if ((sign == 0) && (lo > 54775807)) |
| 3012 | goto return1; |
| 3013 | if ((sign == 1) && (lo > 54775808)) |
| 3014 | goto return1; |
| 3015 | } |
| 3016 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3017 | } else if (type->builtInType == XML_SCHEMAS_INT) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3018 | if (hi != 0) |
| 3019 | goto return1; |
| 3020 | if (mi >= 21) { |
| 3021 | if (mi > 21) |
| 3022 | goto return1; |
| 3023 | if ((sign == 0) && (lo > 47483647)) |
| 3024 | goto return1; |
| 3025 | if ((sign == 1) && (lo > 47483648)) |
| 3026 | goto return1; |
| 3027 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3028 | } else if (type->builtInType == XML_SCHEMAS_SHORT) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3029 | if ((mi != 0) || (hi != 0)) |
| 3030 | goto return1; |
| 3031 | if ((sign == 1) && (lo > 32768)) |
| 3032 | goto return1; |
| 3033 | if ((sign == 0) && (lo > 32767)) |
| 3034 | goto return1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3035 | } else if (type->builtInType == XML_SCHEMAS_BYTE) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3036 | if ((mi != 0) || (hi != 0)) |
| 3037 | goto return1; |
| 3038 | if ((sign == 1) && (lo > 128)) |
| 3039 | goto return1; |
| 3040 | if ((sign == 0) && (lo > 127)) |
| 3041 | goto return1; |
| 3042 | } |
| 3043 | if (val != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3044 | v = xmlSchemaNewValue(type->builtInType); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3045 | if (v != NULL) { |
| 3046 | v->value.decimal.lo = lo; |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 3047 | v->value.decimal.mi = mi; |
| 3048 | v->value.decimal.hi = hi; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3049 | v->value.decimal.sign = sign; |
| 3050 | v->value.decimal.frac = 0; |
William M. Brack | ec3b4b7 | 2005-03-15 15:50:17 +0000 | [diff] [blame] | 3051 | v->value.decimal.total = ret; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3052 | *val = v; |
| 3053 | } |
| 3054 | } |
| 3055 | goto return0; |
| 3056 | } |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 3057 | case XML_SCHEMAS_UINT: |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 3058 | case XML_SCHEMAS_ULONG: |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 3059 | case XML_SCHEMAS_USHORT: |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3060 | case XML_SCHEMAS_UBYTE:{ |
| 3061 | const xmlChar *cur = value; |
| 3062 | unsigned long lo, mi, hi; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3063 | |
| 3064 | if (cur == NULL) |
| 3065 | goto return1; |
William M. Brack | ec3b4b7 | 2005-03-15 15:50:17 +0000 | [diff] [blame] | 3066 | ret = xmlSchemaParseUInt(&cur, &lo, &mi, &hi); |
| 3067 | if (ret < 0) |
| 3068 | goto return1; |
| 3069 | if (*cur != 0) |
| 3070 | goto return1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3071 | if (type->builtInType == XML_SCHEMAS_ULONG) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3072 | if (hi >= 1844) { |
| 3073 | if (hi > 1844) |
| 3074 | goto return1; |
| 3075 | if (mi >= 67440737) { |
| 3076 | if (mi > 67440737) |
| 3077 | goto return1; |
| 3078 | if (lo > 9551615) |
| 3079 | goto return1; |
| 3080 | } |
| 3081 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3082 | } else if (type->builtInType == XML_SCHEMAS_UINT) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3083 | if (hi != 0) |
| 3084 | goto return1; |
| 3085 | if (mi >= 42) { |
| 3086 | if (mi > 42) |
| 3087 | goto return1; |
| 3088 | if (lo > 94967295) |
| 3089 | goto return1; |
| 3090 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3091 | } else if (type->builtInType == XML_SCHEMAS_USHORT) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3092 | if ((mi != 0) || (hi != 0)) |
| 3093 | goto return1; |
| 3094 | if (lo > 65535) |
| 3095 | goto return1; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3096 | } else if (type->builtInType == XML_SCHEMAS_UBYTE) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3097 | if ((mi != 0) || (hi != 0)) |
| 3098 | goto return1; |
| 3099 | if (lo > 255) |
| 3100 | goto return1; |
| 3101 | } |
| 3102 | if (val != NULL) { |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 3103 | v = xmlSchemaNewValue(type->builtInType); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3104 | if (v != NULL) { |
| 3105 | v->value.decimal.lo = lo; |
| 3106 | v->value.decimal.mi = mi; |
| 3107 | v->value.decimal.hi = hi; |
| 3108 | v->value.decimal.sign = 0; |
| 3109 | v->value.decimal.frac = 0; |
William M. Brack | ec3b4b7 | 2005-03-15 15:50:17 +0000 | [diff] [blame] | 3110 | v->value.decimal.total = ret; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3111 | *val = v; |
| 3112 | } |
| 3113 | } |
| 3114 | goto return0; |
| 3115 | } |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 3116 | } |
| 3117 | |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 3118 | done: |
| 3119 | if (norm != NULL) |
| 3120 | xmlFree(norm); |
| 3121 | return (ret); |
| 3122 | return3: |
| 3123 | if (norm != NULL) |
| 3124 | xmlFree(norm); |
| 3125 | return (3); |
| 3126 | return1: |
| 3127 | if (norm != NULL) |
| 3128 | xmlFree(norm); |
| 3129 | return (1); |
| 3130 | return0: |
| 3131 | if (norm != NULL) |
| 3132 | xmlFree(norm); |
| 3133 | return (0); |
| 3134 | error: |
| 3135 | if (norm != NULL) |
| 3136 | xmlFree(norm); |
| 3137 | return (-1); |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | /** |
Daniel Veillard | c3da18a | 2003-03-18 00:31:04 +0000 | [diff] [blame] | 3141 | * xmlSchemaValPredefTypeNode: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3142 | * @type: the predefined type |
| 3143 | * @value: the value to check |
| 3144 | * @val: the return computed value |
Daniel Veillard | c3da18a | 2003-03-18 00:31:04 +0000 | [diff] [blame] | 3145 | * @node: the node containing the value |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3146 | * |
| 3147 | * Check that a value conforms to the lexical space of the predefined type. |
| 3148 | * if true a value is computed and returned in @val. |
| 3149 | * |
| 3150 | * Returns 0 if this validates, a positive error code number otherwise |
| 3151 | * and -1 in case of internal or API error. |
| 3152 | */ |
| 3153 | int |
Daniel Veillard | c3da18a | 2003-03-18 00:31:04 +0000 | [diff] [blame] | 3154 | xmlSchemaValPredefTypeNode(xmlSchemaTypePtr type, const xmlChar *value, |
| 3155 | xmlSchemaValPtr *val, xmlNodePtr node) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3156 | return(xmlSchemaValAtomicType(type, value, val, node, 0, |
| 3157 | XML_SCHEMA_WHITESPACE_UNKNOWN, 1, 1, 0)); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | /** |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3161 | * xmlSchemaValPredefTypeNodeNoNorm: |
| 3162 | * @type: the predefined type |
| 3163 | * @value: the value to check |
| 3164 | * @val: the return computed value |
| 3165 | * @node: the node containing the value |
| 3166 | * |
| 3167 | * Check that a value conforms to the lexical space of the predefined type. |
| 3168 | * if true a value is computed and returned in @val. |
| 3169 | * This one does apply any normalization to the value. |
| 3170 | * |
| 3171 | * Returns 0 if this validates, a positive error code number otherwise |
| 3172 | * and -1 in case of internal or API error. |
| 3173 | */ |
| 3174 | int |
| 3175 | xmlSchemaValPredefTypeNodeNoNorm(xmlSchemaTypePtr type, const xmlChar *value, |
| 3176 | xmlSchemaValPtr *val, xmlNodePtr node) { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3177 | return(xmlSchemaValAtomicType(type, value, val, node, 1, |
| 3178 | XML_SCHEMA_WHITESPACE_UNKNOWN, 1, 0, 1)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | /** |
Daniel Veillard | c3da18a | 2003-03-18 00:31:04 +0000 | [diff] [blame] | 3182 | * xmlSchemaValidatePredefinedType: |
| 3183 | * @type: the predefined type |
| 3184 | * @value: the value to check |
| 3185 | * @val: the return computed value |
| 3186 | * |
| 3187 | * Check that a value conforms to the lexical space of the predefined type. |
| 3188 | * if true a value is computed and returned in @val. |
| 3189 | * |
| 3190 | * Returns 0 if this validates, a positive error code number otherwise |
| 3191 | * and -1 in case of internal or API error. |
| 3192 | */ |
| 3193 | int |
| 3194 | xmlSchemaValidatePredefinedType(xmlSchemaTypePtr type, const xmlChar *value, |
| 3195 | xmlSchemaValPtr *val) { |
| 3196 | return(xmlSchemaValPredefTypeNode(type, value, val, NULL)); |
| 3197 | } |
| 3198 | |
| 3199 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3200 | * xmlSchemaCompareDecimals: |
| 3201 | * @x: a first decimal value |
| 3202 | * @y: a second decimal value |
| 3203 | * |
| 3204 | * Compare 2 decimals |
| 3205 | * |
| 3206 | * Returns -1 if x < y, 0 if x == y, 1 if x > y and -2 in case of error |
| 3207 | */ |
| 3208 | static int |
| 3209 | xmlSchemaCompareDecimals(xmlSchemaValPtr x, xmlSchemaValPtr y) |
| 3210 | { |
| 3211 | xmlSchemaValPtr swp; |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 3212 | int order = 1, integx, integy, dlen; |
| 3213 | unsigned long hi, mi, lo; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3214 | |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 3215 | /* |
| 3216 | * First test: If x is -ve and not zero |
| 3217 | */ |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 3218 | if ((x->value.decimal.sign) && |
| 3219 | ((x->value.decimal.lo != 0) || |
| 3220 | (x->value.decimal.mi != 0) || |
| 3221 | (x->value.decimal.hi != 0))) { |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 3222 | /* |
| 3223 | * Then if y is -ve and not zero reverse the compare |
| 3224 | */ |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 3225 | if ((y->value.decimal.sign) && |
| 3226 | ((y->value.decimal.lo != 0) || |
| 3227 | (y->value.decimal.mi != 0) || |
| 3228 | (y->value.decimal.hi != 0))) |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 3229 | order = -1; |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 3230 | /* |
| 3231 | * Otherwise (y >= 0) we have the answer |
| 3232 | */ |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 3233 | else |
| 3234 | return (-1); |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 3235 | /* |
| 3236 | * If x is not -ve and y is -ve we have the answer |
| 3237 | */ |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 3238 | } else if ((y->value.decimal.sign) && |
| 3239 | ((y->value.decimal.lo != 0) || |
| 3240 | (y->value.decimal.mi != 0) || |
| 3241 | (y->value.decimal.hi != 0))) { |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3242 | return (1); |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 3243 | } |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 3244 | /* |
| 3245 | * If it's not simply determined by a difference in sign, |
| 3246 | * then we need to compare the actual values of the two nums. |
| 3247 | * To do this, we start by looking at the integral parts. |
| 3248 | * If the number of integral digits differ, then we have our |
| 3249 | * answer. |
| 3250 | */ |
| 3251 | integx = x->value.decimal.total - x->value.decimal.frac; |
| 3252 | integy = y->value.decimal.total - y->value.decimal.frac; |
| 3253 | if (integx > integy) |
| 3254 | return order; |
| 3255 | else if (integy > integx) |
| 3256 | return -order; |
| 3257 | /* |
| 3258 | * If the number of integral digits is the same for both numbers, |
| 3259 | * then things get a little more complicated. We need to "normalize" |
| 3260 | * the numbers in order to properly compare them. To do this, we |
| 3261 | * look at the total length of each number (length => number of |
| 3262 | * significant digits), and divide the "shorter" by 10 (decreasing |
| 3263 | * the length) until they are of equal length. |
| 3264 | */ |
| 3265 | dlen = x->value.decimal.total - y->value.decimal.total; |
| 3266 | if (dlen < 0) { /* y has more digits than x */ |
| 3267 | swp = x; |
| 3268 | hi = y->value.decimal.hi; |
| 3269 | mi = y->value.decimal.mi; |
| 3270 | lo = y->value.decimal.lo; |
| 3271 | dlen = -dlen; |
| 3272 | order = -order; |
| 3273 | } else { /* x has more digits than y */ |
| 3274 | swp = y; |
| 3275 | hi = x->value.decimal.hi; |
| 3276 | mi = x->value.decimal.mi; |
| 3277 | lo = x->value.decimal.lo; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3278 | } |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 3279 | while (dlen > 8) { /* in effect, right shift by 10**8 */ |
| 3280 | lo = mi; |
| 3281 | mi = hi; |
| 3282 | hi = 0; |
| 3283 | dlen -= 8; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3284 | } |
William M. Brack | 273670f | 2005-03-11 15:55:14 +0000 | [diff] [blame] | 3285 | while (dlen > 0) { |
| 3286 | unsigned long rem1, rem2; |
| 3287 | rem1 = (hi % 10) * 100000000L; |
| 3288 | hi = hi / 10; |
| 3289 | rem2 = (mi % 10) * 100000000L; |
| 3290 | mi = (mi + rem1) / 10; |
| 3291 | lo = (lo + rem2) / 10; |
| 3292 | dlen--; |
| 3293 | } |
| 3294 | if (hi > swp->value.decimal.hi) { |
| 3295 | return order; |
| 3296 | } else if (hi == swp->value.decimal.hi) { |
| 3297 | if (mi > swp->value.decimal.mi) { |
| 3298 | return order; |
| 3299 | } else if (mi == swp->value.decimal.mi) { |
| 3300 | if (lo > swp->value.decimal.lo) { |
| 3301 | return order; |
| 3302 | } else if (lo == swp->value.decimal.lo) { |
| 3303 | if (x->value.decimal.total == y->value.decimal.total) { |
| 3304 | return 0; |
| 3305 | } else { |
| 3306 | return order; |
| 3307 | } |
| 3308 | } |
| 3309 | } |
| 3310 | } |
| 3311 | return -order; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
| 3314 | /** |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 3315 | * xmlSchemaCompareDurations: |
| 3316 | * @x: a first duration value |
| 3317 | * @y: a second duration value |
| 3318 | * |
| 3319 | * Compare 2 durations |
| 3320 | * |
| 3321 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in |
| 3322 | * case of error |
| 3323 | */ |
| 3324 | static int |
| 3325 | xmlSchemaCompareDurations(xmlSchemaValPtr x, xmlSchemaValPtr y) |
| 3326 | { |
| 3327 | long carry, mon, day; |
| 3328 | double sec; |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 3329 | int invert = 1; |
| 3330 | long xmon, xday, myear, minday, maxday; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 3331 | static const long dayRange [2][12] = { |
| 3332 | { 0, 28, 59, 89, 120, 150, 181, 212, 242, 273, 303, 334, }, |
| 3333 | { 0, 31, 62, 92, 123, 153, 184, 215, 245, 276, 306, 337} }; |
| 3334 | |
| 3335 | if ((x == NULL) || (y == NULL)) |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3336 | return -2; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 3337 | |
| 3338 | /* months */ |
| 3339 | mon = x->value.dur.mon - y->value.dur.mon; |
| 3340 | |
| 3341 | /* seconds */ |
| 3342 | sec = x->value.dur.sec - y->value.dur.sec; |
| 3343 | carry = (long)sec / SECS_PER_DAY; |
| 3344 | sec -= (double)(carry * SECS_PER_DAY); |
| 3345 | |
| 3346 | /* days */ |
| 3347 | day = x->value.dur.day - y->value.dur.day + carry; |
| 3348 | |
| 3349 | /* easy test */ |
| 3350 | if (mon == 0) { |
| 3351 | if (day == 0) |
| 3352 | if (sec == 0.0) |
| 3353 | return 0; |
| 3354 | else if (sec < 0.0) |
| 3355 | return -1; |
| 3356 | else |
| 3357 | return 1; |
| 3358 | else if (day < 0) |
| 3359 | return -1; |
| 3360 | else |
| 3361 | return 1; |
| 3362 | } |
| 3363 | |
| 3364 | if (mon > 0) { |
| 3365 | if ((day >= 0) && (sec >= 0.0)) |
| 3366 | return 1; |
| 3367 | else { |
| 3368 | xmon = mon; |
| 3369 | xday = -day; |
| 3370 | } |
| 3371 | } else if ((day <= 0) && (sec <= 0.0)) { |
| 3372 | return -1; |
| 3373 | } else { |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 3374 | invert = -1; |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 3375 | xmon = -mon; |
| 3376 | xday = day; |
| 3377 | } |
| 3378 | |
| 3379 | myear = xmon / 12; |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 3380 | if (myear == 0) { |
| 3381 | minday = 0; |
| 3382 | maxday = 0; |
| 3383 | } else { |
| 3384 | maxday = 366 * ((myear + 3) / 4) + |
| 3385 | 365 * ((myear - 1) % 4); |
| 3386 | minday = maxday - 1; |
| 3387 | } |
| 3388 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 3389 | xmon = xmon % 12; |
| 3390 | minday += dayRange[0][xmon]; |
| 3391 | maxday += dayRange[1][xmon]; |
| 3392 | |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 3393 | if ((maxday == minday) && (maxday == xday)) |
| 3394 | return(0); /* can this really happen ? */ |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 3395 | if (maxday < xday) |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 3396 | return(-invert); |
| 3397 | if (minday > xday) |
| 3398 | return(invert); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 3399 | |
| 3400 | /* indeterminate */ |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3401 | return 2; |
| 3402 | } |
| 3403 | |
| 3404 | /* |
| 3405 | * macros for adding date/times and durations |
| 3406 | */ |
| 3407 | #define FQUOTIENT(a,b) (floor(((double)a/(double)b))) |
| 3408 | #define MODULO(a,b) (a - FQUOTIENT(a,b) * b) |
| 3409 | #define FQUOTIENT_RANGE(a,low,high) (FQUOTIENT((a-low),(high-low))) |
| 3410 | #define MODULO_RANGE(a,low,high) ((MODULO((a-low),(high-low)))+low) |
| 3411 | |
| 3412 | /** |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3413 | * xmlSchemaDupVal: |
| 3414 | * @v: the #xmlSchemaValPtr value to duplicate |
| 3415 | * |
| 3416 | * Makes a copy of @v. The calling program is responsible for freeing |
| 3417 | * the returned value. |
| 3418 | * |
| 3419 | * returns a pointer to a duplicated #xmlSchemaValPtr or NULL if error. |
| 3420 | */ |
| 3421 | static xmlSchemaValPtr |
| 3422 | xmlSchemaDupVal (xmlSchemaValPtr v) |
| 3423 | { |
| 3424 | xmlSchemaValPtr ret = xmlSchemaNewValue(v->type); |
| 3425 | if (ret == NULL) |
| 3426 | return NULL; |
| 3427 | |
| 3428 | memcpy(ret, v, sizeof(xmlSchemaVal)); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3429 | ret->next = NULL; |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3430 | return ret; |
| 3431 | } |
| 3432 | |
| 3433 | /** |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 3434 | * xmlSchemaCopyValue: |
| 3435 | * @val: the precomputed value to be copied |
| 3436 | * |
| 3437 | * Copies the precomputed value. This duplicates any string within. |
| 3438 | * |
| 3439 | * Returns the copy or NULL if a copy for a data-type is not implemented. |
| 3440 | */ |
| 3441 | xmlSchemaValPtr |
| 3442 | xmlSchemaCopyValue(xmlSchemaValPtr val) |
| 3443 | { |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3444 | xmlSchemaValPtr ret = NULL, prev = NULL, cur; |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 3445 | |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 3446 | /* |
| 3447 | * Copy the string values. |
| 3448 | */ |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3449 | while (val != NULL) { |
| 3450 | switch (val->type) { |
| 3451 | case XML_SCHEMAS_ANYTYPE: |
| 3452 | case XML_SCHEMAS_IDREFS: |
| 3453 | case XML_SCHEMAS_ENTITIES: |
| 3454 | case XML_SCHEMAS_NMTOKENS: |
| 3455 | xmlSchemaFreeValue(ret); |
| 3456 | return (NULL); |
| 3457 | case XML_SCHEMAS_ANYSIMPLETYPE: |
| 3458 | case XML_SCHEMAS_STRING: |
| 3459 | case XML_SCHEMAS_NORMSTRING: |
| 3460 | case XML_SCHEMAS_TOKEN: |
| 3461 | case XML_SCHEMAS_LANGUAGE: |
| 3462 | case XML_SCHEMAS_NAME: |
| 3463 | case XML_SCHEMAS_NCNAME: |
| 3464 | case XML_SCHEMAS_ID: |
| 3465 | case XML_SCHEMAS_IDREF: |
| 3466 | case XML_SCHEMAS_ENTITY: |
| 3467 | case XML_SCHEMAS_NMTOKEN: |
| 3468 | case XML_SCHEMAS_ANYURI: |
| 3469 | cur = xmlSchemaDupVal(val); |
| 3470 | if (val->value.str != NULL) |
| 3471 | cur->value.str = xmlStrdup(BAD_CAST val->value.str); |
| 3472 | break; |
| 3473 | case XML_SCHEMAS_QNAME: |
| 3474 | case XML_SCHEMAS_NOTATION: |
| 3475 | cur = xmlSchemaDupVal(val); |
| 3476 | if (val->value.qname.name != NULL) |
| 3477 | cur->value.qname.name = |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 3478 | xmlStrdup(BAD_CAST val->value.qname.name); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3479 | if (val->value.qname.uri != NULL) |
| 3480 | cur->value.qname.uri = |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 3481 | xmlStrdup(BAD_CAST val->value.qname.uri); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3482 | break; |
| 3483 | case XML_SCHEMAS_HEXBINARY: |
| 3484 | cur = xmlSchemaDupVal(val); |
| 3485 | if (val->value.hex.str != NULL) |
| 3486 | cur->value.hex.str = xmlStrdup(BAD_CAST val->value.hex.str); |
| 3487 | break; |
| 3488 | case XML_SCHEMAS_BASE64BINARY: |
| 3489 | cur = xmlSchemaDupVal(val); |
| 3490 | if (val->value.base64.str != NULL) |
| 3491 | cur->value.base64.str = |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 3492 | xmlStrdup(BAD_CAST val->value.base64.str); |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3493 | break; |
| 3494 | default: |
| 3495 | cur = xmlSchemaDupVal(val); |
| 3496 | break; |
| 3497 | } |
| 3498 | if (ret == NULL) |
| 3499 | ret = cur; |
| 3500 | else |
| 3501 | prev->next = cur; |
| 3502 | prev = cur; |
| 3503 | val = val->next; |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 3504 | } |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 3505 | return (ret); |
Kasimier T. Buchcik | 285ebab | 2005-03-04 18:04:59 +0000 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | /** |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3509 | * _xmlSchemaDateAdd: |
| 3510 | * @dt: an #xmlSchemaValPtr |
| 3511 | * @dur: an #xmlSchemaValPtr of type #XS_DURATION |
| 3512 | * |
| 3513 | * Compute a new date/time from @dt and @dur. This function assumes @dt |
| 3514 | * is either #XML_SCHEMAS_DATETIME, #XML_SCHEMAS_DATE, #XML_SCHEMAS_GYEARMONTH, |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3515 | * or #XML_SCHEMAS_GYEAR. The returned #xmlSchemaVal is the same type as |
| 3516 | * @dt. The calling program is responsible for freeing the returned value. |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3517 | * |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3518 | * Returns a pointer to a new #xmlSchemaVal or NULL if error. |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3519 | */ |
| 3520 | static xmlSchemaValPtr |
| 3521 | _xmlSchemaDateAdd (xmlSchemaValPtr dt, xmlSchemaValPtr dur) |
| 3522 | { |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3523 | xmlSchemaValPtr ret, tmp; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3524 | long carry, tempdays, temp; |
| 3525 | xmlSchemaValDatePtr r, d; |
| 3526 | xmlSchemaValDurationPtr u; |
| 3527 | |
| 3528 | if ((dt == NULL) || (dur == NULL)) |
| 3529 | return NULL; |
| 3530 | |
| 3531 | ret = xmlSchemaNewValue(dt->type); |
| 3532 | if (ret == NULL) |
| 3533 | return NULL; |
| 3534 | |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3535 | /* make a copy so we don't alter the original value */ |
| 3536 | tmp = xmlSchemaDupVal(dt); |
| 3537 | if (tmp == NULL) { |
| 3538 | xmlSchemaFreeValue(ret); |
| 3539 | return NULL; |
| 3540 | } |
| 3541 | |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3542 | r = &(ret->value.date); |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3543 | d = &(tmp->value.date); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3544 | u = &(dur->value.dur); |
| 3545 | |
| 3546 | /* normalization */ |
| 3547 | if (d->mon == 0) |
| 3548 | d->mon = 1; |
| 3549 | |
| 3550 | /* normalize for time zone offset */ |
| 3551 | u->sec -= (d->tzo * 60); |
| 3552 | d->tzo = 0; |
| 3553 | |
| 3554 | /* normalization */ |
| 3555 | if (d->day == 0) |
| 3556 | d->day = 1; |
| 3557 | |
| 3558 | /* month */ |
| 3559 | carry = d->mon + u->mon; |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 3560 | r->mon = (unsigned int) MODULO_RANGE(carry, 1, 13); |
| 3561 | carry = (long) FQUOTIENT_RANGE(carry, 1, 13); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3562 | |
| 3563 | /* year (may be modified later) */ |
| 3564 | r->year = d->year + carry; |
| 3565 | if (r->year == 0) { |
| 3566 | if (d->year > 0) |
| 3567 | r->year--; |
| 3568 | else |
| 3569 | r->year++; |
| 3570 | } |
| 3571 | |
| 3572 | /* time zone */ |
| 3573 | r->tzo = d->tzo; |
| 3574 | r->tz_flag = d->tz_flag; |
| 3575 | |
| 3576 | /* seconds */ |
| 3577 | r->sec = d->sec + u->sec; |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 3578 | carry = (long) FQUOTIENT((long)r->sec, 60); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3579 | if (r->sec != 0.0) { |
| 3580 | r->sec = MODULO(r->sec, 60.0); |
| 3581 | } |
| 3582 | |
| 3583 | /* minute */ |
| 3584 | carry += d->min; |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 3585 | r->min = (unsigned int) MODULO(carry, 60); |
| 3586 | carry = (long) FQUOTIENT(carry, 60); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3587 | |
| 3588 | /* hours */ |
| 3589 | carry += d->hour; |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 3590 | r->hour = (unsigned int) MODULO(carry, 24); |
| 3591 | carry = (long)FQUOTIENT(carry, 24); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3592 | |
| 3593 | /* |
| 3594 | * days |
| 3595 | * Note we use tempdays because the temporary values may need more |
| 3596 | * than 5 bits |
| 3597 | */ |
| 3598 | if ((VALID_YEAR(r->year)) && (VALID_MONTH(r->mon)) && |
| 3599 | (d->day > MAX_DAYINMONTH(r->year, r->mon))) |
| 3600 | tempdays = MAX_DAYINMONTH(r->year, r->mon); |
| 3601 | else if (d->day < 1) |
| 3602 | tempdays = 1; |
| 3603 | else |
| 3604 | tempdays = d->day; |
| 3605 | |
| 3606 | tempdays += u->day + carry; |
| 3607 | |
| 3608 | while (1) { |
| 3609 | if (tempdays < 1) { |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 3610 | long tmon = (long) MODULO_RANGE(r->mon-1, 1, 13); |
| 3611 | long tyr = r->year + (long)FQUOTIENT_RANGE(r->mon-1, 1, 13); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3612 | if (tyr == 0) |
| 3613 | tyr--; |
| 3614 | tempdays += MAX_DAYINMONTH(tyr, tmon); |
| 3615 | carry = -1; |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 3616 | } else if (tempdays > (long) MAX_DAYINMONTH(r->year, r->mon)) { |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3617 | tempdays = tempdays - MAX_DAYINMONTH(r->year, r->mon); |
| 3618 | carry = 1; |
| 3619 | } else |
| 3620 | break; |
| 3621 | |
| 3622 | temp = r->mon + carry; |
Daniel Veillard | ebe25d4 | 2004-03-25 09:35:49 +0000 | [diff] [blame] | 3623 | r->mon = (unsigned int) MODULO_RANGE(temp, 1, 13); |
| 3624 | r->year = r->year + (unsigned int) FQUOTIENT_RANGE(temp, 1, 13); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3625 | if (r->year == 0) { |
| 3626 | if (temp < 1) |
| 3627 | r->year--; |
| 3628 | else |
| 3629 | r->year++; |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | r->day = tempdays; |
| 3634 | |
| 3635 | /* |
| 3636 | * adjust the date/time type to the date values |
| 3637 | */ |
| 3638 | if (ret->type != XML_SCHEMAS_DATETIME) { |
| 3639 | if ((r->hour) || (r->min) || (r->sec)) |
| 3640 | ret->type = XML_SCHEMAS_DATETIME; |
| 3641 | else if (ret->type != XML_SCHEMAS_DATE) { |
| 3642 | if ((r->mon != 1) && (r->day != 1)) |
| 3643 | ret->type = XML_SCHEMAS_DATE; |
| 3644 | else if ((ret->type != XML_SCHEMAS_GYEARMONTH) && (r->mon != 1)) |
| 3645 | ret->type = XML_SCHEMAS_GYEARMONTH; |
| 3646 | } |
| 3647 | } |
| 3648 | |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3649 | xmlSchemaFreeValue(tmp); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3650 | |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3651 | return ret; |
| 3652 | } |
| 3653 | |
| 3654 | /** |
| 3655 | * xmlSchemaDateNormalize: |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3656 | * @dt: an #xmlSchemaValPtr of a date/time type value. |
| 3657 | * @offset: number of seconds to adjust @dt by. |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3658 | * |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3659 | * Normalize @dt to GMT time. The @offset parameter is subtracted from |
| 3660 | * the return value is a time-zone offset is present on @dt. |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3661 | * |
Daniel Veillard | 669adfc | 2004-05-29 20:12:46 +0000 | [diff] [blame] | 3662 | * Returns a normalized copy of @dt or NULL if error. |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3663 | */ |
| 3664 | static xmlSchemaValPtr |
| 3665 | xmlSchemaDateNormalize (xmlSchemaValPtr dt, double offset) |
| 3666 | { |
| 3667 | xmlSchemaValPtr dur, ret; |
| 3668 | |
| 3669 | if (dt == NULL) |
| 3670 | return NULL; |
| 3671 | |
| 3672 | if (((dt->type != XML_SCHEMAS_TIME) && |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 3673 | (dt->type != XML_SCHEMAS_DATETIME) && |
| 3674 | (dt->type != XML_SCHEMAS_DATE)) || (dt->value.date.tzo == 0)) |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3675 | return xmlSchemaDupVal(dt); |
| 3676 | |
| 3677 | dur = xmlSchemaNewValue(XML_SCHEMAS_DURATION); |
| 3678 | if (dur == NULL) |
| 3679 | return NULL; |
| 3680 | |
| 3681 | dur->value.date.sec -= offset; |
| 3682 | |
| 3683 | ret = _xmlSchemaDateAdd(dt, dur); |
| 3684 | if (ret == NULL) |
| 3685 | return NULL; |
| 3686 | |
| 3687 | xmlSchemaFreeValue(dur); |
| 3688 | |
| 3689 | /* ret->value.date.tzo = 0; */ |
| 3690 | return ret; |
| 3691 | } |
| 3692 | |
| 3693 | /** |
| 3694 | * _xmlSchemaDateCastYMToDays: |
| 3695 | * @dt: an #xmlSchemaValPtr |
| 3696 | * |
| 3697 | * Convert mon and year of @dt to total number of days. Take the |
| 3698 | * number of years since (or before) 1 AD and add the number of leap |
| 3699 | * years. This is a function because negative |
| 3700 | * years must be handled a little differently and there is no zero year. |
| 3701 | * |
| 3702 | * Returns number of days. |
| 3703 | */ |
| 3704 | static long |
| 3705 | _xmlSchemaDateCastYMToDays (const xmlSchemaValPtr dt) |
| 3706 | { |
| 3707 | long ret; |
Daniel Veillard | 49e8963 | 2004-09-23 16:24:36 +0000 | [diff] [blame] | 3708 | int mon; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3709 | |
Daniel Veillard | 49e8963 | 2004-09-23 16:24:36 +0000 | [diff] [blame] | 3710 | mon = dt->value.date.mon; |
| 3711 | if (mon <= 0) mon = 1; /* normalization */ |
| 3712 | |
| 3713 | if (dt->value.date.year <= 0) |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3714 | ret = (dt->value.date.year * 365) + |
| 3715 | (((dt->value.date.year+1)/4)-((dt->value.date.year+1)/100)+ |
| 3716 | ((dt->value.date.year+1)/400)) + |
Daniel Veillard | 49e8963 | 2004-09-23 16:24:36 +0000 | [diff] [blame] | 3717 | DAY_IN_YEAR(0, mon, dt->value.date.year); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3718 | else |
| 3719 | ret = ((dt->value.date.year-1) * 365) + |
| 3720 | (((dt->value.date.year-1)/4)-((dt->value.date.year-1)/100)+ |
| 3721 | ((dt->value.date.year-1)/400)) + |
Daniel Veillard | 49e8963 | 2004-09-23 16:24:36 +0000 | [diff] [blame] | 3722 | DAY_IN_YEAR(0, mon, dt->value.date.year); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3723 | |
| 3724 | return ret; |
| 3725 | } |
| 3726 | |
| 3727 | /** |
| 3728 | * TIME_TO_NUMBER: |
| 3729 | * @dt: an #xmlSchemaValPtr |
| 3730 | * |
| 3731 | * Calculates the number of seconds in the time portion of @dt. |
| 3732 | * |
| 3733 | * Returns seconds. |
| 3734 | */ |
| 3735 | #define TIME_TO_NUMBER(dt) \ |
| 3736 | ((double)((dt->value.date.hour * SECS_PER_HOUR) + \ |
Daniel Veillard | b3721c2 | 2003-03-31 11:22:25 +0000 | [diff] [blame] | 3737 | (dt->value.date.min * SECS_PER_MIN) + \ |
| 3738 | (dt->value.date.tzo * SECS_PER_MIN)) + \ |
| 3739 | dt->value.date.sec) |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3740 | |
| 3741 | /** |
| 3742 | * xmlSchemaCompareDates: |
| 3743 | * @x: a first date/time value |
| 3744 | * @y: a second date/time value |
| 3745 | * |
| 3746 | * Compare 2 date/times |
| 3747 | * |
| 3748 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in |
| 3749 | * case of error |
| 3750 | */ |
| 3751 | static int |
| 3752 | xmlSchemaCompareDates (xmlSchemaValPtr x, xmlSchemaValPtr y) |
| 3753 | { |
| 3754 | unsigned char xmask, ymask, xor_mask, and_mask; |
| 3755 | xmlSchemaValPtr p1, p2, q1, q2; |
| 3756 | long p1d, p2d, q1d, q2d; |
| 3757 | |
| 3758 | if ((x == NULL) || (y == NULL)) |
| 3759 | return -2; |
| 3760 | |
| 3761 | if (x->value.date.tz_flag) { |
| 3762 | |
| 3763 | if (!y->value.date.tz_flag) { |
| 3764 | p1 = xmlSchemaDateNormalize(x, 0); |
| 3765 | p1d = _xmlSchemaDateCastYMToDays(p1) + p1->value.date.day; |
| 3766 | /* normalize y + 14:00 */ |
| 3767 | q1 = xmlSchemaDateNormalize(y, (14 * SECS_PER_HOUR)); |
| 3768 | |
| 3769 | q1d = _xmlSchemaDateCastYMToDays(q1) + q1->value.date.day; |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3770 | if (p1d < q1d) { |
| 3771 | xmlSchemaFreeValue(p1); |
| 3772 | xmlSchemaFreeValue(q1); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3773 | return -1; |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3774 | } else if (p1d == q1d) { |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3775 | double sec; |
| 3776 | |
| 3777 | sec = TIME_TO_NUMBER(p1) - TIME_TO_NUMBER(q1); |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3778 | if (sec < 0.0) { |
| 3779 | xmlSchemaFreeValue(p1); |
| 3780 | xmlSchemaFreeValue(q1); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3781 | return -1; |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3782 | } else { |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3783 | int ret = 0; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3784 | /* normalize y - 14:00 */ |
| 3785 | q2 = xmlSchemaDateNormalize(y, -(14 * SECS_PER_HOUR)); |
| 3786 | q2d = _xmlSchemaDateCastYMToDays(q2) + q2->value.date.day; |
| 3787 | if (p1d > q2d) |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3788 | ret = 1; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3789 | else if (p1d == q2d) { |
| 3790 | sec = TIME_TO_NUMBER(p1) - TIME_TO_NUMBER(q2); |
| 3791 | if (sec > 0.0) |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3792 | ret = 1; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3793 | else |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3794 | ret = 2; /* indeterminate */ |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3795 | } |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3796 | xmlSchemaFreeValue(p1); |
| 3797 | xmlSchemaFreeValue(q1); |
| 3798 | xmlSchemaFreeValue(q2); |
| 3799 | if (ret != 0) |
| 3800 | return(ret); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3801 | } |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3802 | } else { |
| 3803 | xmlSchemaFreeValue(p1); |
| 3804 | xmlSchemaFreeValue(q1); |
| 3805 | } |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3806 | } |
| 3807 | } else if (y->value.date.tz_flag) { |
| 3808 | q1 = xmlSchemaDateNormalize(y, 0); |
| 3809 | q1d = _xmlSchemaDateCastYMToDays(q1) + q1->value.date.day; |
| 3810 | |
| 3811 | /* normalize x - 14:00 */ |
| 3812 | p1 = xmlSchemaDateNormalize(x, -(14 * SECS_PER_HOUR)); |
| 3813 | p1d = _xmlSchemaDateCastYMToDays(p1) + p1->value.date.day; |
| 3814 | |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3815 | if (p1d < q1d) { |
| 3816 | xmlSchemaFreeValue(p1); |
| 3817 | xmlSchemaFreeValue(q1); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3818 | return -1; |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3819 | } else if (p1d == q1d) { |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3820 | double sec; |
| 3821 | |
| 3822 | sec = TIME_TO_NUMBER(p1) - TIME_TO_NUMBER(q1); |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3823 | if (sec < 0.0) { |
| 3824 | xmlSchemaFreeValue(p1); |
| 3825 | xmlSchemaFreeValue(q1); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3826 | return -1; |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3827 | } else { |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3828 | int ret = 0; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3829 | /* normalize x + 14:00 */ |
| 3830 | p2 = xmlSchemaDateNormalize(x, (14 * SECS_PER_HOUR)); |
| 3831 | p2d = _xmlSchemaDateCastYMToDays(p2) + p2->value.date.day; |
| 3832 | |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 3833 | if (p2d > q1d) { |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3834 | ret = 1; |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 3835 | } else if (p2d == q1d) { |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3836 | sec = TIME_TO_NUMBER(p2) - TIME_TO_NUMBER(q1); |
| 3837 | if (sec > 0.0) |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3838 | ret = 1; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3839 | else |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3840 | ret = 2; /* indeterminate */ |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3841 | } |
Daniel Veillard | 6560a42 | 2003-03-27 21:25:38 +0000 | [diff] [blame] | 3842 | xmlSchemaFreeValue(p1); |
| 3843 | xmlSchemaFreeValue(q1); |
| 3844 | xmlSchemaFreeValue(p2); |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3845 | if (ret != 0) |
| 3846 | return(ret); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3847 | } |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3848 | } else { |
| 3849 | xmlSchemaFreeValue(p1); |
| 3850 | xmlSchemaFreeValue(q1); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3851 | } |
| 3852 | } |
| 3853 | |
| 3854 | /* |
| 3855 | * if the same type then calculate the difference |
| 3856 | */ |
| 3857 | if (x->type == y->type) { |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3858 | int ret = 0; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3859 | q1 = xmlSchemaDateNormalize(y, 0); |
| 3860 | q1d = _xmlSchemaDateCastYMToDays(q1) + q1->value.date.day; |
| 3861 | |
| 3862 | p1 = xmlSchemaDateNormalize(x, 0); |
| 3863 | p1d = _xmlSchemaDateCastYMToDays(p1) + p1->value.date.day; |
| 3864 | |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3865 | if (p1d < q1d) { |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3866 | ret = -1; |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3867 | } else if (p1d > q1d) { |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3868 | ret = 1; |
Daniel Veillard | fdc9156 | 2002-07-01 21:52:03 +0000 | [diff] [blame] | 3869 | } else { |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3870 | double sec; |
| 3871 | |
| 3872 | sec = TIME_TO_NUMBER(p1) - TIME_TO_NUMBER(q1); |
| 3873 | if (sec < 0.0) |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3874 | ret = -1; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3875 | else if (sec > 0.0) |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3876 | ret = 1; |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3877 | |
| 3878 | } |
Daniel Veillard | 4aede2e | 2003-10-17 12:43:59 +0000 | [diff] [blame] | 3879 | xmlSchemaFreeValue(p1); |
| 3880 | xmlSchemaFreeValue(q1); |
| 3881 | return(ret); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | switch (x->type) { |
| 3885 | case XML_SCHEMAS_DATETIME: |
| 3886 | xmask = 0xf; |
| 3887 | break; |
| 3888 | case XML_SCHEMAS_DATE: |
| 3889 | xmask = 0x7; |
| 3890 | break; |
| 3891 | case XML_SCHEMAS_GYEAR: |
| 3892 | xmask = 0x1; |
| 3893 | break; |
| 3894 | case XML_SCHEMAS_GMONTH: |
| 3895 | xmask = 0x2; |
| 3896 | break; |
| 3897 | case XML_SCHEMAS_GDAY: |
| 3898 | xmask = 0x3; |
| 3899 | break; |
| 3900 | case XML_SCHEMAS_GYEARMONTH: |
| 3901 | xmask = 0x3; |
| 3902 | break; |
| 3903 | case XML_SCHEMAS_GMONTHDAY: |
| 3904 | xmask = 0x6; |
| 3905 | break; |
| 3906 | case XML_SCHEMAS_TIME: |
| 3907 | xmask = 0x8; |
| 3908 | break; |
| 3909 | default: |
| 3910 | xmask = 0; |
| 3911 | break; |
| 3912 | } |
| 3913 | |
| 3914 | switch (y->type) { |
| 3915 | case XML_SCHEMAS_DATETIME: |
| 3916 | ymask = 0xf; |
| 3917 | break; |
| 3918 | case XML_SCHEMAS_DATE: |
| 3919 | ymask = 0x7; |
| 3920 | break; |
| 3921 | case XML_SCHEMAS_GYEAR: |
| 3922 | ymask = 0x1; |
| 3923 | break; |
| 3924 | case XML_SCHEMAS_GMONTH: |
| 3925 | ymask = 0x2; |
| 3926 | break; |
| 3927 | case XML_SCHEMAS_GDAY: |
| 3928 | ymask = 0x3; |
| 3929 | break; |
| 3930 | case XML_SCHEMAS_GYEARMONTH: |
| 3931 | ymask = 0x3; |
| 3932 | break; |
| 3933 | case XML_SCHEMAS_GMONTHDAY: |
| 3934 | ymask = 0x6; |
| 3935 | break; |
| 3936 | case XML_SCHEMAS_TIME: |
| 3937 | ymask = 0x8; |
| 3938 | break; |
| 3939 | default: |
| 3940 | ymask = 0; |
| 3941 | break; |
| 3942 | } |
| 3943 | |
| 3944 | xor_mask = xmask ^ ymask; /* mark type differences */ |
| 3945 | and_mask = xmask & ymask; /* mark field specification */ |
| 3946 | |
| 3947 | /* year */ |
| 3948 | if (xor_mask & 1) |
| 3949 | return 2; /* indeterminate */ |
| 3950 | else if (and_mask & 1) { |
| 3951 | if (x->value.date.year < y->value.date.year) |
| 3952 | return -1; |
| 3953 | else if (x->value.date.year > y->value.date.year) |
| 3954 | return 1; |
| 3955 | } |
| 3956 | |
| 3957 | /* month */ |
| 3958 | if (xor_mask & 2) |
| 3959 | return 2; /* indeterminate */ |
| 3960 | else if (and_mask & 2) { |
| 3961 | if (x->value.date.mon < y->value.date.mon) |
| 3962 | return -1; |
| 3963 | else if (x->value.date.mon > y->value.date.mon) |
| 3964 | return 1; |
| 3965 | } |
| 3966 | |
| 3967 | /* day */ |
| 3968 | if (xor_mask & 4) |
| 3969 | return 2; /* indeterminate */ |
| 3970 | else if (and_mask & 4) { |
| 3971 | if (x->value.date.day < y->value.date.day) |
| 3972 | return -1; |
| 3973 | else if (x->value.date.day > y->value.date.day) |
| 3974 | return 1; |
| 3975 | } |
| 3976 | |
| 3977 | /* time */ |
| 3978 | if (xor_mask & 8) |
| 3979 | return 2; /* indeterminate */ |
| 3980 | else if (and_mask & 8) { |
| 3981 | if (x->value.date.hour < y->value.date.hour) |
| 3982 | return -1; |
| 3983 | else if (x->value.date.hour > y->value.date.hour) |
| 3984 | return 1; |
| 3985 | else if (x->value.date.min < y->value.date.min) |
| 3986 | return -1; |
| 3987 | else if (x->value.date.min > y->value.date.min) |
| 3988 | return 1; |
| 3989 | else if (x->value.date.sec < y->value.date.sec) |
| 3990 | return -1; |
| 3991 | else if (x->value.date.sec > y->value.date.sec) |
| 3992 | return 1; |
| 3993 | } |
| 3994 | |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 3995 | return 0; |
| 3996 | } |
| 3997 | |
| 3998 | /** |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 3999 | * xmlSchemaComparePreserveReplaceStrings: |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4000 | * @x: a first string value |
| 4001 | * @y: a second string value |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4002 | * @invert: inverts the result if x < y or x > y. |
| 4003 | * |
| 4004 | * Compare 2 string for their normalized values. |
| 4005 | * @x is a string with whitespace of "preserve", @y is |
| 4006 | * a string with a whitespace of "replace". I.e. @x could |
| 4007 | * be an "xsd:string" and @y an "xsd:normalizedString". |
| 4008 | * |
| 4009 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in |
| 4010 | * case of error |
| 4011 | */ |
| 4012 | static int |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4013 | xmlSchemaComparePreserveReplaceStrings(const xmlChar *x, |
| 4014 | const xmlChar *y, |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4015 | int invert) |
| 4016 | { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4017 | int tmp; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4018 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4019 | while ((*x != 0) && (*y != 0)) { |
| 4020 | if (IS_WSP_REPLACE_CH(*y)) { |
| 4021 | if (! IS_WSP_SPACE_CH(*x)) { |
| 4022 | if ((*x - 0x20) < 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4023 | if (invert) |
| 4024 | return(1); |
| 4025 | else |
| 4026 | return(-1); |
| 4027 | } else { |
| 4028 | if (invert) |
| 4029 | return(-1); |
| 4030 | else |
| 4031 | return(1); |
| 4032 | } |
| 4033 | } |
| 4034 | } else { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4035 | tmp = *x - *y; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4036 | if (tmp < 0) { |
| 4037 | if (invert) |
| 4038 | return(1); |
| 4039 | else |
| 4040 | return(-1); |
| 4041 | } |
| 4042 | if (tmp > 0) { |
| 4043 | if (invert) |
| 4044 | return(-1); |
| 4045 | else |
| 4046 | return(1); |
| 4047 | } |
| 4048 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4049 | x++; |
| 4050 | y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4051 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4052 | if (*x != 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4053 | if (invert) |
| 4054 | return(-1); |
| 4055 | else |
| 4056 | return(1); |
| 4057 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4058 | if (*y != 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4059 | if (invert) |
| 4060 | return(1); |
| 4061 | else |
| 4062 | return(-1); |
| 4063 | } |
| 4064 | return(0); |
| 4065 | } |
| 4066 | |
| 4067 | /** |
| 4068 | * xmlSchemaComparePreserveCollapseStrings: |
| 4069 | * @x: a first string value |
| 4070 | * @y: a second string value |
| 4071 | * |
| 4072 | * Compare 2 string for their normalized values. |
| 4073 | * @x is a string with whitespace of "preserve", @y is |
| 4074 | * a string with a whitespace of "collapse". I.e. @x could |
| 4075 | * be an "xsd:string" and @y an "xsd:normalizedString". |
| 4076 | * |
| 4077 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in |
| 4078 | * case of error |
| 4079 | */ |
| 4080 | static int |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4081 | xmlSchemaComparePreserveCollapseStrings(const xmlChar *x, |
| 4082 | const xmlChar *y, |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4083 | int invert) |
| 4084 | { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4085 | int tmp; |
| 4086 | |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4087 | /* |
| 4088 | * Skip leading blank chars of the collapsed string. |
| 4089 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4090 | while IS_WSP_BLANK_CH(*y) |
| 4091 | y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4092 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4093 | while ((*x != 0) && (*y != 0)) { |
| 4094 | if IS_WSP_BLANK_CH(*y) { |
| 4095 | if (! IS_WSP_SPACE_CH(*x)) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4096 | /* |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4097 | * The yv character would have been replaced to 0x20. |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4098 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4099 | if ((*x - 0x20) < 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4100 | if (invert) |
| 4101 | return(1); |
| 4102 | else |
| 4103 | return(-1); |
| 4104 | } else { |
| 4105 | if (invert) |
| 4106 | return(-1); |
| 4107 | else |
| 4108 | return(1); |
| 4109 | } |
| 4110 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4111 | x++; |
| 4112 | y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4113 | /* |
| 4114 | * Skip contiguous blank chars of the collapsed string. |
| 4115 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4116 | while IS_WSP_BLANK_CH(*y) |
| 4117 | y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4118 | } else { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4119 | tmp = *x++ - *y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4120 | if (tmp < 0) { |
| 4121 | if (invert) |
| 4122 | return(1); |
| 4123 | else |
| 4124 | return(-1); |
| 4125 | } |
| 4126 | if (tmp > 0) { |
| 4127 | if (invert) |
| 4128 | return(-1); |
| 4129 | else |
| 4130 | return(1); |
| 4131 | } |
| 4132 | } |
| 4133 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4134 | if (*x != 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4135 | if (invert) |
| 4136 | return(-1); |
| 4137 | else |
| 4138 | return(1); |
| 4139 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4140 | if (*y != 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4141 | /* |
| 4142 | * Skip trailing blank chars of the collapsed string. |
| 4143 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4144 | while IS_WSP_BLANK_CH(*y) |
| 4145 | y++; |
| 4146 | if (*y != 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4147 | if (invert) |
| 4148 | return(1); |
| 4149 | else |
| 4150 | return(-1); |
| 4151 | } |
| 4152 | } |
| 4153 | return(0); |
| 4154 | } |
| 4155 | |
| 4156 | /** |
| 4157 | * xmlSchemaComparePreserveCollapseStrings: |
| 4158 | * @x: a first string value |
| 4159 | * @y: a second string value |
| 4160 | * |
| 4161 | * Compare 2 string for their normalized values. |
| 4162 | * @x is a string with whitespace of "preserve", @y is |
| 4163 | * a string with a whitespace of "collapse". I.e. @x could |
| 4164 | * be an "xsd:string" and @y an "xsd:normalizedString". |
| 4165 | * |
| 4166 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in |
| 4167 | * case of error |
| 4168 | */ |
| 4169 | static int |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4170 | xmlSchemaCompareReplaceCollapseStrings(const xmlChar *x, |
| 4171 | const xmlChar *y, |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4172 | int invert) |
| 4173 | { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4174 | int tmp; |
| 4175 | |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4176 | /* |
| 4177 | * Skip leading blank chars of the collapsed string. |
| 4178 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4179 | while IS_WSP_BLANK_CH(*y) |
| 4180 | y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4181 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4182 | while ((*x != 0) && (*y != 0)) { |
| 4183 | if IS_WSP_BLANK_CH(*y) { |
| 4184 | if (! IS_WSP_BLANK_CH(*x)) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4185 | /* |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4186 | * The yv character would have been replaced to 0x20. |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4187 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4188 | if ((*x - 0x20) < 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4189 | if (invert) |
| 4190 | return(1); |
| 4191 | else |
| 4192 | return(-1); |
| 4193 | } else { |
| 4194 | if (invert) |
| 4195 | return(-1); |
| 4196 | else |
| 4197 | return(1); |
| 4198 | } |
| 4199 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4200 | x++; |
| 4201 | y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4202 | /* |
| 4203 | * Skip contiguous blank chars of the collapsed string. |
| 4204 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4205 | while IS_WSP_BLANK_CH(*y) |
| 4206 | y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4207 | } else { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4208 | if IS_WSP_BLANK_CH(*x) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4209 | /* |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4210 | * The xv character would have been replaced to 0x20. |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4211 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4212 | if ((0x20 - *y) < 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4213 | if (invert) |
| 4214 | return(1); |
| 4215 | else |
| 4216 | return(-1); |
| 4217 | } else { |
| 4218 | if (invert) |
| 4219 | return(-1); |
| 4220 | else |
| 4221 | return(1); |
| 4222 | } |
| 4223 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4224 | tmp = *x++ - *y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4225 | if (tmp < 0) |
| 4226 | return(-1); |
| 4227 | if (tmp > 0) |
| 4228 | return(1); |
| 4229 | } |
| 4230 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4231 | if (*x != 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4232 | if (invert) |
| 4233 | return(-1); |
| 4234 | else |
| 4235 | return(1); |
| 4236 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4237 | if (*y != 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4238 | /* |
| 4239 | * Skip trailing blank chars of the collapsed string. |
| 4240 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4241 | while IS_WSP_BLANK_CH(*y) |
| 4242 | y++; |
| 4243 | if (*y != 0) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4244 | if (invert) |
| 4245 | return(1); |
| 4246 | else |
| 4247 | return(-1); |
| 4248 | } |
| 4249 | } |
| 4250 | return(0); |
| 4251 | } |
| 4252 | |
| 4253 | |
| 4254 | /** |
| 4255 | * xmlSchemaCompareReplacedStrings: |
| 4256 | * @x: a first string value |
| 4257 | * @y: a second string value |
| 4258 | * |
| 4259 | * Compare 2 string for their normalized values. |
| 4260 | * |
| 4261 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in |
| 4262 | * case of error |
| 4263 | */ |
| 4264 | static int |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4265 | xmlSchemaCompareReplacedStrings(const xmlChar *x, |
| 4266 | const xmlChar *y) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4267 | { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4268 | int tmp; |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4269 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4270 | while ((*x != 0) && (*y != 0)) { |
| 4271 | if IS_WSP_BLANK_CH(*y) { |
| 4272 | if (! IS_WSP_BLANK_CH(*x)) { |
| 4273 | if ((*x - 0x20) < 0) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4274 | return(-1); |
| 4275 | else |
| 4276 | return(1); |
| 4277 | } |
| 4278 | } else { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4279 | if IS_WSP_BLANK_CH(*x) { |
| 4280 | if ((0x20 - *y) < 0) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4281 | return(-1); |
| 4282 | else |
| 4283 | return(1); |
| 4284 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4285 | tmp = *x - *y; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4286 | if (tmp < 0) |
| 4287 | return(-1); |
| 4288 | if (tmp > 0) |
| 4289 | return(1); |
| 4290 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4291 | x++; |
| 4292 | y++; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4293 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4294 | if (*x != 0) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4295 | return(1); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4296 | if (*y != 0) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4297 | return(-1); |
| 4298 | return(0); |
| 4299 | } |
| 4300 | |
| 4301 | /** |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4302 | * xmlSchemaCompareNormStrings: |
| 4303 | * @x: a first string value |
| 4304 | * @y: a second string value |
| 4305 | * |
| 4306 | * Compare 2 string for their normalized values. |
| 4307 | * |
| 4308 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, and -2 in |
| 4309 | * case of error |
| 4310 | */ |
| 4311 | static int |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4312 | xmlSchemaCompareNormStrings(const xmlChar *x, |
| 4313 | const xmlChar *y) { |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4314 | int tmp; |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4315 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4316 | while (IS_BLANK_CH(*x)) x++; |
| 4317 | while (IS_BLANK_CH(*y)) y++; |
| 4318 | while ((*x != 0) && (*y != 0)) { |
| 4319 | if (IS_BLANK_CH(*x)) { |
| 4320 | if (!IS_BLANK_CH(*y)) { |
| 4321 | tmp = *x - *y; |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4322 | return(tmp); |
| 4323 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4324 | while (IS_BLANK_CH(*x)) x++; |
| 4325 | while (IS_BLANK_CH(*y)) y++; |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4326 | } else { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4327 | tmp = *x++ - *y++; |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4328 | if (tmp < 0) |
| 4329 | return(-1); |
| 4330 | if (tmp > 0) |
| 4331 | return(1); |
| 4332 | } |
| 4333 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4334 | if (*x != 0) { |
| 4335 | while (IS_BLANK_CH(*x)) x++; |
| 4336 | if (*x != 0) |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4337 | return(1); |
| 4338 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4339 | if (*y != 0) { |
| 4340 | while (IS_BLANK_CH(*y)) y++; |
| 4341 | if (*y != 0) |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4342 | return(-1); |
| 4343 | } |
| 4344 | return(0); |
| 4345 | } |
| 4346 | |
| 4347 | /** |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 4348 | * xmlSchemaCompareFloats: |
| 4349 | * @x: a first float or double value |
| 4350 | * @y: a second float or double value |
| 4351 | * |
| 4352 | * Compare 2 values |
| 4353 | * |
| 4354 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in |
| 4355 | * case of error |
| 4356 | */ |
| 4357 | static int |
| 4358 | xmlSchemaCompareFloats(xmlSchemaValPtr x, xmlSchemaValPtr y) { |
| 4359 | double d1, d2; |
| 4360 | |
| 4361 | if ((x == NULL) || (y == NULL)) |
| 4362 | return(-2); |
| 4363 | |
| 4364 | /* |
| 4365 | * Cast everything to doubles. |
| 4366 | */ |
| 4367 | if (x->type == XML_SCHEMAS_DOUBLE) |
| 4368 | d1 = x->value.d; |
| 4369 | else if (x->type == XML_SCHEMAS_FLOAT) |
| 4370 | d1 = x->value.f; |
| 4371 | else |
| 4372 | return(-2); |
| 4373 | |
| 4374 | if (y->type == XML_SCHEMAS_DOUBLE) |
| 4375 | d2 = y->value.d; |
| 4376 | else if (y->type == XML_SCHEMAS_FLOAT) |
| 4377 | d2 = y->value.f; |
| 4378 | else |
| 4379 | return(-2); |
| 4380 | |
| 4381 | /* |
| 4382 | * Check for special cases. |
| 4383 | */ |
| 4384 | if (xmlXPathIsNaN(d1)) { |
| 4385 | if (xmlXPathIsNaN(d2)) |
| 4386 | return(0); |
| 4387 | return(1); |
| 4388 | } |
| 4389 | if (xmlXPathIsNaN(d2)) |
| 4390 | return(-1); |
| 4391 | if (d1 == xmlXPathPINF) { |
| 4392 | if (d2 == xmlXPathPINF) |
| 4393 | return(0); |
| 4394 | return(1); |
| 4395 | } |
| 4396 | if (d2 == xmlXPathPINF) |
| 4397 | return(-1); |
| 4398 | if (d1 == xmlXPathNINF) { |
| 4399 | if (d2 == xmlXPathNINF) |
| 4400 | return(0); |
| 4401 | return(-1); |
| 4402 | } |
| 4403 | if (d2 == xmlXPathNINF) |
| 4404 | return(1); |
| 4405 | |
| 4406 | /* |
| 4407 | * basic tests, the last one we should have equality, but |
| 4408 | * portability is more important than speed and handling |
| 4409 | * NaN or Inf in a portable way is always a challenge, so ... |
| 4410 | */ |
| 4411 | if (d1 < d2) |
| 4412 | return(-1); |
| 4413 | if (d1 > d2) |
| 4414 | return(1); |
| 4415 | if (d1 == d2) |
| 4416 | return(0); |
| 4417 | return(2); |
| 4418 | } |
| 4419 | |
| 4420 | /** |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4421 | * xmlSchemaCompareValues: |
| 4422 | * @x: a first value |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4423 | * @xvalue: the first value as a string (optional) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4424 | * @xwtsp: the whitespace type |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4425 | * @y: a second value |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4426 | * @xvalue: the second value as a string (optional) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4427 | * @ywtsp: the whitespace type |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4428 | * |
| 4429 | * Compare 2 values |
| 4430 | * |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4431 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, 3 if not |
| 4432 | * comparable and -2 in case of error |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4433 | */ |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4434 | static int |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4435 | xmlSchemaCompareValuesInternal(xmlSchemaValType xtype, |
| 4436 | xmlSchemaValPtr x, |
| 4437 | const xmlChar *xvalue, |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4438 | xmlSchemaWhitespaceValueType xws, |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4439 | xmlSchemaValType ytype, |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4440 | xmlSchemaValPtr y, |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4441 | const xmlChar *yvalue, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4442 | xmlSchemaWhitespaceValueType yws) |
| 4443 | { |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4444 | switch (xtype) { |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 4445 | case XML_SCHEMAS_UNKNOWN: |
William M. Brack | 2f2a663 | 2004-08-20 23:09:47 +0000 | [diff] [blame] | 4446 | case XML_SCHEMAS_ANYTYPE: |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 4447 | return(-2); |
| 4448 | case XML_SCHEMAS_INTEGER: |
| 4449 | case XML_SCHEMAS_NPINTEGER: |
| 4450 | case XML_SCHEMAS_NINTEGER: |
| 4451 | case XML_SCHEMAS_NNINTEGER: |
| 4452 | case XML_SCHEMAS_PINTEGER: |
| 4453 | case XML_SCHEMAS_INT: |
| 4454 | case XML_SCHEMAS_UINT: |
| 4455 | case XML_SCHEMAS_LONG: |
| 4456 | case XML_SCHEMAS_ULONG: |
| 4457 | case XML_SCHEMAS_SHORT: |
| 4458 | case XML_SCHEMAS_USHORT: |
| 4459 | case XML_SCHEMAS_BYTE: |
| 4460 | case XML_SCHEMAS_UBYTE: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4461 | case XML_SCHEMAS_DECIMAL: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4462 | if ((x == NULL) || (y == NULL)) |
| 4463 | return(-2); |
| 4464 | if (ytype == xtype) |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 4465 | return(xmlSchemaCompareDecimals(x, y)); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4466 | if ((ytype == XML_SCHEMAS_DECIMAL) || |
| 4467 | (ytype == XML_SCHEMAS_INTEGER) || |
| 4468 | (ytype == XML_SCHEMAS_NPINTEGER) || |
| 4469 | (ytype == XML_SCHEMAS_NINTEGER) || |
| 4470 | (ytype == XML_SCHEMAS_NNINTEGER) || |
| 4471 | (ytype == XML_SCHEMAS_PINTEGER) || |
| 4472 | (ytype == XML_SCHEMAS_INT) || |
| 4473 | (ytype == XML_SCHEMAS_UINT) || |
| 4474 | (ytype == XML_SCHEMAS_LONG) || |
| 4475 | (ytype == XML_SCHEMAS_ULONG) || |
| 4476 | (ytype == XML_SCHEMAS_SHORT) || |
| 4477 | (ytype == XML_SCHEMAS_USHORT) || |
| 4478 | (ytype == XML_SCHEMAS_BYTE) || |
| 4479 | (ytype == XML_SCHEMAS_UBYTE)) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4480 | return(xmlSchemaCompareDecimals(x, y)); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 4481 | return(-2); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 4482 | case XML_SCHEMAS_DURATION: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4483 | if ((x == NULL) || (y == NULL)) |
| 4484 | return(-2); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4485 | if (ytype == XML_SCHEMAS_DURATION) |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 4486 | return(xmlSchemaCompareDurations(x, y)); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 4487 | return(-2); |
| 4488 | case XML_SCHEMAS_TIME: |
| 4489 | case XML_SCHEMAS_GDAY: |
| 4490 | case XML_SCHEMAS_GMONTH: |
| 4491 | case XML_SCHEMAS_GMONTHDAY: |
| 4492 | case XML_SCHEMAS_GYEAR: |
| 4493 | case XML_SCHEMAS_GYEARMONTH: |
| 4494 | case XML_SCHEMAS_DATE: |
| 4495 | case XML_SCHEMAS_DATETIME: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4496 | if ((x == NULL) || (y == NULL)) |
| 4497 | return(-2); |
| 4498 | if ((ytype == XML_SCHEMAS_DATETIME) || |
| 4499 | (ytype == XML_SCHEMAS_TIME) || |
| 4500 | (ytype == XML_SCHEMAS_GDAY) || |
| 4501 | (ytype == XML_SCHEMAS_GMONTH) || |
| 4502 | (ytype == XML_SCHEMAS_GMONTHDAY) || |
| 4503 | (ytype == XML_SCHEMAS_GYEAR) || |
| 4504 | (ytype == XML_SCHEMAS_DATE) || |
| 4505 | (ytype == XML_SCHEMAS_GYEARMONTH)) |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 4506 | return (xmlSchemaCompareDates(x, y)); |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 4507 | return (-2); |
Kasimier T. Buchcik | 2ee855d | 2005-03-07 11:14:14 +0000 | [diff] [blame] | 4508 | /* |
| 4509 | * Note that we will support comparison of string types against |
| 4510 | * anySimpleType as well. |
| 4511 | */ |
| 4512 | case XML_SCHEMAS_ANYSIMPLETYPE: |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4513 | case XML_SCHEMAS_STRING: |
| 4514 | case XML_SCHEMAS_NORMSTRING: |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 4515 | case XML_SCHEMAS_TOKEN: |
| 4516 | case XML_SCHEMAS_LANGUAGE: |
| 4517 | case XML_SCHEMAS_NMTOKEN: |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 4518 | case XML_SCHEMAS_NAME: |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 4519 | case XML_SCHEMAS_NCNAME: |
| 4520 | case XML_SCHEMAS_ID: |
| 4521 | case XML_SCHEMAS_IDREF: |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 4522 | case XML_SCHEMAS_ENTITY: |
Daniel Veillard | 80b1909 | 2003-03-28 13:29:53 +0000 | [diff] [blame] | 4523 | case XML_SCHEMAS_ANYURI: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4524 | { |
| 4525 | const xmlChar *xv, *yv; |
| 4526 | |
| 4527 | if (x == NULL) |
| 4528 | xv = xvalue; |
| 4529 | else |
| 4530 | xv = x->value.str; |
| 4531 | if (y == NULL) |
| 4532 | yv = yvalue; |
| 4533 | else |
| 4534 | yv = y->value.str; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4535 | /* |
| 4536 | * TODO: Compare those against QName. |
| 4537 | */ |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4538 | if (ytype == XML_SCHEMAS_QNAME) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4539 | TODO |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4540 | if (y == NULL) |
| 4541 | return(-2); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4542 | return (-2); |
| 4543 | } |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4544 | if ((ytype == XML_SCHEMAS_ANYSIMPLETYPE) || |
| 4545 | (ytype == XML_SCHEMAS_STRING) || |
| 4546 | (ytype == XML_SCHEMAS_NORMSTRING) || |
| 4547 | (ytype == XML_SCHEMAS_TOKEN) || |
| 4548 | (ytype == XML_SCHEMAS_LANGUAGE) || |
| 4549 | (ytype == XML_SCHEMAS_NMTOKEN) || |
| 4550 | (ytype == XML_SCHEMAS_NAME) || |
| 4551 | (ytype == XML_SCHEMAS_NCNAME) || |
| 4552 | (ytype == XML_SCHEMAS_ID) || |
| 4553 | (ytype == XML_SCHEMAS_IDREF) || |
| 4554 | (ytype == XML_SCHEMAS_ENTITY) || |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4555 | (ytype == XML_SCHEMAS_ANYURI)) { |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4556 | |
| 4557 | if (xws == XML_SCHEMA_WHITESPACE_PRESERVE) { |
| 4558 | |
| 4559 | if (yws == XML_SCHEMA_WHITESPACE_PRESERVE) { |
| 4560 | /* TODO: What about x < y or x > y. */ |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4561 | if (xmlStrEqual(xv, yv)) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4562 | return (0); |
| 4563 | else |
| 4564 | return (2); |
| 4565 | } else if (yws == XML_SCHEMA_WHITESPACE_REPLACE) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4566 | return (xmlSchemaComparePreserveReplaceStrings(xv, yv, 0)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4567 | else if (yws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4568 | return (xmlSchemaComparePreserveCollapseStrings(xv, yv, 0)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4569 | |
| 4570 | } else if (xws == XML_SCHEMA_WHITESPACE_REPLACE) { |
| 4571 | |
| 4572 | if (yws == XML_SCHEMA_WHITESPACE_PRESERVE) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4573 | return (xmlSchemaComparePreserveReplaceStrings(yv, xv, 1)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4574 | if (yws == XML_SCHEMA_WHITESPACE_REPLACE) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4575 | return (xmlSchemaCompareReplacedStrings(xv, yv)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4576 | if (yws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4577 | return (xmlSchemaCompareReplaceCollapseStrings(xv, yv, 0)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4578 | |
| 4579 | } else if (xws == XML_SCHEMA_WHITESPACE_COLLAPSE) { |
| 4580 | |
| 4581 | if (yws == XML_SCHEMA_WHITESPACE_PRESERVE) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4582 | return (xmlSchemaComparePreserveCollapseStrings(yv, xv, 1)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4583 | if (yws == XML_SCHEMA_WHITESPACE_REPLACE) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4584 | return (xmlSchemaCompareReplaceCollapseStrings(yv, xv, 1)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4585 | if (yws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4586 | return (xmlSchemaCompareNormStrings(xv, yv)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4587 | } else |
| 4588 | return (-2); |
| 4589 | |
| 4590 | } |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4591 | return (-2); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4592 | } |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 4593 | case XML_SCHEMAS_QNAME: |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 4594 | case XML_SCHEMAS_NOTATION: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4595 | if ((x == NULL) || (y == NULL)) |
| 4596 | return(-2); |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 4597 | if ((ytype == XML_SCHEMAS_QNAME) || |
| 4598 | (ytype == XML_SCHEMAS_NOTATION)) { |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 4599 | if ((xmlStrEqual(x->value.qname.name, y->value.qname.name)) && |
| 4600 | (xmlStrEqual(x->value.qname.uri, y->value.qname.uri))) |
| 4601 | return(0); |
| 4602 | return(2); |
| 4603 | } |
| 4604 | return (-2); |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4605 | case XML_SCHEMAS_FLOAT: |
| 4606 | case XML_SCHEMAS_DOUBLE: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4607 | if ((x == NULL) || (y == NULL)) |
| 4608 | return(-2); |
| 4609 | if ((ytype == XML_SCHEMAS_FLOAT) || |
| 4610 | (ytype == XML_SCHEMAS_DOUBLE)) |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 4611 | return (xmlSchemaCompareFloats(x, y)); |
| 4612 | return (-2); |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4613 | case XML_SCHEMAS_BOOLEAN: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4614 | if ((x == NULL) || (y == NULL)) |
| 4615 | return(-2); |
| 4616 | if (ytype == XML_SCHEMAS_BOOLEAN) { |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 4617 | if (x->value.b == y->value.b) |
| 4618 | return(0); |
| 4619 | if (x->value.b == 0) |
| 4620 | return(-1); |
| 4621 | return(1); |
| 4622 | } |
| 4623 | return (-2); |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 4624 | case XML_SCHEMAS_HEXBINARY: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4625 | if ((x == NULL) || (y == NULL)) |
| 4626 | return(-2); |
| 4627 | if (ytype == XML_SCHEMAS_HEXBINARY) { |
Daniel Veillard | 70bcb0e | 2003-08-08 14:00:28 +0000 | [diff] [blame] | 4628 | if (x->value.hex.total == y->value.hex.total) { |
| 4629 | int ret = xmlStrcmp(x->value.hex.str, y->value.hex.str); |
| 4630 | if (ret > 0) |
| 4631 | return(1); |
| 4632 | else if (ret == 0) |
| 4633 | return(0); |
| 4634 | } |
| 4635 | else if (x->value.hex.total > y->value.hex.total) |
| 4636 | return(1); |
| 4637 | |
| 4638 | return(-1); |
| 4639 | } |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 4640 | return (-2); |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 4641 | case XML_SCHEMAS_BASE64BINARY: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4642 | if ((x == NULL) || (y == NULL)) |
| 4643 | return(-2); |
| 4644 | if (ytype == XML_SCHEMAS_BASE64BINARY) { |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 4645 | if (x->value.base64.total == y->value.base64.total) { |
| 4646 | int ret = xmlStrcmp(x->value.base64.str, |
| 4647 | y->value.base64.str); |
| 4648 | if (ret > 0) |
| 4649 | return(1); |
| 4650 | else if (ret == 0) |
| 4651 | return(0); |
| 4652 | } |
| 4653 | else if (x->value.base64.total > y->value.base64.total) |
| 4654 | return(1); |
| 4655 | else |
| 4656 | return(-1); |
| 4657 | } |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4658 | return (-2); |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4659 | case XML_SCHEMAS_IDREFS: |
| 4660 | case XML_SCHEMAS_ENTITIES: |
| 4661 | case XML_SCHEMAS_NMTOKENS: |
| 4662 | TODO |
| 4663 | break; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4664 | } |
Daniel Veillard | 5a87241 | 2002-05-22 06:40:27 +0000 | [diff] [blame] | 4665 | return -2; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | /** |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4669 | * xmlSchemaCompareValues: |
| 4670 | * @x: a first value |
| 4671 | * @y: a second value |
| 4672 | * |
| 4673 | * Compare 2 values |
| 4674 | * |
| 4675 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in |
| 4676 | * case of error |
| 4677 | */ |
| 4678 | int |
| 4679 | xmlSchemaCompareValues(xmlSchemaValPtr x, xmlSchemaValPtr y) { |
| 4680 | xmlSchemaWhitespaceValueType xws, yws; |
| 4681 | |
Daniel Veillard | 5e09414 | 2005-02-18 19:36:12 +0000 | [diff] [blame] | 4682 | if ((x == NULL) || (y == NULL)) |
| 4683 | return(-2); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4684 | if (x->type == XML_SCHEMAS_STRING) |
| 4685 | xws = XML_SCHEMA_WHITESPACE_PRESERVE; |
| 4686 | else if (x->type == XML_SCHEMAS_NORMSTRING) |
| 4687 | xws = XML_SCHEMA_WHITESPACE_REPLACE; |
| 4688 | else |
| 4689 | xws = XML_SCHEMA_WHITESPACE_COLLAPSE; |
| 4690 | |
| 4691 | if (y->type == XML_SCHEMAS_STRING) |
| 4692 | yws = XML_SCHEMA_WHITESPACE_PRESERVE; |
| 4693 | else if (x->type == XML_SCHEMAS_NORMSTRING) |
| 4694 | yws = XML_SCHEMA_WHITESPACE_REPLACE; |
| 4695 | else |
| 4696 | yws = XML_SCHEMA_WHITESPACE_COLLAPSE; |
| 4697 | |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4698 | return(xmlSchemaCompareValuesInternal(x->type, x, NULL, xws, y->type, |
| 4699 | y, NULL, yws)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | /** |
| 4703 | * xmlSchemaCompareValuesWhtsp: |
| 4704 | * @x: a first value |
| 4705 | * @xws: the whitespace value of x |
| 4706 | * @y: a second value |
| 4707 | * @yws: the whitespace value of y |
| 4708 | * |
| 4709 | * Compare 2 values |
| 4710 | * |
| 4711 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in |
| 4712 | * case of error |
| 4713 | */ |
| 4714 | int |
| 4715 | xmlSchemaCompareValuesWhtsp(xmlSchemaValPtr x, |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4716 | xmlSchemaWhitespaceValueType xws, |
| 4717 | xmlSchemaValPtr y, |
| 4718 | xmlSchemaWhitespaceValueType yws) |
| 4719 | { |
Kasimier T. Buchcik | 9dbb0ce | 2005-03-16 16:39:23 +0000 | [diff] [blame] | 4720 | if ((x == NULL) || (y == NULL)) |
| 4721 | return(-2); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 4722 | return(xmlSchemaCompareValuesInternal(x->type, x, NULL, xws, y->type, |
| 4723 | y, NULL, yws)); |
| 4724 | } |
| 4725 | |
| 4726 | /** |
| 4727 | * xmlSchemaCompareValuesWhtspExt: |
| 4728 | * @x: a first value |
| 4729 | * @xws: the whitespace value of x |
| 4730 | * @y: a second value |
| 4731 | * @yws: the whitespace value of y |
| 4732 | * |
| 4733 | * Compare 2 values |
| 4734 | * |
| 4735 | * Returns -1 if x < y, 0 if x == y, 1 if x > y, 2 if x <> y, and -2 in |
| 4736 | * case of error |
| 4737 | */ |
| 4738 | static int |
| 4739 | xmlSchemaCompareValuesWhtspExt(xmlSchemaValType xtype, |
| 4740 | xmlSchemaValPtr x, |
| 4741 | const xmlChar *xvalue, |
| 4742 | xmlSchemaWhitespaceValueType xws, |
| 4743 | xmlSchemaValType ytype, |
| 4744 | xmlSchemaValPtr y, |
| 4745 | const xmlChar *yvalue, |
| 4746 | xmlSchemaWhitespaceValueType yws) |
| 4747 | { |
| 4748 | return(xmlSchemaCompareValuesInternal(xtype, x, xvalue, xws, ytype, y, |
| 4749 | yvalue, yws)); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 4750 | } |
| 4751 | |
| 4752 | /** |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4753 | * xmlSchemaNormLen: |
| 4754 | * @value: a string |
| 4755 | * |
| 4756 | * Computes the UTF8 length of the normalized value of the string |
| 4757 | * |
| 4758 | * Returns the length or -1 in case of error. |
| 4759 | */ |
| 4760 | static int |
| 4761 | xmlSchemaNormLen(const xmlChar *value) { |
| 4762 | const xmlChar *utf; |
| 4763 | int ret = 0; |
| 4764 | |
| 4765 | if (value == NULL) |
| 4766 | return(-1); |
| 4767 | utf = value; |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4768 | while (IS_BLANK_CH(*utf)) utf++; |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4769 | while (*utf != 0) { |
| 4770 | if (utf[0] & 0x80) { |
| 4771 | if ((utf[1] & 0xc0) != 0x80) |
| 4772 | return(-1); |
| 4773 | if ((utf[0] & 0xe0) == 0xe0) { |
| 4774 | if ((utf[2] & 0xc0) != 0x80) |
| 4775 | return(-1); |
| 4776 | if ((utf[0] & 0xf0) == 0xf0) { |
| 4777 | if ((utf[0] & 0xf8) != 0xf0 || (utf[3] & 0xc0) != 0x80) |
| 4778 | return(-1); |
| 4779 | utf += 4; |
| 4780 | } else { |
| 4781 | utf += 3; |
| 4782 | } |
| 4783 | } else { |
| 4784 | utf += 2; |
| 4785 | } |
William M. Brack | 76e95df | 2003-10-18 16:20:14 +0000 | [diff] [blame] | 4786 | } else if (IS_BLANK_CH(*utf)) { |
| 4787 | while (IS_BLANK_CH(*utf)) utf++; |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4788 | if (*utf == 0) |
| 4789 | break; |
| 4790 | } else { |
| 4791 | utf++; |
| 4792 | } |
| 4793 | ret++; |
| 4794 | } |
| 4795 | return(ret); |
| 4796 | } |
| 4797 | |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 4798 | /** |
| 4799 | * xmlSchemaGetFacetValueAsULong: |
| 4800 | * @facet: an schemas type facet |
| 4801 | * |
| 4802 | * Extract the value of a facet |
| 4803 | * |
| 4804 | * Returns the value as a long |
| 4805 | */ |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4806 | unsigned long |
| 4807 | xmlSchemaGetFacetValueAsULong(xmlSchemaFacetPtr facet) |
| 4808 | { |
| 4809 | /* |
| 4810 | * TODO: Check if this is a decimal. |
| 4811 | */ |
William M. Brack | 094dd86 | 2004-11-14 14:28:34 +0000 | [diff] [blame] | 4812 | if (facet == NULL) |
| 4813 | return 0; |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4814 | return ((unsigned long) facet->val->value.decimal.lo); |
| 4815 | } |
| 4816 | |
Daniel Veillard | c4c2155 | 2003-03-29 10:53:38 +0000 | [diff] [blame] | 4817 | /** |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4818 | * xmlSchemaValidateListSimpleTypeFacet: |
| 4819 | * @facet: the facet to check |
| 4820 | * @value: the lexical repr of the value to validate |
| 4821 | * @actualLen: the number of list items |
| 4822 | * @expectedLen: the resulting expected number of list items |
| 4823 | * |
| 4824 | * Checks the value of a list simple type against a facet. |
| 4825 | * |
| 4826 | * Returns 0 if the value is valid, a positive error code |
| 4827 | * number otherwise and -1 in case of an internal error. |
| 4828 | */ |
| 4829 | int |
| 4830 | xmlSchemaValidateListSimpleTypeFacet(xmlSchemaFacetPtr facet, |
| 4831 | const xmlChar *value, |
| 4832 | unsigned long actualLen, |
| 4833 | unsigned long *expectedLen) |
| 4834 | { |
Daniel Veillard | ce682bc | 2004-11-05 17:22:25 +0000 | [diff] [blame] | 4835 | if (facet == NULL) |
| 4836 | return(-1); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4837 | /* |
| 4838 | * TODO: Check if this will work with large numbers. |
| 4839 | * (compare value.decimal.mi and value.decimal.hi as well?). |
| 4840 | */ |
| 4841 | if (facet->type == XML_SCHEMA_FACET_LENGTH) { |
| 4842 | if (actualLen != facet->val->value.decimal.lo) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4843 | if (expectedLen != NULL) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4844 | *expectedLen = facet->val->value.decimal.lo; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4845 | return (XML_SCHEMAV_CVC_LENGTH_VALID); |
| 4846 | } |
| 4847 | } else if (facet->type == XML_SCHEMA_FACET_MINLENGTH) { |
| 4848 | if (actualLen < facet->val->value.decimal.lo) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4849 | if (expectedLen != NULL) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4850 | *expectedLen = facet->val->value.decimal.lo; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4851 | return (XML_SCHEMAV_CVC_MINLENGTH_VALID); |
| 4852 | } |
| 4853 | } else if (facet->type == XML_SCHEMA_FACET_MAXLENGTH) { |
| 4854 | if (actualLen > facet->val->value.decimal.lo) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4855 | if (expectedLen != NULL) |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4856 | *expectedLen = facet->val->value.decimal.lo; |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 4857 | return (XML_SCHEMAV_CVC_MAXLENGTH_VALID); |
| 4858 | } |
| 4859 | } else |
| 4860 | /* |
| 4861 | * NOTE: That we can pass NULL as xmlSchemaValPtr to |
| 4862 | * xmlSchemaValidateFacet, since the remaining facet types |
| 4863 | * are: XML_SCHEMA_FACET_PATTERN, XML_SCHEMA_FACET_ENUMERATION. |
| 4864 | */ |
| 4865 | return(xmlSchemaValidateFacet(NULL, facet, value, NULL)); |
| 4866 | return (0); |
| 4867 | } |
| 4868 | |
| 4869 | /** |
Daniel Veillard | 6927b10 | 2004-10-27 17:29:04 +0000 | [diff] [blame] | 4870 | * xmlSchemaValidateLengthFacet: |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4871 | * @type: the built-in type |
| 4872 | * @facet: the facet to check |
| 4873 | * @value: the lexical repr. of the value to be validated |
| 4874 | * @val: the precomputed value |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4875 | * @ws: the whitespace type of the value |
| 4876 | * @length: the actual length of the value |
| 4877 | * |
| 4878 | * Checka a value against a "length", "minLength" and "maxLength" |
| 4879 | * facet; sets @length to the computed length of @value. |
| 4880 | * |
| 4881 | * Returns 0 if the value is valid, a positive error code |
| 4882 | * otherwise and -1 in case of an internal or API error. |
| 4883 | */ |
| 4884 | static int |
| 4885 | xmlSchemaValidateLengthFacetInternal(xmlSchemaFacetPtr facet, |
| 4886 | xmlSchemaTypeType valType, |
| 4887 | const xmlChar *value, |
| 4888 | xmlSchemaValPtr val, |
| 4889 | unsigned long *length, |
| 4890 | xmlSchemaWhitespaceValueType ws) |
| 4891 | { |
| 4892 | unsigned int len = 0; |
| 4893 | |
| 4894 | if ((length == NULL) || (facet == NULL)) |
| 4895 | return (-1); |
| 4896 | *length = 0; |
| 4897 | if ((facet->type != XML_SCHEMA_FACET_LENGTH) && |
| 4898 | (facet->type != XML_SCHEMA_FACET_MAXLENGTH) && |
| 4899 | (facet->type != XML_SCHEMA_FACET_MINLENGTH)) |
| 4900 | return (-1); |
| 4901 | |
| 4902 | /* |
| 4903 | * TODO: length, maxLength and minLength must be of type |
| 4904 | * nonNegativeInteger only. Check if decimal is used somehow. |
| 4905 | */ |
| 4906 | if ((facet->val == NULL) || |
| 4907 | ((facet->val->type != XML_SCHEMAS_DECIMAL) && |
| 4908 | (facet->val->type != XML_SCHEMAS_NNINTEGER)) || |
| 4909 | (facet->val->value.decimal.frac != 0)) { |
| 4910 | return(-1); |
| 4911 | } |
| 4912 | if ((val != NULL) && (val->type == XML_SCHEMAS_HEXBINARY)) |
| 4913 | len = val->value.hex.total; |
| 4914 | else if ((val != NULL) && (val->type == XML_SCHEMAS_BASE64BINARY)) |
| 4915 | len = val->value.base64.total; |
| 4916 | else { |
| 4917 | switch (valType) { |
| 4918 | case XML_SCHEMAS_STRING: |
| 4919 | case XML_SCHEMAS_NORMSTRING: |
| 4920 | if (ws == XML_SCHEMA_WHITESPACE_UNKNOWN) { |
| 4921 | /* |
| 4922 | * This is to ensure API compatibility with the old |
| 4923 | * xmlSchemaValidateLengthFacet(). Anyway, this was and |
| 4924 | * is not the correct handling. |
| 4925 | * TODO: Get rid of this case somehow. |
| 4926 | */ |
| 4927 | if (valType == XML_SCHEMAS_STRING) |
| 4928 | len = xmlUTF8Strlen(value); |
| 4929 | else |
| 4930 | len = xmlSchemaNormLen(value); |
| 4931 | } else if (value != NULL) { |
| 4932 | if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
| 4933 | len = xmlSchemaNormLen(value); |
| 4934 | else |
| 4935 | /* |
| 4936 | * Should be OK for "preserve" as well. |
| 4937 | */ |
| 4938 | len = xmlUTF8Strlen(value); |
| 4939 | } |
| 4940 | break; |
| 4941 | case XML_SCHEMAS_IDREF: |
| 4942 | case XML_SCHEMAS_TOKEN: |
| 4943 | case XML_SCHEMAS_LANGUAGE: |
| 4944 | case XML_SCHEMAS_NMTOKEN: |
| 4945 | case XML_SCHEMAS_NAME: |
| 4946 | case XML_SCHEMAS_NCNAME: |
Kasimier T. Buchcik | bd6c3f7 | 2005-05-25 17:29:36 +0000 | [diff] [blame] | 4947 | case XML_SCHEMAS_ID: |
| 4948 | /* |
| 4949 | * FIXME: What exactly to do with anyURI? |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4950 | */ |
| 4951 | case XML_SCHEMAS_ANYURI: |
| 4952 | if (value != NULL) |
| 4953 | len = xmlSchemaNormLen(value); |
| 4954 | break; |
Kasimier T. Buchcik | bd6c3f7 | 2005-05-25 17:29:36 +0000 | [diff] [blame] | 4955 | case XML_SCHEMAS_QNAME: |
| 4956 | case XML_SCHEMAS_NOTATION: |
| 4957 | /* |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 4958 | * For QName and NOTATION, those facets are |
| 4959 | * deprecated and should be ignored. |
Kasimier T. Buchcik | bd6c3f7 | 2005-05-25 17:29:36 +0000 | [diff] [blame] | 4960 | */ |
| 4961 | return (0); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 4962 | default: |
| 4963 | TODO |
| 4964 | } |
| 4965 | } |
| 4966 | *length = (unsigned long) len; |
| 4967 | /* |
| 4968 | * TODO: Return the whole expected value, i.e. "lo", "mi" and "hi". |
| 4969 | */ |
| 4970 | if (facet->type == XML_SCHEMA_FACET_LENGTH) { |
| 4971 | if (len != facet->val->value.decimal.lo) |
| 4972 | return(XML_SCHEMAV_CVC_LENGTH_VALID); |
| 4973 | } else if (facet->type == XML_SCHEMA_FACET_MINLENGTH) { |
| 4974 | if (len < facet->val->value.decimal.lo) |
| 4975 | return(XML_SCHEMAV_CVC_MINLENGTH_VALID); |
| 4976 | } else { |
| 4977 | if (len > facet->val->value.decimal.lo) |
| 4978 | return(XML_SCHEMAV_CVC_MAXLENGTH_VALID); |
| 4979 | } |
| 4980 | |
| 4981 | return (0); |
| 4982 | } |
| 4983 | |
| 4984 | /** |
| 4985 | * xmlSchemaValidateLengthFacet: |
| 4986 | * @type: the built-in type |
| 4987 | * @facet: the facet to check |
| 4988 | * @value: the lexical repr. of the value to be validated |
| 4989 | * @val: the precomputed value |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 4990 | * @length: the actual length of the value |
| 4991 | * |
| 4992 | * Checka a value against a "length", "minLength" and "maxLength" |
| 4993 | * facet; sets @length to the computed length of @value. |
| 4994 | * |
| 4995 | * Returns 0 if the value is valid, a positive error code |
| 4996 | * otherwise and -1 in case of an internal or API error. |
| 4997 | */ |
| 4998 | int |
| 4999 | xmlSchemaValidateLengthFacet(xmlSchemaTypePtr type, |
| 5000 | xmlSchemaFacetPtr facet, |
| 5001 | const xmlChar *value, |
| 5002 | xmlSchemaValPtr val, |
| 5003 | unsigned long *length) |
| 5004 | { |
Daniel Veillard | cc5e233 | 2005-03-16 21:55:35 +0000 | [diff] [blame] | 5005 | if (type == NULL) |
| 5006 | return(-1); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5007 | return (xmlSchemaValidateLengthFacetInternal(facet, |
| 5008 | type->builtInType, value, val, length, |
| 5009 | XML_SCHEMA_WHITESPACE_UNKNOWN)); |
| 5010 | } |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5011 | |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5012 | /** |
| 5013 | * xmlSchemaValidateLengthFacetWhtsp: |
| 5014 | * @facet: the facet to check |
| 5015 | * @valType: the built-in type |
| 5016 | * @value: the lexical repr. of the value to be validated |
| 5017 | * @val: the precomputed value |
| 5018 | * @ws: the whitespace type of the value |
| 5019 | * @length: the actual length of the value |
| 5020 | * |
| 5021 | * Checka a value against a "length", "minLength" and "maxLength" |
| 5022 | * facet; sets @length to the computed length of @value. |
| 5023 | * |
| 5024 | * Returns 0 if the value is valid, a positive error code |
| 5025 | * otherwise and -1 in case of an internal or API error. |
| 5026 | */ |
| 5027 | int |
| 5028 | xmlSchemaValidateLengthFacetWhtsp(xmlSchemaFacetPtr facet, |
| 5029 | xmlSchemaValType valType, |
| 5030 | const xmlChar *value, |
| 5031 | xmlSchemaValPtr val, |
| 5032 | unsigned long *length, |
| 5033 | xmlSchemaWhitespaceValueType ws) |
| 5034 | { |
| 5035 | return (xmlSchemaValidateLengthFacetInternal(facet, valType, value, val, |
| 5036 | length, ws)); |
Daniel Veillard | c0826a7 | 2004-08-10 14:17:33 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
| 5039 | /** |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5040 | * xmlSchemaValidateFacetInternal: |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5041 | * @facet: the facet to check |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5042 | * @fws: the whitespace type of the facet's value |
| 5043 | * @valType: the built-in type of the value |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5044 | * @value: the lexical repr of the value to validate |
| 5045 | * @val: the precomputed value |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5046 | * @ws: the whitespace type of the value |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5047 | * |
| 5048 | * Check a value against a facet condition |
| 5049 | * |
| 5050 | * Returns 0 if the element is schemas valid, a positive error code |
| 5051 | * number otherwise and -1 in case of internal or API error. |
| 5052 | */ |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5053 | static int |
| 5054 | xmlSchemaValidateFacetInternal(xmlSchemaFacetPtr facet, |
| 5055 | xmlSchemaWhitespaceValueType fws, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5056 | xmlSchemaValType valType, |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5057 | const xmlChar *value, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5058 | xmlSchemaValPtr val, |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5059 | xmlSchemaWhitespaceValueType ws) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5060 | { |
| 5061 | int ret; |
| 5062 | |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5063 | if (facet == NULL) |
| 5064 | return(-1); |
| 5065 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5066 | switch (facet->type) { |
| 5067 | case XML_SCHEMA_FACET_PATTERN: |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5068 | /* |
| 5069 | * NOTE that for patterns, the @value needs to be the normalized |
| 5070 | * value, *not* the lexical initial value or the canonical value. |
| 5071 | */ |
| 5072 | if (value == NULL) |
| 5073 | return(-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5074 | ret = xmlRegexpExec(facet->regexp, value); |
| 5075 | if (ret == 1) |
| 5076 | return(0); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5077 | if (ret == 0) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5078 | return(XML_SCHEMAV_CVC_PATTERN_VALID); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5079 | return(ret); |
| 5080 | case XML_SCHEMA_FACET_MAXEXCLUSIVE: |
| 5081 | ret = xmlSchemaCompareValues(val, facet->val); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5082 | if (ret == -2) |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5083 | return(-1); |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5084 | if (ret == -1) |
| 5085 | return(0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5086 | return(XML_SCHEMAV_CVC_MAXEXCLUSIVE_VALID); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 5087 | case XML_SCHEMA_FACET_MAXINCLUSIVE: |
| 5088 | ret = xmlSchemaCompareValues(val, facet->val); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5089 | if (ret == -2) |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 5090 | return(-1); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 5091 | if ((ret == -1) || (ret == 0)) |
| 5092 | return(0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5093 | return(XML_SCHEMAV_CVC_MAXINCLUSIVE_VALID); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 5094 | case XML_SCHEMA_FACET_MINEXCLUSIVE: |
| 5095 | ret = xmlSchemaCompareValues(val, facet->val); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5096 | if (ret == -2) |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 5097 | return(-1); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 5098 | if (ret == 1) |
| 5099 | return(0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5100 | return(XML_SCHEMAV_CVC_MINEXCLUSIVE_VALID); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 5101 | case XML_SCHEMA_FACET_MININCLUSIVE: |
| 5102 | ret = xmlSchemaCompareValues(val, facet->val); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5103 | if (ret == -2) |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 5104 | return(-1); |
Daniel Veillard | 070803b | 2002-05-03 07:29:38 +0000 | [diff] [blame] | 5105 | if ((ret == 1) || (ret == 0)) |
| 5106 | return(0); |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5107 | return(XML_SCHEMAV_CVC_MININCLUSIVE_VALID); |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 5108 | case XML_SCHEMA_FACET_WHITESPACE: |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5109 | /* TODO whitespaces */ |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5110 | /* |
| 5111 | * NOTE: Whitespace should be handled to normalize |
| 5112 | * the value to be validated against a the facets; |
| 5113 | * not to normalize the value in-between. |
| 5114 | */ |
Daniel Veillard | 8651f53 | 2002-04-17 09:06:27 +0000 | [diff] [blame] | 5115 | return(0); |
Daniel Veillard | 88c5891 | 2002-04-23 07:12:20 +0000 | [diff] [blame] | 5116 | case XML_SCHEMA_FACET_ENUMERATION: |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5117 | if (ws == XML_SCHEMA_WHITESPACE_UNKNOWN) { |
| 5118 | /* |
| 5119 | * This is to ensure API compatibility with the old |
| 5120 | * xmlSchemaValidateFacet(). |
| 5121 | * TODO: Get rid of this case. |
| 5122 | */ |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5123 | if ((facet->value != NULL) && |
| 5124 | (xmlStrEqual(facet->value, value))) |
| 5125 | return(0); |
| 5126 | } else { |
| 5127 | ret = xmlSchemaCompareValuesWhtspExt(facet->val->type, |
| 5128 | facet->val, facet->value, fws, valType, val, |
| 5129 | value, ws); |
| 5130 | if (ret == -2) |
| 5131 | return(-1); |
| 5132 | if (ret == 0) |
| 5133 | return(0); |
| 5134 | } |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5135 | return(XML_SCHEMAV_CVC_ENUMERATION_VALID); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5136 | case XML_SCHEMA_FACET_LENGTH: |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5137 | /* |
| 5138 | * SPEC (1.3) "if {primitive type definition} is QName or NOTATION, |
| 5139 | * then any {value} is facet-valid." |
| 5140 | */ |
| 5141 | if ((valType == XML_SCHEMAS_QNAME) || |
| 5142 | (valType == XML_SCHEMAS_NOTATION)) |
| 5143 | return (0); |
| 5144 | /* No break on purpose. */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5145 | case XML_SCHEMA_FACET_MAXLENGTH: |
| 5146 | case XML_SCHEMA_FACET_MINLENGTH: { |
| 5147 | unsigned int len = 0; |
| 5148 | |
Kasimier T. Buchcik | 4efd90d | 2005-06-09 10:32:53 +0000 | [diff] [blame] | 5149 | if ((valType == XML_SCHEMAS_QNAME) || |
| 5150 | (valType == XML_SCHEMAS_NOTATION)) |
| 5151 | return (0); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5152 | /* |
| 5153 | * TODO: length, maxLength and minLength must be of type |
| 5154 | * nonNegativeInteger only. Check if decimal is used somehow. |
| 5155 | */ |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5156 | if ((facet->val == NULL) || |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 5157 | ((facet->val->type != XML_SCHEMAS_DECIMAL) && |
| 5158 | (facet->val->type != XML_SCHEMAS_NNINTEGER)) || |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5159 | (facet->val->value.decimal.frac != 0)) { |
| 5160 | return(-1); |
| 5161 | } |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 5162 | if ((val != NULL) && (val->type == XML_SCHEMAS_HEXBINARY)) |
Daniel Veillard | 70bcb0e | 2003-08-08 14:00:28 +0000 | [diff] [blame] | 5163 | len = val->value.hex.total; |
Daniel Veillard | 1ac24d3 | 2003-08-27 14:15:15 +0000 | [diff] [blame] | 5164 | else if ((val != NULL) && (val->type == XML_SCHEMAS_BASE64BINARY)) |
| 5165 | len = val->value.base64.total; |
| 5166 | else { |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5167 | switch (valType) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5168 | case XML_SCHEMAS_STRING: |
| 5169 | case XML_SCHEMAS_NORMSTRING: |
| 5170 | if (ws == XML_SCHEMA_WHITESPACE_UNKNOWN) { |
| 5171 | /* |
| 5172 | * This is to ensure API compatibility with the old |
| 5173 | * xmlSchemaValidateFacet(). Anyway, this was and |
| 5174 | * is not the correct handling. |
| 5175 | * TODO: Get rid of this case somehow. |
| 5176 | */ |
| 5177 | if (valType == XML_SCHEMAS_STRING) |
| 5178 | len = xmlUTF8Strlen(value); |
| 5179 | else |
| 5180 | len = xmlSchemaNormLen(value); |
| 5181 | } else if (value != NULL) { |
| 5182 | if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
| 5183 | len = xmlSchemaNormLen(value); |
| 5184 | else |
| 5185 | /* |
| 5186 | * Should be OK for "preserve" as well. |
| 5187 | */ |
| 5188 | len = xmlUTF8Strlen(value); |
| 5189 | } |
| 5190 | break; |
| 5191 | case XML_SCHEMAS_IDREF: |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 5192 | case XML_SCHEMAS_TOKEN: |
| 5193 | case XML_SCHEMAS_LANGUAGE: |
| 5194 | case XML_SCHEMAS_NMTOKEN: |
| 5195 | case XML_SCHEMAS_NAME: |
| 5196 | case XML_SCHEMAS_NCNAME: |
| 5197 | case XML_SCHEMAS_ID: |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5198 | case XML_SCHEMAS_ANYURI: |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5199 | if (value != NULL) |
| 5200 | len = xmlSchemaNormLen(value); |
| 5201 | break; |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 5202 | default: |
| 5203 | TODO |
Daniel Veillard | 70bcb0e | 2003-08-08 14:00:28 +0000 | [diff] [blame] | 5204 | } |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5205 | } |
| 5206 | if (facet->type == XML_SCHEMA_FACET_LENGTH) { |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 5207 | if (len != facet->val->value.decimal.lo) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5208 | return(XML_SCHEMAV_CVC_LENGTH_VALID); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5209 | } else if (facet->type == XML_SCHEMA_FACET_MINLENGTH) { |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 5210 | if (len < facet->val->value.decimal.lo) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5211 | return(XML_SCHEMAV_CVC_MINLENGTH_VALID); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5212 | } else { |
Daniel Veillard | e637c4a | 2003-03-30 21:10:09 +0000 | [diff] [blame] | 5213 | if (len > facet->val->value.decimal.lo) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5214 | return(XML_SCHEMAV_CVC_MAXLENGTH_VALID); |
Daniel Veillard | 8bc6cf9 | 2003-02-27 17:42:22 +0000 | [diff] [blame] | 5215 | } |
| 5216 | break; |
| 5217 | } |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 5218 | case XML_SCHEMA_FACET_TOTALDIGITS: |
| 5219 | case XML_SCHEMA_FACET_FRACTIONDIGITS: |
| 5220 | |
| 5221 | if ((facet->val == NULL) || |
| 5222 | ((facet->val->type != XML_SCHEMAS_DECIMAL) && |
| 5223 | (facet->val->type != XML_SCHEMAS_NNINTEGER)) || |
| 5224 | (facet->val->value.decimal.frac != 0)) { |
| 5225 | return(-1); |
| 5226 | } |
| 5227 | if ((val == NULL) || |
| 5228 | ((val->type != XML_SCHEMAS_DECIMAL) && |
| 5229 | (val->type != XML_SCHEMAS_INTEGER) && |
| 5230 | (val->type != XML_SCHEMAS_NPINTEGER) && |
| 5231 | (val->type != XML_SCHEMAS_NINTEGER) && |
| 5232 | (val->type != XML_SCHEMAS_NNINTEGER) && |
| 5233 | (val->type != XML_SCHEMAS_PINTEGER) && |
| 5234 | (val->type != XML_SCHEMAS_INT) && |
| 5235 | (val->type != XML_SCHEMAS_UINT) && |
| 5236 | (val->type != XML_SCHEMAS_LONG) && |
| 5237 | (val->type != XML_SCHEMAS_ULONG) && |
| 5238 | (val->type != XML_SCHEMAS_SHORT) && |
| 5239 | (val->type != XML_SCHEMAS_USHORT) && |
| 5240 | (val->type != XML_SCHEMAS_BYTE) && |
| 5241 | (val->type != XML_SCHEMAS_UBYTE))) { |
| 5242 | return(-1); |
| 5243 | } |
| 5244 | if (facet->type == XML_SCHEMA_FACET_TOTALDIGITS) { |
| 5245 | if (val->value.decimal.total > facet->val->value.decimal.lo) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5246 | return(XML_SCHEMAV_CVC_TOTALDIGITS_VALID); |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 5247 | |
| 5248 | } else if (facet->type == XML_SCHEMA_FACET_FRACTIONDIGITS) { |
| 5249 | if (val->value.decimal.frac > facet->val->value.decimal.lo) |
Daniel Veillard | 01fa615 | 2004-06-29 17:04:39 +0000 | [diff] [blame] | 5250 | return(XML_SCHEMAV_CVC_FRACTIONDIGITS_VALID); |
Daniel Veillard | 560c2a4 | 2003-07-06 21:13:49 +0000 | [diff] [blame] | 5251 | } |
| 5252 | break; |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5253 | default: |
| 5254 | TODO |
| 5255 | } |
| 5256 | return(0); |
Daniel Veillard | b6c7f41 | 2003-03-29 16:41:55 +0000 | [diff] [blame] | 5257 | |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5258 | } |
| 5259 | |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5260 | /** |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5261 | * xmlSchemaValidateFacet: |
| 5262 | * @base: the base type |
| 5263 | * @facet: the facet to check |
| 5264 | * @value: the lexical repr of the value to validate |
| 5265 | * @val: the precomputed value |
| 5266 | * |
| 5267 | * Check a value against a facet condition |
| 5268 | * |
| 5269 | * Returns 0 if the element is schemas valid, a positive error code |
| 5270 | * number otherwise and -1 in case of internal or API error. |
| 5271 | */ |
| 5272 | int |
Kasimier T. Buchcik | 9dbb0ce | 2005-03-16 16:39:23 +0000 | [diff] [blame] | 5273 | xmlSchemaValidateFacet(xmlSchemaTypePtr base, |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5274 | xmlSchemaFacetPtr facet, |
| 5275 | const xmlChar *value, |
| 5276 | xmlSchemaValPtr val) |
| 5277 | { |
| 5278 | /* |
| 5279 | * This tries to ensure API compatibility regarding the old |
| 5280 | * xmlSchemaValidateFacet() and the new xmlSchemaValidateFacetInternal() and |
| 5281 | * xmlSchemaValidateFacetWhtsp(). |
| 5282 | */ |
Kasimier T. Buchcik | 9dbb0ce | 2005-03-16 16:39:23 +0000 | [diff] [blame] | 5283 | if (val != NULL) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5284 | return(xmlSchemaValidateFacetInternal(facet, |
Kasimier T. Buchcik | 9dbb0ce | 2005-03-16 16:39:23 +0000 | [diff] [blame] | 5285 | XML_SCHEMA_WHITESPACE_UNKNOWN, val->type, value, val, |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5286 | XML_SCHEMA_WHITESPACE_UNKNOWN)); |
Kasimier T. Buchcik | 9dbb0ce | 2005-03-16 16:39:23 +0000 | [diff] [blame] | 5287 | else if (base != NULL) |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5288 | return(xmlSchemaValidateFacetInternal(facet, |
Kasimier T. Buchcik | 9dbb0ce | 2005-03-16 16:39:23 +0000 | [diff] [blame] | 5289 | XML_SCHEMA_WHITESPACE_UNKNOWN, base->builtInType, value, val, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5290 | XML_SCHEMA_WHITESPACE_UNKNOWN)); |
Kasimier T. Buchcik | 9dbb0ce | 2005-03-16 16:39:23 +0000 | [diff] [blame] | 5291 | return(-1); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | /** |
| 5295 | * xmlSchemaValidateFacetWhtsp: |
| 5296 | * @facet: the facet to check |
| 5297 | * @fws: the whitespace type of the facet's value |
| 5298 | * @valType: the built-in type of the value |
| 5299 | * @value: the lexical (or normalized for pattern) repr of the value to validate |
| 5300 | * @val: the precomputed value |
| 5301 | * @ws: the whitespace type of the value |
| 5302 | * |
| 5303 | * Check a value against a facet condition. This takes value normalization |
| 5304 | * according to the specified whitespace types into account. |
| 5305 | * Note that @value needs to be the *normalized* value if the facet |
| 5306 | * is of type "pattern". |
| 5307 | * |
| 5308 | * Returns 0 if the element is schemas valid, a positive error code |
| 5309 | * number otherwise and -1 in case of internal or API error. |
| 5310 | */ |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5311 | int |
| 5312 | xmlSchemaValidateFacetWhtsp(xmlSchemaFacetPtr facet, |
| 5313 | xmlSchemaWhitespaceValueType fws, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5314 | xmlSchemaValType valType, |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5315 | const xmlChar *value, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5316 | xmlSchemaValPtr val, |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5317 | xmlSchemaWhitespaceValueType ws) |
| 5318 | { |
| 5319 | return(xmlSchemaValidateFacetInternal(facet, fws, valType, |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5320 | value, val, ws)); |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5321 | } |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5322 | |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 5323 | #if 0 |
| 5324 | #ifndef DBL_DIG |
| 5325 | #define DBL_DIG 16 |
| 5326 | #endif |
| 5327 | #ifndef DBL_EPSILON |
| 5328 | #define DBL_EPSILON 1E-9 |
| 5329 | #endif |
| 5330 | |
| 5331 | #define INTEGER_DIGITS DBL_DIG |
| 5332 | #define FRACTION_DIGITS (DBL_DIG + 1) |
| 5333 | #define EXPONENT_DIGITS (3 + 2) |
| 5334 | |
| 5335 | /** |
| 5336 | * xmlXPathFormatNumber: |
| 5337 | * @number: number to format |
| 5338 | * @buffer: output buffer |
| 5339 | * @buffersize: size of output buffer |
| 5340 | * |
| 5341 | * Convert the number into a string representation. |
| 5342 | */ |
| 5343 | static void |
| 5344 | xmlSchemaFormatFloat(double number, char buffer[], int buffersize) |
| 5345 | { |
| 5346 | switch (xmlXPathIsInf(number)) { |
| 5347 | case 1: |
| 5348 | if (buffersize > (int)sizeof("INF")) |
| 5349 | snprintf(buffer, buffersize, "INF"); |
| 5350 | break; |
| 5351 | case -1: |
| 5352 | if (buffersize > (int)sizeof("-INF")) |
| 5353 | snprintf(buffer, buffersize, "-INF"); |
| 5354 | break; |
| 5355 | default: |
| 5356 | if (xmlXPathIsNaN(number)) { |
| 5357 | if (buffersize > (int)sizeof("NaN")) |
| 5358 | snprintf(buffer, buffersize, "NaN"); |
| 5359 | } else if (number == 0) { |
| 5360 | snprintf(buffer, buffersize, "0.0E0"); |
| 5361 | } else { |
| 5362 | /* 3 is sign, decimal point, and terminating zero */ |
| 5363 | char work[DBL_DIG + EXPONENT_DIGITS + 3]; |
| 5364 | int integer_place, fraction_place; |
| 5365 | char *ptr; |
| 5366 | char *after_fraction; |
| 5367 | double absolute_value; |
| 5368 | int size; |
| 5369 | |
| 5370 | absolute_value = fabs(number); |
| 5371 | |
| 5372 | /* |
| 5373 | * Result is in work, and after_fraction points |
| 5374 | * just past the fractional part. |
| 5375 | * Use scientific notation |
| 5376 | */ |
| 5377 | integer_place = DBL_DIG + EXPONENT_DIGITS + 1; |
| 5378 | fraction_place = DBL_DIG - 1; |
| 5379 | snprintf(work, sizeof(work),"%*.*e", |
| 5380 | integer_place, fraction_place, number); |
| 5381 | after_fraction = strchr(work + DBL_DIG, 'e'); |
| 5382 | /* Remove fractional trailing zeroes */ |
| 5383 | ptr = after_fraction; |
| 5384 | while (*(--ptr) == '0') |
| 5385 | ; |
| 5386 | if (*ptr != '.') |
| 5387 | ptr++; |
| 5388 | while ((*ptr++ = *after_fraction++) != 0); |
| 5389 | |
| 5390 | /* Finally copy result back to caller */ |
| 5391 | size = strlen(work) + 1; |
| 5392 | if (size > buffersize) { |
| 5393 | work[buffersize - 1] = 0; |
| 5394 | size = buffersize; |
| 5395 | } |
| 5396 | memmove(buffer, work, size); |
| 5397 | } |
| 5398 | break; |
| 5399 | } |
| 5400 | } |
| 5401 | #endif |
| 5402 | |
Kasimier T. Buchcik | 6c81d0e | 2005-03-15 14:58:11 +0000 | [diff] [blame] | 5403 | /** |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5404 | * xmlSchemaGetCanonValue: |
| 5405 | * @val: the precomputed value |
| 5406 | * @retValue: the returned value |
| 5407 | * |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5408 | * Get a the cononical lexical representation of the value. |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 5409 | * The caller has to FREE the returned retValue. |
| 5410 | * |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5411 | * WARNING: Some value types are not supported yet, resulting |
| 5412 | * in a @retValue of "???". |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 5413 | * |
| 5414 | * TODO: XML Schema 1.0 does not define canonical representations |
| 5415 | * for: duration, gYearMonth, gYear, gMonthDay, gMonth, gDay, |
| 5416 | * anyURI, QName, NOTATION. This will be fixed in XML Schema 1.1. |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5417 | * |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 5418 | * |
| 5419 | * Returns 0 if the value could be built, 1 if the value type is |
| 5420 | * not supported yet and -1 in case of API errors. |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5421 | */ |
| 5422 | int |
Daniel Veillard | b5839c3 | 2005-02-19 18:27:14 +0000 | [diff] [blame] | 5423 | xmlSchemaGetCanonValue(xmlSchemaValPtr val, const xmlChar **retValue) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5424 | { |
Daniel Veillard | b5839c3 | 2005-02-19 18:27:14 +0000 | [diff] [blame] | 5425 | if ((retValue == NULL) || (val == NULL)) |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5426 | return (-1); |
| 5427 | *retValue = NULL; |
| 5428 | switch (val->type) { |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5429 | case XML_SCHEMAS_STRING: |
| 5430 | if (val->value.str == NULL) |
| 5431 | *retValue = BAD_CAST xmlStrdup(BAD_CAST ""); |
| 5432 | else |
| 5433 | *retValue = |
| 5434 | BAD_CAST xmlStrdup((const xmlChar *) val->value.str); |
| 5435 | break; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5436 | case XML_SCHEMAS_NORMSTRING: |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5437 | if (val->value.str == NULL) |
| 5438 | *retValue = BAD_CAST xmlStrdup(BAD_CAST ""); |
| 5439 | else { |
| 5440 | *retValue = xmlSchemaWhiteSpaceReplace( |
| 5441 | (const xmlChar *) val->value.str); |
| 5442 | if ((*retValue) == NULL) |
| 5443 | *retValue = BAD_CAST xmlStrdup( |
| 5444 | (const xmlChar *) val->value.str); |
| 5445 | } |
| 5446 | break; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5447 | case XML_SCHEMAS_TOKEN: |
| 5448 | case XML_SCHEMAS_LANGUAGE: |
| 5449 | case XML_SCHEMAS_NMTOKEN: |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5450 | case XML_SCHEMAS_NAME: |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5451 | case XML_SCHEMAS_NCNAME: |
| 5452 | case XML_SCHEMAS_ID: |
| 5453 | case XML_SCHEMAS_IDREF: |
| 5454 | case XML_SCHEMAS_ENTITY: |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 5455 | case XML_SCHEMAS_NOTATION: /* Unclear */ |
| 5456 | case XML_SCHEMAS_ANYURI: /* Unclear */ |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5457 | if (val->value.str == NULL) |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5458 | return (-1); |
Kasimier T. Buchcik | aba15f7 | 2005-04-01 15:17:27 +0000 | [diff] [blame] | 5459 | *retValue = |
| 5460 | BAD_CAST xmlSchemaCollapseString(BAD_CAST val->value.str); |
| 5461 | if (*retValue == NULL) |
| 5462 | *retValue = |
| 5463 | BAD_CAST xmlStrdup((const xmlChar *) val->value.str); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5464 | break; |
| 5465 | case XML_SCHEMAS_QNAME: |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 5466 | /* TODO: Unclear in XML Schema 1.0. */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5467 | if (val->value.qname.uri == NULL) { |
| 5468 | *retValue = BAD_CAST xmlStrdup(BAD_CAST val->value.qname.name); |
| 5469 | return (0); |
| 5470 | } else { |
| 5471 | *retValue = BAD_CAST xmlStrdup(BAD_CAST "{"); |
| 5472 | *retValue = BAD_CAST xmlStrcat((xmlChar *) (*retValue), |
| 5473 | BAD_CAST val->value.qname.uri); |
| 5474 | *retValue = BAD_CAST xmlStrcat((xmlChar *) (*retValue), |
| 5475 | BAD_CAST "}"); |
| 5476 | *retValue = BAD_CAST xmlStrcat((xmlChar *) (*retValue), |
| 5477 | BAD_CAST val->value.qname.uri); |
| 5478 | } |
| 5479 | break; |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 5480 | case XML_SCHEMAS_DECIMAL: |
| 5481 | /* |
| 5482 | * TODO: Lookout for a more simple implementation. |
| 5483 | */ |
| 5484 | if ((val->value.decimal.total == 1) && |
| 5485 | (val->value.decimal.lo == 0)) { |
| 5486 | *retValue = xmlStrdup(BAD_CAST "0.0"); |
| 5487 | } else { |
| 5488 | xmlSchemaValDecimal dec = val->value.decimal; |
| 5489 | int bufsize; |
| 5490 | char *buf = NULL, *offs; |
| 5491 | |
| 5492 | /* Add room for the decimal point as well. */ |
| 5493 | bufsize = dec.total + 2; |
| 5494 | if (dec.sign) |
| 5495 | bufsize++; |
| 5496 | /* Add room for leading/trailing zero. */ |
| 5497 | if ((dec.frac == 0) || (dec.frac == dec.total)) |
| 5498 | bufsize++; |
| 5499 | buf = xmlMalloc(bufsize); |
| 5500 | offs = buf; |
| 5501 | if (dec.sign) |
| 5502 | *offs++ = '-'; |
| 5503 | if (dec.frac == dec.total) { |
| 5504 | *offs++ = '0'; |
| 5505 | *offs++ = '.'; |
| 5506 | } |
| 5507 | if (dec.hi != 0) |
| 5508 | snprintf(offs, bufsize - (offs - buf), |
| 5509 | "%lu%lu%lu", dec.hi, dec.mi, dec.lo); |
| 5510 | else if (dec.mi != 0) |
| 5511 | snprintf(offs, bufsize - (offs - buf), |
| 5512 | "%lu%lu", dec.mi, dec.lo); |
| 5513 | else |
| 5514 | snprintf(offs, bufsize - (offs - buf), |
| 5515 | "%lu", dec.lo); |
| 5516 | |
| 5517 | if (dec.frac != 0) { |
| 5518 | if (dec.frac != dec.total) { |
| 5519 | int diff = dec.total - dec.frac; |
| 5520 | /* |
| 5521 | * Insert the decimal point. |
| 5522 | */ |
| 5523 | memmove(offs + diff + 1, offs + diff, dec.frac +1); |
| 5524 | offs[diff] = '.'; |
| 5525 | } else { |
| 5526 | unsigned int i = 0; |
| 5527 | /* |
| 5528 | * Insert missing zeroes behind the decimal point. |
| 5529 | */ |
| 5530 | while (*(offs + i) != 0) |
| 5531 | i++; |
| 5532 | if (i < dec.total) { |
| 5533 | memmove(offs + (dec.total - i), offs, i +1); |
| 5534 | memset(offs, '0', dec.total - i); |
| 5535 | } |
| 5536 | } |
| 5537 | } else { |
| 5538 | /* |
| 5539 | * Append decimal point and zero. |
| 5540 | */ |
| 5541 | offs = buf + bufsize - 1; |
| 5542 | *offs-- = 0; |
| 5543 | *offs-- = '0'; |
| 5544 | *offs-- = '.'; |
| 5545 | } |
| 5546 | *retValue = BAD_CAST buf; |
| 5547 | } |
| 5548 | break; |
| 5549 | case XML_SCHEMAS_INTEGER: |
| 5550 | case XML_SCHEMAS_PINTEGER: |
| 5551 | case XML_SCHEMAS_NPINTEGER: |
| 5552 | case XML_SCHEMAS_NINTEGER: |
| 5553 | case XML_SCHEMAS_NNINTEGER: |
| 5554 | case XML_SCHEMAS_LONG: |
| 5555 | case XML_SCHEMAS_BYTE: |
| 5556 | case XML_SCHEMAS_SHORT: |
| 5557 | case XML_SCHEMAS_INT: |
| 5558 | case XML_SCHEMAS_UINT: |
| 5559 | case XML_SCHEMAS_ULONG: |
| 5560 | case XML_SCHEMAS_USHORT: |
| 5561 | case XML_SCHEMAS_UBYTE: |
| 5562 | if ((val->value.decimal.total == 1) && |
| 5563 | (val->value.decimal.lo == 0)) |
| 5564 | *retValue = xmlStrdup(BAD_CAST "0"); |
| 5565 | else { |
| 5566 | xmlSchemaValDecimal dec = val->value.decimal; |
| 5567 | int bufsize = dec.total + 1; |
| 5568 | |
| 5569 | /* Add room for the decimal point as well. */ |
| 5570 | if (dec.sign) |
| 5571 | bufsize++; |
| 5572 | *retValue = xmlMalloc(bufsize); |
| 5573 | if (dec.hi != 0) { |
| 5574 | if (dec.sign) |
| 5575 | snprintf((char *) *retValue, bufsize, |
| 5576 | "-%lu%lu%lu", dec.hi, dec.mi, dec.lo); |
| 5577 | else |
| 5578 | snprintf((char *) *retValue, bufsize, |
| 5579 | "%lu%lu%lu", dec.hi, dec.mi, dec.lo); |
| 5580 | } else if (dec.mi != 0) { |
| 5581 | if (dec.sign) |
| 5582 | snprintf((char *) *retValue, bufsize, |
| 5583 | "-%lu%lu", dec.mi, dec.lo); |
| 5584 | else |
| 5585 | snprintf((char *) *retValue, bufsize, |
| 5586 | "%lu%lu", dec.mi, dec.lo); |
| 5587 | } else { |
| 5588 | if (dec.sign) |
| 5589 | snprintf((char *) *retValue, bufsize, "-%lu", dec.lo); |
| 5590 | else |
| 5591 | snprintf((char *) *retValue, bufsize, "%lu", dec.lo); |
| 5592 | } |
| 5593 | } |
| 5594 | break; |
| 5595 | case XML_SCHEMAS_BOOLEAN: |
| 5596 | if (val->value.b) |
| 5597 | *retValue = BAD_CAST xmlStrdup(BAD_CAST "true"); |
| 5598 | else |
| 5599 | *retValue = BAD_CAST xmlStrdup(BAD_CAST "false"); |
| 5600 | break; |
| 5601 | case XML_SCHEMAS_DURATION: { |
| 5602 | char buf[100]; |
| 5603 | unsigned long year; |
| 5604 | unsigned long mon, day, hour = 0, min = 0; |
| 5605 | double sec = 0, left; |
| 5606 | |
| 5607 | /* TODO: Unclear in XML Schema 1.0 */ |
| 5608 | /* |
| 5609 | * TODO: This results in a normalized output of the value |
| 5610 | * - which is NOT conformant to the spec - |
| 5611 | * since the exact values of each property are not |
| 5612 | * recoverable. Think about extending the structure to |
| 5613 | * provide a field for every property. |
| 5614 | */ |
| 5615 | year = (unsigned long) FQUOTIENT(labs(val->value.dur.mon), 12); |
| 5616 | mon = labs(val->value.dur.mon) - 12 * year; |
| 5617 | |
| 5618 | day = (unsigned long) FQUOTIENT(fabs(val->value.dur.sec), 86400); |
| 5619 | left = fabs(val->value.dur.sec) - day * 86400; |
| 5620 | if (left > 0) { |
| 5621 | hour = (unsigned long) FQUOTIENT(left, 3600); |
| 5622 | left = left - (hour * 3600); |
| 5623 | if (left > 0) { |
| 5624 | min = (unsigned long) FQUOTIENT(left, 60); |
| 5625 | sec = left - (min * 60); |
| 5626 | } |
| 5627 | } |
| 5628 | if ((val->value.dur.mon < 0) || (val->value.dur.sec < 0)) |
| 5629 | snprintf(buf, 100, "P%luY%luM%luDT%luH%luM%.14gS", |
| 5630 | year, mon, day, hour, min, sec); |
| 5631 | else |
| 5632 | snprintf(buf, 100, "-P%luY%luM%luDT%luH%luM%.14gS", |
| 5633 | year, mon, day, hour, min, sec); |
| 5634 | *retValue = BAD_CAST xmlStrdup(BAD_CAST buf); |
| 5635 | } |
| 5636 | break; |
| 5637 | case XML_SCHEMAS_GYEAR: { |
| 5638 | char buf[30]; |
| 5639 | /* TODO: Unclear in XML Schema 1.0 */ |
| 5640 | /* TODO: What to do with the timezone? */ |
| 5641 | snprintf(buf, 30, "%04ld", val->value.date.year); |
| 5642 | *retValue = BAD_CAST xmlStrdup(BAD_CAST buf); |
| 5643 | } |
| 5644 | break; |
| 5645 | case XML_SCHEMAS_GMONTH: { |
| 5646 | /* TODO: Unclear in XML Schema 1.0 */ |
| 5647 | /* TODO: What to do with the timezone? */ |
| 5648 | *retValue = xmlMalloc(5); |
| 5649 | snprintf((char *) *retValue, 6, "--%02u", |
| 5650 | val->value.date.mon); |
| 5651 | } |
| 5652 | break; |
| 5653 | case XML_SCHEMAS_GDAY: { |
| 5654 | /* TODO: Unclear in XML Schema 1.0 */ |
| 5655 | /* TODO: What to do with the timezone? */ |
| 5656 | *retValue = xmlMalloc(6); |
| 5657 | snprintf((char *) *retValue, 6, "---%02u", |
| 5658 | val->value.date.day); |
| 5659 | } |
| 5660 | break; |
| 5661 | case XML_SCHEMAS_GMONTHDAY: { |
| 5662 | /* TODO: Unclear in XML Schema 1.0 */ |
| 5663 | /* TODO: What to do with the timezone? */ |
| 5664 | *retValue = xmlMalloc(8); |
| 5665 | snprintf((char *) *retValue, 8, "--%02u-%02u", |
| 5666 | val->value.date.mon, val->value.date.day); |
| 5667 | } |
| 5668 | break; |
| 5669 | case XML_SCHEMAS_GYEARMONTH: { |
| 5670 | char buf[35]; |
| 5671 | /* TODO: Unclear in XML Schema 1.0 */ |
| 5672 | /* TODO: What to do with the timezone? */ |
| 5673 | if (val->value.date.year < 0) |
| 5674 | snprintf(buf, 35, "-%04ld-%02u", |
| 5675 | labs(val->value.date.year), |
| 5676 | val->value.date.mon); |
| 5677 | else |
| 5678 | snprintf(buf, 35, "%04ld-%02u", |
| 5679 | val->value.date.year, val->value.date.mon); |
| 5680 | *retValue = BAD_CAST xmlStrdup(BAD_CAST buf); |
| 5681 | } |
| 5682 | break; |
| 5683 | case XML_SCHEMAS_TIME: |
| 5684 | { |
| 5685 | char buf[30]; |
| 5686 | |
| 5687 | if (val->value.date.tz_flag) { |
| 5688 | xmlSchemaValPtr norm; |
| 5689 | |
| 5690 | norm = xmlSchemaDateNormalize(val, 0); |
| 5691 | if (norm == NULL) |
| 5692 | return (-1); |
| 5693 | /* |
| 5694 | * TODO: Check if "%.14g" is portable. |
| 5695 | */ |
| 5696 | snprintf(buf, 30, |
| 5697 | "%02u:%02u:%02.14gZ", |
| 5698 | norm->value.date.hour, |
| 5699 | norm->value.date.min, |
| 5700 | norm->value.date.sec); |
| 5701 | xmlSchemaFreeValue(norm); |
| 5702 | } else { |
| 5703 | snprintf(buf, 30, |
| 5704 | "%02u:%02u:%02.14g", |
| 5705 | val->value.date.hour, |
| 5706 | val->value.date.min, |
| 5707 | val->value.date.sec); |
| 5708 | } |
| 5709 | *retValue = BAD_CAST xmlStrdup(BAD_CAST buf); |
| 5710 | } |
| 5711 | break; |
| 5712 | case XML_SCHEMAS_DATE: |
| 5713 | { |
| 5714 | char buf[30]; |
| 5715 | |
| 5716 | if (val->value.date.tz_flag) { |
| 5717 | xmlSchemaValPtr norm; |
| 5718 | |
| 5719 | norm = xmlSchemaDateNormalize(val, 0); |
| 5720 | if (norm == NULL) |
| 5721 | return (-1); |
| 5722 | /* |
| 5723 | * TODO: Append the canonical value of the |
| 5724 | * recoverable timezone and not "Z". |
| 5725 | */ |
| 5726 | snprintf(buf, 30, |
| 5727 | "%04ld:%02u:%02uZ", |
| 5728 | norm->value.date.year, norm->value.date.mon, |
| 5729 | norm->value.date.day); |
| 5730 | xmlSchemaFreeValue(norm); |
| 5731 | } else { |
| 5732 | snprintf(buf, 30, |
| 5733 | "%04ld:%02u:%02u", |
| 5734 | val->value.date.year, val->value.date.mon, |
| 5735 | val->value.date.day); |
| 5736 | } |
| 5737 | *retValue = BAD_CAST xmlStrdup(BAD_CAST buf); |
| 5738 | } |
| 5739 | break; |
| 5740 | case XML_SCHEMAS_DATETIME: |
| 5741 | { |
| 5742 | char buf[50]; |
| 5743 | |
| 5744 | if (val->value.date.tz_flag) { |
| 5745 | xmlSchemaValPtr norm; |
| 5746 | |
| 5747 | norm = xmlSchemaDateNormalize(val, 0); |
| 5748 | if (norm == NULL) |
| 5749 | return (-1); |
| 5750 | /* |
| 5751 | * TODO: Check if "%.14g" is portable. |
| 5752 | */ |
| 5753 | snprintf(buf, 50, |
| 5754 | "%04ld:%02u:%02uT%02u:%02u:%02.14gZ", |
| 5755 | norm->value.date.year, norm->value.date.mon, |
| 5756 | norm->value.date.day, norm->value.date.hour, |
| 5757 | norm->value.date.min, norm->value.date.sec); |
| 5758 | xmlSchemaFreeValue(norm); |
| 5759 | } else { |
| 5760 | snprintf(buf, 50, |
| 5761 | "%04ld:%02u:%02uT%02u:%02u:%02.14g", |
| 5762 | val->value.date.year, val->value.date.mon, |
| 5763 | val->value.date.day, val->value.date.hour, |
| 5764 | val->value.date.min, val->value.date.sec); |
| 5765 | } |
| 5766 | *retValue = BAD_CAST xmlStrdup(BAD_CAST buf); |
| 5767 | } |
| 5768 | break; |
| 5769 | case XML_SCHEMAS_HEXBINARY: |
| 5770 | *retValue = BAD_CAST xmlStrdup(BAD_CAST val->value.hex.str); |
| 5771 | break; |
| 5772 | case XML_SCHEMAS_BASE64BINARY: |
| 5773 | /* |
| 5774 | * TODO: Is the following spec piece implemented?: |
| 5775 | * SPEC: "Note: For some values the canonical form defined |
| 5776 | * above does not conform to [RFC 2045], which requires breaking |
| 5777 | * with linefeeds at appropriate intervals." |
| 5778 | */ |
| 5779 | *retValue = BAD_CAST xmlStrdup(BAD_CAST val->value.base64.str); |
| 5780 | break; |
| 5781 | case XML_SCHEMAS_FLOAT: { |
| 5782 | char buf[30]; |
| 5783 | /* |
| 5784 | * |m| < 16777216, -149 <= e <= 104. |
| 5785 | * TODO: Handle, NaN, INF, -INF. The format is not |
| 5786 | * yet conformant. The c type float does not cover |
| 5787 | * the whole range. |
| 5788 | */ |
| 5789 | snprintf(buf, 30, "%01.14e", val->value.f); |
| 5790 | *retValue = BAD_CAST xmlStrdup(BAD_CAST buf); |
| 5791 | } |
| 5792 | break; |
| 5793 | case XML_SCHEMAS_DOUBLE: { |
| 5794 | char buf[40]; |
| 5795 | /* |m| < 9007199254740992, -1075 <= e <= 970 */ |
| 5796 | /* |
| 5797 | * TODO: Handle, NaN, INF, -INF. The format is not |
| 5798 | * yet conformant. The c type float does not cover |
| 5799 | * the whole range. |
| 5800 | */ |
| 5801 | snprintf(buf, 40, "%01.14e", val->value.d); |
| 5802 | *retValue = BAD_CAST xmlStrdup(BAD_CAST buf); |
| 5803 | } |
| 5804 | break; |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5805 | default: |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5806 | *retValue = BAD_CAST xmlStrdup(BAD_CAST "???"); |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 5807 | return (1); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5808 | } |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5809 | return (0); |
| 5810 | } |
| 5811 | |
Daniel Veillard | bda5957 | 2005-04-01 17:15:17 +0000 | [diff] [blame] | 5812 | /** |
Kasimier T. Buchcik | c872afb | 2005-04-18 10:57:04 +0000 | [diff] [blame] | 5813 | * xmlSchemaGetCanonValueWhtsp: |
| 5814 | * @val: the precomputed value |
| 5815 | * @retValue: the returned value |
| 5816 | * @ws: the whitespace type of the value |
| 5817 | * |
| 5818 | * Get a the cononical representation of the value. |
| 5819 | * The caller has to free the returned @retValue. |
| 5820 | * |
| 5821 | * Returns 0 if the value could be built, 1 if the value type is |
| 5822 | * not supported yet and -1 in case of API errors. |
| 5823 | */ |
| 5824 | int |
| 5825 | xmlSchemaGetCanonValueWhtsp(xmlSchemaValPtr val, |
| 5826 | const xmlChar **retValue, |
| 5827 | xmlSchemaWhitespaceValueType ws) |
| 5828 | { |
| 5829 | if ((retValue == NULL) || (val == NULL)) |
| 5830 | return (-1); |
| 5831 | if ((ws == XML_SCHEMA_WHITESPACE_UNKNOWN) || |
| 5832 | (ws > XML_SCHEMA_WHITESPACE_COLLAPSE)) |
| 5833 | return (-1); |
| 5834 | |
| 5835 | *retValue = NULL; |
| 5836 | switch (val->type) { |
| 5837 | case XML_SCHEMAS_STRING: |
| 5838 | if (val->value.str == NULL) |
| 5839 | *retValue = BAD_CAST xmlStrdup(BAD_CAST ""); |
| 5840 | else if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
| 5841 | *retValue = xmlSchemaCollapseString(val->value.str); |
| 5842 | else if (ws == XML_SCHEMA_WHITESPACE_REPLACE) |
| 5843 | *retValue = xmlSchemaWhiteSpaceReplace(val->value.str); |
| 5844 | if ((*retValue) == NULL) |
| 5845 | *retValue = BAD_CAST xmlStrdup(val->value.str); |
| 5846 | break; |
| 5847 | case XML_SCHEMAS_NORMSTRING: |
| 5848 | if (val->value.str == NULL) |
| 5849 | *retValue = BAD_CAST xmlStrdup(BAD_CAST ""); |
| 5850 | else { |
| 5851 | if (ws == XML_SCHEMA_WHITESPACE_COLLAPSE) |
| 5852 | *retValue = xmlSchemaCollapseString(val->value.str); |
| 5853 | else |
| 5854 | *retValue = xmlSchemaWhiteSpaceReplace(val->value.str); |
| 5855 | if ((*retValue) == NULL) |
| 5856 | *retValue = BAD_CAST xmlStrdup(val->value.str); |
| 5857 | } |
| 5858 | break; |
| 5859 | default: |
| 5860 | return (xmlSchemaGetCanonValue(val, retValue)); |
| 5861 | } |
| 5862 | return (0); |
| 5863 | } |
| 5864 | |
| 5865 | /** |
Daniel Veillard | bda5957 | 2005-04-01 17:15:17 +0000 | [diff] [blame] | 5866 | * xmlSchemaGetValType: |
| 5867 | * @val: a schemas value |
| 5868 | * |
| 5869 | * Accessor for the type of a value |
| 5870 | * |
| 5871 | * Returns the xmlSchemaValType of the value |
| 5872 | */ |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5873 | xmlSchemaValType |
| 5874 | xmlSchemaGetValType(xmlSchemaValPtr val) |
| 5875 | { |
Daniel Veillard | bda5957 | 2005-04-01 17:15:17 +0000 | [diff] [blame] | 5876 | if (val == NULL) |
| 5877 | return(XML_SCHEMAS_UNKNOWN); |
Kasimier T. Buchcik | 478d693 | 2005-03-16 16:29:18 +0000 | [diff] [blame] | 5878 | return (val->type); |
Kasimier T. Buchcik | 6e224f1 | 2005-02-17 11:10:44 +0000 | [diff] [blame] | 5879 | } |
| 5880 | |
Daniel Veillard | 5d4644e | 2005-04-01 13:11:58 +0000 | [diff] [blame] | 5881 | #define bottom_xmlschemastypes |
| 5882 | #include "elfgcchack.h" |
Daniel Veillard | 4255d50 | 2002-04-16 15:50:10 +0000 | [diff] [blame] | 5883 | #endif /* LIBXML_SCHEMAS_ENABLED */ |