Commit 8d73bcb5 authored by Daniel Veillard's avatar Daniel Veillard

added a new API to split a QName without generating any memory allocation

* tree.c include/libxml/tree.h: added a new API to split a
  QName without generating any memory allocation
* valid.c: fixed another problem with namespaces on element
  in mixed content case
* python/tests/reader2.py: updated the testcase with
  Bjorn Reese fix to reader for unsignificant white space
* parser.c HTMLparser.c: cleanup.
Daniel
parent 5ee43b06
Sun Aug 3 21:02:30 EDT 2003 Daniel Veillard <daniel@veillard.com>
* tree.c include/libxml/tree.h: added a new API to split a
QName without generating any memory allocation
* valid.c: fixed another problem with namespaces on element
in mixed content case
* python/tests/reader2.py: updated the testcase with
Bjorn Reese fix to reader for unsignificant white space
* parser.c HTMLparser.c: cleanup.
Sun Aug 3 20:55:40 EDT 2003 Daniel Veillard <daniel@veillard.com>
* catalog.c: trying to fix #118754 of possible recursion in the
......
......@@ -4331,7 +4331,7 @@ htmlCreateDocParserCtxt(xmlChar *cur, const char *encoding ATTRIBUTE_UNUSED) {
*/
static int
htmlParseLookupSequence(htmlParserCtxtPtr ctxt, xmlChar first,
xmlChar next, xmlChar third, int comment) {
xmlChar next, xmlChar third, int comment) {
int base, len;
htmlParserInputPtr in;
const xmlChar *buf;
......
......@@ -556,6 +556,9 @@ xmlChar * xmlBuildQName (const xmlChar *ncname,
int len);
xmlChar * xmlSplitQName2 (const xmlChar *name,
xmlChar **prefix);
const xmlChar * xmlSplitQName3 (const xmlChar *name,
int *len);
/*
* Handling Buffers.
*/
......
......@@ -1789,7 +1789,7 @@ xmlSplitQName(xmlParserCtxtPtr ctxt, const xmlChar *name, xmlChar **prefix) {
c = *cur;
*prefix = ret;
if (c == 0) {
return(xmlStrndup("", 0));
return(xmlStrndup(BAD_CAST "", 0));
}
len = 0;
......
......@@ -63,17 +63,17 @@ s = """
"""
expect="""10,test
1,test
3,#text
14,#text
1,x
1,c
3,#text
15,c
15,x
3,#text
14,#text
1,b
3,#text
15,b
3,#text
14,#text
15,test
"""
res=""
......@@ -113,11 +113,11 @@ s = """<!DOCTYPE test [
tst_ent = """<x>hello</x>"""
expect="""10 test
1 test
3 #text
14 #text
1 x
3 #text
15 x
3 #text
14 #text
15 test
"""
res=""
......@@ -165,19 +165,19 @@ s = """<!DOCTYPE test [
</test>"""
expect="""10 test 0
1 test 0
3 #text 1
14 #text 1
1 x 1
1 y 2
3 #text 3
15 y 2
15 x 1
3 #text 1
14 #text 1
1 x 1
1 y 2
3 #text 3
15 y 2
15 x 1
3 #text 1
14 #text 1
15 test 0
"""
res=""
......@@ -218,11 +218,11 @@ s = """<!DOCTYPE test [
</test>"""
expect="""10 test 0
1 test 0
3 #text 1
14 #text 1
5 x 1
3 #text 1
14 #text 1
5 x 1
3 #text 1
14 #text 1
15 test 0
"""
res=""
......
......@@ -236,6 +236,43 @@ xmlSplitQName2(const xmlChar *name, xmlChar **prefix) {
return(ret);
}
/**
* xmlSplitQName3:
* @name: the full QName
* @len: an int *
*
* parse an XML qualified name string,i
*
* returns NULL if it is not a Qualified Name, otherwise, update len
* with the lenght in byte of the prefix and return a pointer
*/
const xmlChar *
xmlSplitQName3(const xmlChar *name, int *len) {
int l = 0;
if (name == NULL) return(NULL);
if (len == NULL) return(NULL);
/* nasty but valid */
if (name[0] == ':')
return(NULL);
/*
* we are not trying to validate but just to cut, and yes it will
* work even if this is as set of UTF-8 encoded chars
*/
while ((name[l] != 0) && (name[l] != ':'))
l++;
if (name[l] == 0)
return(NULL);
*len = l;
return(&name[l+1]);
}
/************************************************************************
* *
* Check Name, NCName and QName strings *
......
......@@ -5059,24 +5059,55 @@ done:
static int
xmlValidateCheckMixed(xmlValidCtxtPtr ctxt ATTRIBUTE_UNUSED,
xmlElementContentPtr cont, const xmlChar *qname) {
while (cont != NULL) {
if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) {
if (xmlStrEqual(cont->name, qname))
return(1);
} else if ((cont->type == XML_ELEMENT_CONTENT_OR) &&
(cont->c1 != NULL) &&
(cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){
if (xmlStrEqual(cont->c1->name, qname))
return(1);
} else if ((cont->type != XML_ELEMENT_CONTENT_OR) ||
(cont->c1 == NULL) ||
(cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){
/* Internal error !!! */
xmlGenericError(xmlGenericErrorContext,
"Internal: MIXED struct bad\n");
break;
const xmlChar *name;
int plen;
name = xmlSplitQName3(qname, &plen);
if (name == NULL) {
while (cont != NULL) {
if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) {
if ((cont->prefix == NULL) && (xmlStrEqual(cont->name, qname)))
return(1);
} else if ((cont->type == XML_ELEMENT_CONTENT_OR) &&
(cont->c1 != NULL) &&
(cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){
if ((cont->c1->prefix == NULL) &&
(xmlStrEqual(cont->c1->name, qname)))
return(1);
} else if ((cont->type != XML_ELEMENT_CONTENT_OR) ||
(cont->c1 == NULL) ||
(cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){
/* Internal error !!! */
xmlGenericError(xmlGenericErrorContext,
"Internal: MIXED struct bad\n");
break;
}
cont = cont->c2;
}
} else {
while (cont != NULL) {
if (cont->type == XML_ELEMENT_CONTENT_ELEMENT) {
if ((cont->prefix != NULL) &&
(xmlStrncmp(cont->prefix, qname, plen) == 0) &&
(xmlStrEqual(cont->name, name)))
return(1);
} else if ((cont->type == XML_ELEMENT_CONTENT_OR) &&
(cont->c1 != NULL) &&
(cont->c1->type == XML_ELEMENT_CONTENT_ELEMENT)){
if ((cont->c1->prefix != NULL) &&
(xmlStrncmp(cont->c1->prefix, qname, plen) == 0) &&
(xmlStrEqual(cont->c1->name, name)))
return(1);
} else if ((cont->type != XML_ELEMENT_CONTENT_OR) ||
(cont->c1 == NULL) ||
(cont->c1->type != XML_ELEMENT_CONTENT_PCDATA)){
/* Internal error !!! */
xmlGenericError(xmlGenericErrorContext,
"Internal: MIXED struct bad\n");
break;
}
cont = cont->c2;
}
cont = cont->c2;
}
return(0);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment