mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
patch from Richard Jinks for XPath substring() function new set of tests
* xpath.c: patch from Richard Jinks for XPath substring() function * result/XPath/expr/strings test/XPath/expr/strings: new set of tests Daniel
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
Mon Jun 10 18:00:02 CEST 2002 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* xpath.c: patch from Richard Jinks for XPath substring() function
|
||||||
|
* result/XPath/expr/strings test/XPath/expr/strings: new set of tests
|
||||||
|
|
||||||
2002-06-06 Aleksey Sanin <set EMAIL_ADDRESS environment variable>
|
2002-06-06 Aleksey Sanin <set EMAIL_ADDRESS environment variable>
|
||||||
|
|
||||||
* xmlIO.c: patch from Rachel Hestilow to fix bug #84340
|
* xmlIO.c: patch from Rachel Hestilow to fix bug #84340
|
||||||
|
@ -822,6 +822,9 @@ void xmlDocDumpFormatMemoryEnc(xmlDocPtr out_doc,
|
|||||||
int * doc_txt_len,
|
int * doc_txt_len,
|
||||||
const char *txt_encoding,
|
const char *txt_encoding,
|
||||||
int format);
|
int format);
|
||||||
|
int xmlDocFormatDump(FILE *f,
|
||||||
|
xmlDocPtr cur,
|
||||||
|
int format);
|
||||||
int xmlDocDump (FILE *f,
|
int xmlDocDump (FILE *f,
|
||||||
xmlDocPtr cur);
|
xmlDocPtr cur);
|
||||||
void xmlElemDump (FILE *f,
|
void xmlElemDump (FILE *f,
|
||||||
|
@ -67,28 +67,64 @@ Object is a string : 234
|
|||||||
Expression: substring("12345",2)
|
Expression: substring("12345",2)
|
||||||
Object is a string : 2345
|
Object is a string : 2345
|
||||||
|
|
||||||
|
========================
|
||||||
|
Expression: substring("12345",-4)
|
||||||
|
Object is a string : 12345
|
||||||
|
|
||||||
|
========================
|
||||||
|
Expression: substring("12345",3.4)
|
||||||
|
Object is a string : 345
|
||||||
|
|
||||||
|
========================
|
||||||
|
Expression: substring("12345",3.6)
|
||||||
|
Object is a string : 45
|
||||||
|
|
||||||
========================
|
========================
|
||||||
Expression: substring("12345",1.5,2.6)
|
Expression: substring("12345",1.5,2.6)
|
||||||
Object is a string : 234
|
Object is a string : 234
|
||||||
|
|
||||||
|
========================
|
||||||
|
Expression: substring("12345",2.2,2.2)
|
||||||
|
Object is a string : 23
|
||||||
|
|
||||||
========================
|
========================
|
||||||
Expression: substring("12345",0,3)
|
Expression: substring("12345",0,3)
|
||||||
Object is a string : 12
|
Object is a string : 12
|
||||||
|
|
||||||
========================
|
========================
|
||||||
Expression: substring("12345", 0 div 0, 3)
|
Expression: substring("12345",-8,10)
|
||||||
|
Object is a string : 1
|
||||||
|
|
||||||
|
========================
|
||||||
|
Expression: substring("12345",4,-10)
|
||||||
Object is a string :
|
Object is a string :
|
||||||
|
|
||||||
========================
|
========================
|
||||||
Expression: substring("12345", 1, 0 div 0)
|
Expression: substring("12345",0 div 0, 3)
|
||||||
Object is a string :
|
Object is a string :
|
||||||
|
|
||||||
========================
|
========================
|
||||||
Expression: substring("12345", -42, 1 div 0)
|
Expression: substring("12345",1, 0 div 0)
|
||||||
|
Object is a string :
|
||||||
|
|
||||||
|
========================
|
||||||
|
Expression: substring("12345",1 div 0, 3)
|
||||||
|
Object is a string :
|
||||||
|
|
||||||
|
========================
|
||||||
|
Expression: substring("12345",3,-1 div 0)
|
||||||
|
Object is a string :
|
||||||
|
|
||||||
|
========================
|
||||||
|
Expression: substring("12345",-42, 1 div 0)
|
||||||
Object is a string : 12345
|
Object is a string : 12345
|
||||||
|
|
||||||
========================
|
========================
|
||||||
Expression: substring("12345", -1 div 0, 1 div 0)
|
Expression: substring("12345",-1 div 0, 1 div 0)
|
||||||
|
Object is a string :
|
||||||
|
|
||||||
|
========================
|
||||||
|
Expression: substring("12345",-1 div 0,5)
|
||||||
Object is a string :
|
Object is a string :
|
||||||
|
|
||||||
========================
|
========================
|
||||||
|
@ -15,11 +15,20 @@ contains("tititototata","tata")
|
|||||||
contains("tititototata","tita")
|
contains("tititototata","tita")
|
||||||
substring("12345",2,3)
|
substring("12345",2,3)
|
||||||
substring("12345",2)
|
substring("12345",2)
|
||||||
|
substring("12345",-4)
|
||||||
|
substring("12345",3.4)
|
||||||
|
substring("12345",3.6)
|
||||||
substring("12345",1.5,2.6)
|
substring("12345",1.5,2.6)
|
||||||
|
substring("12345",2.2,2.2)
|
||||||
substring("12345",0,3)
|
substring("12345",0,3)
|
||||||
substring("12345", 0 div 0, 3)
|
substring("12345",-8,10)
|
||||||
substring("12345", 1, 0 div 0)
|
substring("12345",4,-10)
|
||||||
substring("12345", -42, 1 div 0)
|
substring("12345",0 div 0, 3)
|
||||||
substring("12345", -1 div 0, 1 div 0)
|
substring("12345",1, 0 div 0)
|
||||||
|
substring("12345",1 div 0, 3)
|
||||||
|
substring("12345",3,-1 div 0)
|
||||||
|
substring("12345",-42, 1 div 0)
|
||||||
|
substring("12345",-1 div 0, 1 div 0)
|
||||||
|
substring("12345",-1 div 0,5)
|
||||||
string-length("")
|
string-length("")
|
||||||
string-length("titi")
|
string-length("titi")
|
||||||
|
21
tree.c
21
tree.c
@ -6986,16 +6986,17 @@ xmlSetCompressMode(int mode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlDocDump:
|
* xmlDocFormatDump:
|
||||||
* @f: the FILE*
|
* @f: the FILE*
|
||||||
* @cur: the document
|
* @cur: the document
|
||||||
|
* @format: should formatting spaces been added
|
||||||
*
|
*
|
||||||
* Dump an XML document to an open FILE.
|
* Dump an XML document to an open FILE.
|
||||||
*
|
*
|
||||||
* returns: the number of bytes written or -1 in case of failure.
|
* returns: the number of bytes written or -1 in case of failure.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
xmlDocDump(FILE *f, xmlDocPtr cur) {
|
xmlDocFormatDump(FILE *f, xmlDocPtr cur, int format) {
|
||||||
xmlOutputBufferPtr buf;
|
xmlOutputBufferPtr buf;
|
||||||
const char * encoding;
|
const char * encoding;
|
||||||
xmlCharEncodingHandlerPtr handler = NULL;
|
xmlCharEncodingHandlerPtr handler = NULL;
|
||||||
@ -7030,12 +7031,26 @@ xmlDocDump(FILE *f, xmlDocPtr cur) {
|
|||||||
}
|
}
|
||||||
buf = xmlOutputBufferCreateFile(f, handler);
|
buf = xmlOutputBufferCreateFile(f, handler);
|
||||||
if (buf == NULL) return(-1);
|
if (buf == NULL) return(-1);
|
||||||
xmlDocContentDumpOutput(buf, cur, NULL, 0);
|
xmlDocContentDumpOutput(buf, cur, NULL, format);
|
||||||
|
|
||||||
ret = xmlOutputBufferClose(buf);
|
ret = xmlOutputBufferClose(buf);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xmlDocDump:
|
||||||
|
* @f: the FILE*
|
||||||
|
* @cur: the document
|
||||||
|
*
|
||||||
|
* Dump an XML document to an open FILE.
|
||||||
|
*
|
||||||
|
* returns: the number of bytes written or -1 in case of failure.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
xmlDocDump(FILE *f, xmlDocPtr cur) {
|
||||||
|
return(xmlDocFormatDump (f, cur, 0));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlSaveFileTo:
|
* xmlSaveFileTo:
|
||||||
* @buf: an output I/O buffer
|
* @buf: an output I/O buffer
|
||||||
|
4
xmlIO.c
4
xmlIO.c
@ -143,6 +143,7 @@ xmlCleanupInputCallbacks(void)
|
|||||||
xmlInputCallbackTable[i].readcallback = NULL;
|
xmlInputCallbackTable[i].readcallback = NULL;
|
||||||
xmlInputCallbackTable[i].closecallback = NULL;
|
xmlInputCallbackTable[i].closecallback = NULL;
|
||||||
}
|
}
|
||||||
|
xmlInputCallbackInitialized = 0;
|
||||||
|
|
||||||
xmlInputCallbackNr = 0;
|
xmlInputCallbackNr = 0;
|
||||||
xmlInputCallbackInitialized = 0;
|
xmlInputCallbackInitialized = 0;
|
||||||
@ -168,6 +169,7 @@ xmlCleanupOutputCallbacks(void)
|
|||||||
xmlOutputCallbackTable[i].writecallback = NULL;
|
xmlOutputCallbackTable[i].writecallback = NULL;
|
||||||
xmlOutputCallbackTable[i].closecallback = NULL;
|
xmlOutputCallbackTable[i].closecallback = NULL;
|
||||||
}
|
}
|
||||||
|
xmlOutputCallbackInitialized = 0;
|
||||||
|
|
||||||
xmlOutputCallbackNr = 0;
|
xmlOutputCallbackNr = 0;
|
||||||
xmlOutputCallbackInitialized = 0;
|
xmlOutputCallbackInitialized = 0;
|
||||||
@ -2116,7 +2118,7 @@ xmlParserInputBufferGrow(xmlParserInputBufferPtr in, int len) {
|
|||||||
int res = 0;
|
int res = 0;
|
||||||
int nbchars = 0;
|
int nbchars = 0;
|
||||||
int buffree;
|
int buffree;
|
||||||
int needSize;
|
unsigned int needSize;
|
||||||
|
|
||||||
if ((len <= MINLEN) && (len != 4))
|
if ((len <= MINLEN) && (len != 4))
|
||||||
len = MINLEN;
|
len = MINLEN;
|
||||||
|
50
xpath.c
50
xpath.c
@ -6162,37 +6162,47 @@ xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs) {
|
|||||||
/*
|
/*
|
||||||
* If last pos not present, calculate last position
|
* If last pos not present, calculate last position
|
||||||
*/
|
*/
|
||||||
if (nargs != 3)
|
if (nargs != 3) {
|
||||||
le = m;
|
le = (double)m;
|
||||||
|
if (in < 1.0)
|
||||||
|
in = 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Need to check for the special cases where either
|
/* Need to check for the special cases where either
|
||||||
* the index is NaN, the length is NaN, or both
|
* the index is NaN, the length is NaN, or both
|
||||||
* arguments are infinity (relying on Inf + -Inf = NaN)
|
* arguments are infinity (relying on Inf + -Inf = NaN)
|
||||||
*/
|
*/
|
||||||
if (!xmlXPathIsNaN(in + le)) {
|
if (!xmlXPathIsNaN(in + le) && !xmlXPathIsInf(in)) {
|
||||||
/*
|
/*
|
||||||
* To meet our requirements, initial index calculations
|
* To meet the requirements of the spec, the arguments
|
||||||
* must be done before we convert to integer format
|
* must be converted to integer format before
|
||||||
|
* initial index calculations are done
|
||||||
*
|
*
|
||||||
* First we normalize indices
|
* First we go to integer form, rounding up
|
||||||
*/
|
* and checking for special cases
|
||||||
in -= 1.0;
|
|
||||||
le += in;
|
|
||||||
if (in < 0.0)
|
|
||||||
in = 0.0;
|
|
||||||
if (le > (double)m)
|
|
||||||
le = (double)m;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Now we go to integer form, rounding up
|
|
||||||
*/
|
*/
|
||||||
i = (int) in;
|
i = (int) in;
|
||||||
if (((double)i) != in) i++;
|
if (((double)i)+0.5 <= in) i++;
|
||||||
|
|
||||||
l = (int) le;
|
if (xmlXPathIsInf(le) == 1) {
|
||||||
if (((double)l) != le) l++;
|
l = m;
|
||||||
|
if (i < 1)
|
||||||
|
i = 1;
|
||||||
|
}
|
||||||
|
else if (xmlXPathIsInf(le) == -1 || le < 0.0)
|
||||||
|
l = 0;
|
||||||
|
else {
|
||||||
|
l = (int) le;
|
||||||
|
if (((double)l)+0.5 <= le) l++;
|
||||||
|
}
|
||||||
|
|
||||||
if (l > m) l=m;
|
/* Now we normalize inidices */
|
||||||
|
i -= 1;
|
||||||
|
l += i;
|
||||||
|
if (i < 0)
|
||||||
|
i = 0;
|
||||||
|
if (l > m)
|
||||||
|
l = m;
|
||||||
|
|
||||||
/* number of chars to copy */
|
/* number of chars to copy */
|
||||||
l -= i;
|
l -= i;
|
||||||
|
Reference in New Issue
Block a user