📄 xmlschemastypes.c
字号:
goto error; } /* * it should be an xs:gMonthDay or xs:gMonth */ ret = _xmlSchemaParseGMonth(&(dt->value.date), &cur); if (ret != 0) goto error; /* * a '-' char could indicate this type is xs:gMonthDay or * a negative time zone offset. Check for xs:gMonthDay first. * Also the first three char's of a negative tzo (-MM:SS) can * appear to be a valid day; so even if the day portion * of the xs:gMonthDay verifies, we must insure it was not * a tzo. */ if (*cur == '-') { const xmlChar *rewnd = cur; cur++; ret = _xmlSchemaParseGDay(&(dt->value.date), &cur); if ((ret == 0) && ((*cur == 0) || (*cur != ':'))) { /* * we can use the VALID_MDAY macro to validate the month * and day because the leap year test will flag year zero * as a leap year (even though zero is an invalid year). */ if (VALID_MDAY((&(dt->value.date)))) { RETURN_TYPE_IF_VALID(XML_SCHEMAS_GMONTHDAY); goto error; } } /* * not xs:gMonthDay so rewind and check if just xs:gMonth * with an optional time zone. */ cur = rewnd; } RETURN_TYPE_IF_VALID(XML_SCHEMAS_GMONTH); goto error; } /* * It's a right-truncated date or an xs:time. * Try to parse an xs:time then fallback on right-truncated dates. */ if ((*cur >= '0') && (*cur <= '9')) { ret = _xmlSchemaParseTime(&(dt->value.date), &cur); if (ret == 0) { /* it's an xs:time */ RETURN_TYPE_IF_VALID(XML_SCHEMAS_TIME); } } /* fallback on date parsing */ cur = dateTime; ret = _xmlSchemaParseGYear(&(dt->value.date), &cur); if (ret != 0) goto error; /* is it an xs:gYear? */ RETURN_TYPE_IF_VALID(XML_SCHEMAS_GYEAR); if (*cur != '-') goto error; cur++; ret = _xmlSchemaParseGMonth(&(dt->value.date), &cur); if (ret != 0) goto error; /* is it an xs:gYearMonth? */ RETURN_TYPE_IF_VALID(XML_SCHEMAS_GYEARMONTH); if (*cur != '-') goto error; cur++; ret = _xmlSchemaParseGDay(&(dt->value.date), &cur); if ((ret != 0) || !VALID_DATE((&(dt->value.date)))) goto error; /* is it an xs:date? */ RETURN_TYPE_IF_VALID(XML_SCHEMAS_DATE); if (*cur != 'T') goto error; cur++; /* it should be an xs:dateTime */ ret = _xmlSchemaParseTime(&(dt->value.date), &cur); if (ret != 0) goto error; ret = _xmlSchemaParseTimeZone(&(dt->value.date), &cur); if ((ret != 0) || (*cur != 0) || !VALID_DATETIME((&(dt->value.date)))) goto error; dt->type = XML_SCHEMAS_DATETIME;done:#if 1 if ((type != XML_SCHEMAS_UNKNOWN) && (type != dt->type)) goto error;#else /* * insure the parsed type is equal to or less significant (right * truncated) than the desired type. */ if ((type != XML_SCHEMAS_UNKNOWN) && (type != dt->type)) { /* time only matches time */ if ((type == XML_SCHEMAS_TIME) && (dt->type == XML_SCHEMAS_TIME)) goto error; if ((type == XML_SCHEMAS_DATETIME) && ((dt->type != XML_SCHEMAS_DATE) || (dt->type != XML_SCHEMAS_GYEARMONTH) || (dt->type != XML_SCHEMAS_GYEAR))) goto error; if ((type == XML_SCHEMAS_DATE) && ((dt->type != XML_SCHEMAS_GYEAR) || (dt->type != XML_SCHEMAS_GYEARMONTH))) goto error; if ((type == XML_SCHEMAS_GYEARMONTH) && (dt->type != XML_SCHEMAS_GYEAR)) goto error; if ((type == XML_SCHEMAS_GMONTHDAY) && (dt->type != XML_SCHEMAS_GMONTH)) goto error; }#endif if (val != NULL) *val = dt; else xmlSchemaFreeValue(dt); return 0;error: if (dt != NULL) xmlSchemaFreeValue(dt); return 1;}/** * xmlSchemaValidateDuration: * @type: the predefined type * @duration: string to analyze * @val: the return computed value * * Check that @duration conforms to the lexical space of the duration type. * if true a value is computed and returned in @val. * * Returns 0 if this validates, a positive error code number otherwise * and -1 in case of internal or API error. */static intxmlSchemaValidateDuration (xmlSchemaTypePtr type ATTRIBUTE_UNUSED, const xmlChar *duration, xmlSchemaValPtr *val) { const xmlChar *cur = duration; xmlSchemaValPtr dur; int isneg = 0; unsigned int seq = 0; double num; int num_type = 0; /* -1 = invalid, 0 = int, 1 = floating */ const xmlChar desig[] = {'Y', 'M', 'D', 'H', 'M', 'S'}; const double multi[] = { 0.0, 0.0, 86400.0, 3600.0, 60.0, 1.0, 0.0}; if (duration == NULL) return -1; if (*cur == '-') { isneg = 1; cur++; } /* duration must start with 'P' (after sign) */ if (*cur++ != 'P') return 1; if (*cur == 0) return 1; dur = xmlSchemaNewValue(XML_SCHEMAS_DURATION); if (dur == NULL) return -1; while (*cur != 0) { /* input string should be empty or invalid date/time item */ if (seq >= sizeof(desig)) goto error; /* T designator must be present for time items */ if (*cur == 'T') { if (seq <= 3) { seq = 3; cur++; } else return 1; } else if (seq == 3) goto error; /* parse the number portion of the item */ PARSE_NUM(num, cur, num_type); if ((num_type == -1) || (*cur == 0)) goto error; /* update duration based on item type */ while (seq < sizeof(desig)) { if (*cur == desig[seq]) { /* verify numeric type; only seconds can be float */ if ((num_type != 0) && (seq < (sizeof(desig)-1))) goto error; switch (seq) { case 0: dur->value.dur.mon = (long)num * 12; break; case 1: dur->value.dur.mon += (long)num; break; default: /* convert to seconds using multiplier */ dur->value.dur.sec += num * multi[seq]; seq++; break; } break; /* exit loop */ } /* no date designators found? */ if (++seq == 3) goto error; } cur++; } if (isneg) { dur->value.dur.mon = -dur->value.dur.mon; dur->value.dur.day = -dur->value.dur.day; dur->value.dur.sec = -dur->value.dur.sec; } if (val != NULL) *val = dur; else xmlSchemaFreeValue(dur); return 0;error: if (dur != NULL) xmlSchemaFreeValue(dur); return 1;}/** * xmlSchemaStrip: * @value: a value * * Removes the leading and ending spaces of a string * * Returns the new string or NULL if no change was required. */static xmlChar *xmlSchemaStrip(const xmlChar *value) { const xmlChar *start = value, *end, *f; if (value == NULL) return(NULL); while ((*start != 0) && (IS_BLANK_CH(*start))) start++; end = start; while (*end != 0) end++; f = end; end--; while ((end > start) && (IS_BLANK_CH(*end))) end--; end++; if ((start == value) && (f == end)) return(NULL); return(xmlStrndup(start, end - start));}/** * xmlSchemaWhiteSpaceReplace: * @value: a value * * Replaces 0xd, 0x9 and 0xa with a space. * * Returns the new string or NULL if no change was required. */xmlChar *xmlSchemaWhiteSpaceReplace(const xmlChar *value) { const xmlChar *cur = value; xmlChar *ret = NULL, *mcur; if (value == NULL) return(NULL); while ((*cur != 0) && (((*cur) != 0xd) && ((*cur) != 0x9) && ((*cur) != 0xa))) { cur++; } if (*cur == 0) return (NULL); ret = xmlStrdup(value); /* TODO FIXME: I guess gcc will bark at this. */ mcur = (xmlChar *) (ret + (cur - value)); do { if ( ((*mcur) == 0xd) || ((*mcur) == 0x9) || ((*mcur) == 0xa) ) *mcur = ' '; mcur++; } while (*mcur != 0); return(ret);}/** * xmlSchemaCollapseString: * @value: a value * * Removes and normalize white spaces in the string * * Returns the new string or NULL if no change was required. */xmlChar *xmlSchemaCollapseString(const xmlChar *value) { const xmlChar *start = value, *end, *f; xmlChar *g; int col = 0; if (value == NULL) return(NULL); while ((*start != 0) && (IS_BLANK_CH(*start))) start++; end = start; while (*end != 0) { if ((*end == ' ') && (IS_BLANK_CH(end[1]))) { col = end - start; break; } else if ((*end == 0xa) || (*end == 0x9) || (*end == 0xd)) { col = end - start; break; } end++; } if (col == 0) { f = end; end--; while ((end > start) && (IS_BLANK_CH(*end))) end--; end++; if ((start == value) && (f == end)) return(NULL); return(xmlStrndup(start, end - start)); } start = xmlStrdup(start); if (start == NULL) return(NULL); g = (xmlChar *) (start + col); end = g; while (*end != 0) { if (IS_BLANK_CH(*end)) { end++; while (IS_BLANK_CH(*end)) end++; if (*end != 0) *g++ = ' '; } else *g++ = *end++; } *g = 0; return((xmlChar *) start);}/** * xmlSchemaValAtomicListNode: * @type: the predefined atomic type for a token in the list * @value: the list value to check * @ret: the return computed value * @node: the node containing the value * * Check that a value conforms to the lexical space of the predefined * list type. if true a value is computed and returned in @ret. * * Returns the number of items if this validates, a negative error code * number otherwise */static intxmlSchemaValAtomicListNode(xmlSchemaTypePtr type, const xmlChar *value, xmlSchemaValPtr *ret, xmlNodePtr node) { xmlChar *val, *cur, *endval; int nb_values = 0; int tmp = 0; if (value == NULL) { return(-1); } val = xmlStrdup(value); if (val == NULL) { return(-1); } if (ret != NULL) { *ret = NULL; } cur = val; /* * Split the list */ while (IS_BLANK_CH(*cur)) *cur++ = 0; while (*cur != 0) { if (IS_BLANK_CH(*cur)) { *cur = 0; cur++; while (IS_BLANK_CH(*cur)) *cur++ = 0; } else { nb_values++; cur++; while ((*cur != 0) && (!IS_BLANK_CH(*cur))) cur++; } } if (nb_values == 0) { xmlFree(val); return(nb_values); } endval = cur; cur = val; while ((*cur == 0) && (cur != endval)) cur++; while (cur != endval) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -