📄 xmlschemastypes.c
字号:
tmp = xmlSchemaValPredefTypeNode(type, cur, NULL, node); if (tmp != 0) break; while (*cur != 0) cur++; while ((*cur == 0) && (cur != endval)) cur++; } /* TODO what return value ? c.f. bug #158628 if (ret != NULL) { TODO } */ xmlFree(val); if (tmp == 0) return(nb_values); return(-1);}/** * xmlSchemaParseUInt: * @str: pointer to the string R/W * @llo: pointer to the low result * @lmi: pointer to the mid result * @lhi: pointer to the high result * * Parse an unsigned long into 3 fields. * * Returns the number of significant digits in the number or * -1 if overflow of the capacity */static intxmlSchemaParseUInt(const xmlChar **str, unsigned long *llo, unsigned long *lmi, unsigned long *lhi) { unsigned long lo = 0, mi = 0, hi = 0; const xmlChar *tmp, *cur = *str; int ret = 0, i = 0; while (*cur == '0') { /* ignore leading zeroes */ cur++; } tmp = cur; while ((*tmp != 0) && (*tmp >= '0') && (*tmp <= '9')) { i++;tmp++;ret++; } if (i > 24) { *str = tmp; return(-1); } while (i > 16) { hi = hi * 10 + (*cur++ - '0'); i--; } while (i > 8) { mi = mi * 10 + (*cur++ - '0'); i--; } while (i > 0) { lo = lo * 10 + (*cur++ - '0'); i--; } *str = cur; *llo = lo; *lmi = mi; *lhi = hi; return(ret);}/** * xmlSchemaValAtomicType: * @type: the predefined type * @value: the value to check * @val: the return computed value * @node: the node containing the value * flags: flags to control the vlidation * * Check that a value conforms to the lexical space of the atomic type. * if true a value is computed and returned in @val. * This checks the value space for list types as well (IDREFS, NMTOKENS). * * Returns 0 if this validates, a positive error code number otherwise * and -1 in case of internal or API error. */static intxmlSchemaValAtomicType(xmlSchemaTypePtr type, const xmlChar * value, xmlSchemaValPtr * val, xmlNodePtr node, int flags){ xmlSchemaValPtr v; xmlChar *norm = NULL; int ret = 0; if (xmlSchemaTypesInitialized == 0) xmlSchemaInitTypes(); if (type == NULL) return (-1); /* * validating a non existant text node is similar to validating * an empty one. */ if (value == NULL) value = BAD_CAST ""; if (val != NULL) *val = NULL; if ((flags == 0) && (value != NULL)) { if ((type->builtInType != XML_SCHEMAS_STRING) && (type->builtInType != XML_SCHEMAS_ANYTYPE) && (type->builtInType != XML_SCHEMAS_ANYSIMPLETYPE)) { if (type->builtInType == XML_SCHEMAS_NORMSTRING) norm = xmlSchemaWhiteSpaceReplace(value); else norm = xmlSchemaCollapseString(value); if (norm != NULL) value = norm; } } switch (type->builtInType) { case XML_SCHEMAS_UNKNOWN: goto error; case XML_SCHEMAS_ANYTYPE: case XML_SCHEMAS_ANYSIMPLETYPE: goto return0; case XML_SCHEMAS_STRING: goto return0; case XML_SCHEMAS_NORMSTRING:{ const xmlChar *cur = value; while (*cur != 0) { if ((*cur == 0xd) || (*cur == 0xa) || (*cur == 0x9)) { goto return1; } else { cur++; } } if (val != NULL) { v = xmlSchemaNewValue(XML_SCHEMAS_NORMSTRING); if (v != NULL) { v->value.str = xmlStrdup(value); *val = v; } else { goto error; } } goto return0; } case XML_SCHEMAS_DECIMAL:{ const xmlChar *cur = value; unsigned int len, neg = 0; xmlChar cval[25]; xmlChar *cptr = cval; int dec = -1; if (cur == NULL) goto return1; /* First we handle an optional sign */ if (*cur == '+') cur++; else if (*cur == '-') { neg = 1; cur++; } /* * Next we "pre-parse" the number, in preparation for calling * the common routine xmlSchemaParseUInt. We get rid of any * leading zeroes (because we have reserved only 25 chars), * and note the position of any decimal point. */ len = 0; while (len < 24) { if ((*cur >= '0') && (*cur <= '9')) { *cptr++ = *cur; len++; } else if (*cur == '.') { if (dec != -1) goto return1; /* multiple decimal points */ if (!len) { /* num starts with '.' */ *cptr++ = '0'; len++; } dec = len++; } else break; cur++; } if (*cur != 0) goto return1; /* error if any extraneous chars */ if (val != NULL) { v = xmlSchemaNewValue(XML_SCHEMAS_DECIMAL); if (v != NULL) { /* * If a mixed decimal, get rid of trailing zeroes */ if (dec != -1) { while ((cptr > cval) && (*(cptr-1) == '0')) { cptr--; len--; } } *cptr = 0; /* Terminate our (preparsed) string */ cptr = cval; /* * Now evaluate the significant digits of the number */ xmlSchemaParseUInt((const xmlChar **)&cptr, &v->value.decimal.lo, &v->value.decimal.mi, &v->value.decimal.hi); v->value.decimal.sign = neg; if (dec == -1) { v->value.decimal.frac = 0; v->value.decimal.total = len; } else { v->value.decimal.frac = len - dec - 1; v->value.decimal.total = len - 1; } *val = v; } } goto return0; } case XML_SCHEMAS_TIME: case XML_SCHEMAS_GDAY: case XML_SCHEMAS_GMONTH: case XML_SCHEMAS_GMONTHDAY: case XML_SCHEMAS_GYEAR: case XML_SCHEMAS_GYEARMONTH: case XML_SCHEMAS_DATE: case XML_SCHEMAS_DATETIME: ret = xmlSchemaValidateDates(type->builtInType, value, val); break; case XML_SCHEMAS_DURATION: ret = xmlSchemaValidateDuration(type, value, val); break; case XML_SCHEMAS_FLOAT: case XML_SCHEMAS_DOUBLE:{ const xmlChar *cur = value; int neg = 0; if (cur == NULL) goto return1; if ((cur[0] == 'N') && (cur[1] == 'a') && (cur[2] == 'N')) { cur += 3; if (*cur != 0) goto return1; if (val != NULL) { if (type == xmlSchemaTypeFloatDef) { v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT); if (v != NULL) { v->value.f = (float) xmlXPathNAN; } else { xmlSchemaFreeValue(v); goto error; } } else { v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE); if (v != NULL) { v->value.d = xmlXPathNAN; } else { xmlSchemaFreeValue(v); goto error; } } *val = v; } goto return0; } if (*cur == '-') { neg = 1; cur++; } if ((cur[0] == 'I') && (cur[1] == 'N') && (cur[2] == 'F')) { cur += 3; if (*cur != 0) goto return1; if (val != NULL) { if (type == xmlSchemaTypeFloatDef) { v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT); if (v != NULL) { if (neg) v->value.f = (float) xmlXPathNINF; else v->value.f = (float) xmlXPathPINF; } else { xmlSchemaFreeValue(v); goto error; } } else { v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE); if (v != NULL) { if (neg) v->value.d = xmlXPathNINF; else v->value.d = xmlXPathPINF; } else { xmlSchemaFreeValue(v); goto error; } } *val = v; } goto return0; } if ((neg == 0) && (*cur == '+')) cur++; if ((cur[0] == 0) || (cur[0] == '+') || (cur[0] == '-')) goto return1; while ((*cur >= '0') && (*cur <= '9')) { cur++; } if (*cur == '.') { cur++; while ((*cur >= '0') && (*cur <= '9')) cur++; } if ((*cur == 'e') || (*cur == 'E')) { cur++; if ((*cur == '-') || (*cur == '+')) cur++; while ((*cur >= '0') && (*cur <= '9')) cur++; } if (*cur != 0) goto return1; if (val != NULL) { if (type == xmlSchemaTypeFloatDef) { v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT); if (v != NULL) { /* * TODO: sscanf seems not to give the correct * value for extremely high/low values. * E.g. "1E-149" results in zero. */ if (sscanf((const char *) value, "%f", &(v->value.f)) == 1) { *val = v; } else { xmlSchemaFreeValue(v); goto return1; } } else { goto error; } } else { v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE); if (v != NULL) { /* * TODO: sscanf seems not to give the correct * value for extremely high/low values. */ if (sscanf((const char *) value, "%lf", &(v->value.d)) == 1) { *val = v; } else { xmlSchemaFreeValue(v); goto return1; } } else { goto error; } } } goto return0; } case XML_SCHEMAS_BOOLEAN:{ const xmlChar *cur = value; if ((cur[0] == '0') && (cur[1] == 0)) ret = 0; else if ((cur[0] == '1') && (cur[1] == 0)) ret = 1; else if ((cur[0] == 't') && (cur[1] == 'r') && (cur[2] == 'u') && (cur[3] == 'e') && (cur[4] == 0)) ret = 1; else if ((cur[0] == 'f') && (cur[1] == 'a') && (cur[2] == 'l') && (cur[3] == 's') && (cur[4] == 'e') && (cur[5] == 0)) ret = 0; else goto return1; if (val != NULL) { v = xmlSchemaNewValue(XML_SCHEMAS_BOOLEAN); if (v != NULL) { v->value.b = ret; *val = v; } else { goto error; } } goto return0; } case XML_SCHEMAS_TOKEN:{ const xmlChar *cur = value; if (IS_BLANK_CH(*cur)) goto return1; while (*cur != 0) { if ((*cur == 0xd) || (*cur == 0xa) || (*cur == 0x9)) { goto return1; } else if (*cur == ' ') { cur++; if (*cur == 0) goto return1; if (*cur == ' ') goto return1; } else { cur++; } } if (val != NULL) { v = xmlSchemaNewValue(XML_SCHEMAS_TOKEN); if (v != NULL) { v->value.str = xmlStrdup(value); *val = v; } else { goto error; } } goto return0; } case XML_SCHEMAS_LANGUAGE: if (xmlCheckLanguageID(value) == 1) { if (val != NULL) { v = xmlSchemaNewValue(XML_SCHEMAS_LANGUAGE); if (v != NULL) { v->value.str = xmlStrdup(value); *val = v; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -