aboutsummaryrefslogtreecommitdiffstats
path: root/xmlschemastypes.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2003-02-06 08:22:32 +0000
committerDaniel Veillard <veillard@src.gnome.org>2003-02-06 08:22:32 +0000
commit96a4b2524590c4c8fe776dfcbf4574737f6206b6 (patch)
tree5ee9cf9cb941b8464a0b50f2963cc9e13ddf697b /xmlschemastypes.c
parent72fef16e5c05224a81425b2ada12f4147b5194be (diff)
downloadandroid_external_libxml2-96a4b2524590c4c8fe776dfcbf4574737f6206b6.tar.gz
android_external_libxml2-96a4b2524590c4c8fe776dfcbf4574737f6206b6.tar.bz2
android_external_libxml2-96a4b2524590c4c8fe776dfcbf4574737f6206b6.zip
started implementing some of the missing default simple types updated the
* xmlschemastypes.c: started implementing some of the missing default simple types * result/relaxng/*: updated the results Daniel
Diffstat (limited to 'xmlschemastypes.c')
-rw-r--r--xmlschemastypes.c316
1 files changed, 303 insertions, 13 deletions
diff --git a/xmlschemastypes.c b/xmlschemastypes.c
index f7fc9823..aff3e575 100644
--- a/xmlschemastypes.c
+++ b/xmlschemastypes.c
@@ -18,6 +18,8 @@
#include <libxml/parserInternals.h>
#include <libxml/hash.h>
#include <libxml/valid.h>
+#include <libxml/xpath.h>
+#include <libxml/uri.h>
#include <libxml/xmlschemas.h>
#include <libxml/schemasInternals.h>
@@ -53,6 +55,7 @@ typedef enum {
XML_SCHEMAS_DURATION,
XML_SCHEMAS_FLOAT,
XML_SCHEMAS_DOUBLE,
+ XML_SCHEMAS_INT,
XML_SCHEMAS_,
XML_SCHEMAS_XXX
} xmlSchemaValType;
@@ -129,6 +132,7 @@ static xmlSchemaTypePtr xmlSchemaTypeDurationDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeNmtoken = NULL;
static xmlSchemaTypePtr xmlSchemaTypeFloatDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeDoubleDef = NULL;
+static xmlSchemaTypePtr xmlSchemaTypeNameDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeQNameDef = NULL;
static xmlSchemaTypePtr xmlSchemaTypeAnyURIDef = NULL;
@@ -205,6 +209,7 @@ xmlSchemaInitTypes(void) {
xmlSchemaTypeNmtoken = xmlSchemaInitBasicType("NMTOKEN");
xmlSchemaTypeFloatDef = xmlSchemaInitBasicType("float");
xmlSchemaTypeDoubleDef = xmlSchemaInitBasicType("double");
+ xmlSchemaTypeNameDef = xmlSchemaInitBasicType("Name");
xmlSchemaTypeQNameDef = xmlSchemaInitBasicType("QName");
xmlSchemaTypeAnyURIDef = xmlSchemaInitBasicType("anyURI");
@@ -965,6 +970,137 @@ error:
return 1;
}
+
+/**
+ * xmlSchemaValidateNCName:
+ * @value: the value to check
+ *
+ * Check that a value conforms to the lexical space of NCName
+ *
+ * Returns 0 if this validates, a positive error code number otherwise
+ * and -1 in case of internal or API error.
+ */
+static int
+xmlSchemaValidateNCName(const xmlChar *value) {
+ const xmlChar *cur = value;
+
+ /*
+ * First quick algorithm for ASCII range
+ */
+ while (IS_BLANK(*cur)) cur++;
+ if (((*cur >= 'a') && (*cur <= 'z')) || ((*cur >= 'A') && (*cur <= 'Z')) ||
+ (*cur == '_'))
+ cur++;
+ else
+ goto try_complex;
+ while (((*cur >= 'a') && (*cur <= 'z')) ||
+ ((*cur >= 'A') && (*cur <= 'Z')) ||
+ ((*cur >= '0') && (*cur <= '9')) ||
+ (*cur == '_') || (*cur == '-') || (*cur == '.'))
+ cur++;
+ while (IS_BLANK(*cur)) cur++;
+ if (*cur == 0)
+ return(0);
+
+try_complex:
+ /*
+ * Second check for chars outside the ASCII range
+ */
+ TODO
+ return(0);
+}
+
+/**
+ * xmlSchemaValidateQName:
+ * @value: the value to check
+ *
+ * Check that a value conforms to the lexical space of QName
+ *
+ * Returns 0 if this validates, a positive error code number otherwise
+ * and -1 in case of internal or API error.
+ */
+static int
+xmlSchemaValidateQName(const xmlChar *value) {
+ const xmlChar *cur = value;
+
+ /*
+ * First quick algorithm for ASCII range
+ */
+ while (IS_BLANK(*cur)) cur++;
+ if (((*cur >= 'a') && (*cur <= 'z')) || ((*cur >= 'A') && (*cur <= 'Z')) ||
+ (*cur == '_'))
+ cur++;
+ else
+ goto try_complex;
+ while (((*cur >= 'a') && (*cur <= 'z')) ||
+ ((*cur >= 'A') && (*cur <= 'Z')) ||
+ ((*cur >= '0') && (*cur <= '9')) ||
+ (*cur == '_') || (*cur == '-') || (*cur == '.'))
+ cur++;
+ if (*cur == ':') {
+ cur++;
+ if (((*cur >= 'a') && (*cur <= 'z')) ||
+ ((*cur >= 'A') && (*cur <= 'Z')) ||
+ (*cur == '_'))
+ cur++;
+ else
+ goto try_complex;
+ while (((*cur >= 'a') && (*cur <= 'z')) ||
+ ((*cur >= 'A') && (*cur <= 'Z')) ||
+ ((*cur >= '0') && (*cur <= '9')) ||
+ (*cur == '_') || (*cur == '-') || (*cur == '.'))
+ cur++;
+ }
+ while (IS_BLANK(*cur)) cur++;
+ if (*cur == 0)
+ return(0);
+
+try_complex:
+ /*
+ * Second check for chars outside the ASCII range
+ */
+ TODO
+ return(0);
+}
+
+/**
+ * xmlSchemaValidateName:
+ * @value: the value to check
+ *
+ * Check that a value conforms to the lexical space of Name
+ *
+ * Returns 0 if this validates, a positive error code number otherwise
+ * and -1 in case of internal or API error.
+ */
+static int
+xmlSchemaValidateName(const xmlChar *value) {
+ const xmlChar *cur = value;
+
+ /*
+ * First quick algorithm for ASCII range
+ */
+ while (IS_BLANK(*cur)) cur++;
+ if (((*cur >= 'a') && (*cur <= 'z')) || ((*cur >= 'A') && (*cur <= 'Z')) ||
+ (*cur == '_') || (*cur == ':'))
+ cur++;
+ else
+ goto try_complex;
+ while (((*cur >= 'a') && (*cur <= 'z')) ||
+ ((*cur >= 'A') && (*cur <= 'Z')) ||
+ ((*cur >= '0') && (*cur <= '9')) ||
+ (*cur == '_') || (*cur == '-') || (*cur == '.') || (*cur == ':'))
+ cur++;
+ while (IS_BLANK(*cur)) cur++;
+ if (*cur == 0)
+ return(0);
+
+try_complex:
+ /*
+ * Second check for chars outside the ASCII range
+ */
+ TODO
+ return(0);
+}
/**
* xmlSchemaValidatePredefinedType:
* @type: the predefined type
@@ -981,6 +1117,7 @@ int
xmlSchemaValidatePredefinedType(xmlSchemaTypePtr type, const xmlChar *value,
xmlSchemaValPtr *val) {
xmlSchemaValPtr v;
+ int ret;
if (xmlSchemaTypesInitialized == 0)
return(-1);
@@ -1108,42 +1245,195 @@ xmlSchemaValidatePredefinedType(xmlSchemaTypePtr type, const xmlChar *value,
}
}
return(0);
- } else if (type == xmlSchemaTypeFloatDef) {
- const xmlChar *cur = value, *tmp;
- int frac = 0, len, neg = 0;
+ } else if (type == xmlSchemaTypeIntDef) {
+ const xmlChar *cur = value;
unsigned long base = 0;
+ int total = 0;
+ int sign = 0;
if (cur == NULL)
return(1);
+ if (*cur == '-') {
+ sign = 1;
+ cur++;
+ } else if (*cur == '+')
+ cur++;
+ while (*cur == '0') {
+ total++;
+ cur++;
+ }
+ while ((*cur >= '0') && (*cur <= '9')) {
+ base = base * 10 + (*cur - '0');
+ total++;
+ cur++;
+ }
+ if (*cur != 0)
+ return(1);
+ if ((sign == 1) && (total == 0))
+ return(1);
+ if (val != NULL) {
+ v = xmlSchemaNewValue(XML_SCHEMAS_INT);
+ if (v != NULL) {
+ v->value.decimal.base = base;
+ v->value.decimal.sign = sign;
+ v->value.decimal.frac = 0;
+ v->value.decimal.total = total;
+ *val = v;
+ }
+ }
+ return(0);
+ } else if ((type == xmlSchemaTypeFloatDef) ||
+ (type == xmlSchemaTypeDoubleDef)) {
+ const xmlChar *cur = value;
+ int neg = 0;
+ if (cur == NULL)
+ return(1);
+ if ((cur[0] == 'N') && (cur[1] == 'a') && (cur[2] == 'N')) {
+ cur += 3;
+ if (*cur != 0)
+ return(1);
+ if (val != NULL) {
+ if (type == xmlSchemaTypeFloatDef) {
+ v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT);
+ if (v != NULL) {
+ v->value.f = (float) xmlXPathNAN;
+ } else {
+ xmlSchemaFreeValue(v);
+ return(-1);
+ }
+ } else {
+ v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE);
+ if (v != NULL) {
+ v->value.d = xmlXPathNAN;
+ } else {
+ xmlSchemaFreeValue(v);
+ return(-1);
+ }
+ }
+ *val = v;
+ }
+ return(0);
+ }
if (*cur == '+')
cur++;
else if (*cur == '-') {
neg = 1;
cur++;
}
- tmp = cur;
+ if ((cur[0] == 'I') && (cur[1] == 'N') && (cur[2] == 'F')) {
+ cur += 3;
+ if (*cur != 0)
+ return(1);
+ 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);
+ return(-1);
+ }
+ } else {
+ v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE);
+ if (v != NULL) {
+ if (neg)
+ v->value.d = xmlXPathNINF;
+ else
+ v->value.d = xmlXPathPINF;
+ } else {
+ xmlSchemaFreeValue(v);
+ return(-1);
+ }
+ }
+ *val = v;
+ }
+ return(0);
+ }
while ((*cur >= '0') && (*cur <= '9')) {
- base = base * 10 + (*cur - '0');
cur++;
}
- len = cur - tmp;
if (*cur == '.') {
cur++;
- tmp = cur;
- while ((*cur >= '0') && (*cur <= '9')) {
- base = base * 10 + (*cur - '0');
+ while ((*cur >= '0') && (*cur <= '9'))
+ cur++;
+ }
+ if ((*cur == 'e') || (*cur == 'E')) {
+ cur++;
+ if (*cur == '-')
+ cur++;
+ while ((*cur >= '0') && (*cur <= '9'))
cur++;
+ }
+ if (*cur != 0)
+ return(1);
+ if (val != NULL) {
+ if (type == xmlSchemaTypeFloatDef) {
+ v = xmlSchemaNewValue(XML_SCHEMAS_FLOAT);
+ if (v != NULL) {
+ if (sscanf((const char *)value, "%f", &(v->value.f))==1) {
+ *val = v;
+ } else {
+ xmlGenericError(xmlGenericErrorContext,
+ "failed to scanf float %s\n", value);
+ xmlSchemaFreeValue(v);
+ return(1);
+ }
+ } else {
+ return(-1);
+ }
+ } else {
+ v = xmlSchemaNewValue(XML_SCHEMAS_DOUBLE);
+ if (v != NULL) {
+ if (sscanf((const char *)value, "%lf", &(v->value.d))==1) {
+ *val = v;
+ } else {
+ xmlGenericError(xmlGenericErrorContext,
+ "failed to scanf double %s\n", value);
+ xmlSchemaFreeValue(v);
+ return(1);
+ }
+ } else {
+ return(-1);
+ }
}
- frac = cur - tmp;
}
- TODO
return(0);
- } else if (type == xmlSchemaTypeDoubleDef) {
- TODO
+ } else if (type == xmlSchemaTypeNameDef) {
+ ret = xmlSchemaValidateName(value);
+ if ((ret == 0) && (val != NULL)) {
+ TODO;
+ }
+ return(ret);
+ } else if (type == xmlSchemaTypeQNameDef) {
+ ret = xmlSchemaValidateQName(value);
+ if ((ret == 0) && (val != NULL)) {
+ TODO;
+ }
+ return(ret);
+ } else if (type == xmlSchemaTypeNCNameDef) {
+ ret = xmlSchemaValidateNCName(value);
+ if ((ret == 0) && (val != NULL)) {
+ TODO;
+ }
+ return(ret);
+ } else if (type == xmlSchemaTypeAnyURIDef) {
+ xmlURIPtr uri;
+
+ uri = xmlParseURI((const char *) value);
+ if (uri == NULL)
+ return(1);
+ if (val != NULL) {
+ TODO;
+ }
+ xmlFreeURI(uri);
return(0);
} else {
TODO
return(0);
}
+ return(-1);
}
/**