aboutsummaryrefslogtreecommitdiffstats
path: root/xpath.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2002-04-10 16:14:34 +0000
committerDaniel Veillard <veillard@src.gnome.org>2002-04-10 16:14:34 +0000
commit0eafdef9881c396ce4c014359d8f497cc088cfab (patch)
tree75b836b809ca66fa749c39ed466c464bcadccf5f /xpath.c
parent01917aa1cb20fb33e6fa2b1e0ca2125051e491e0 (diff)
downloadandroid_external_libxml2-0eafdef9881c396ce4c014359d8f497cc088cfab.tar.gz
android_external_libxml2-0eafdef9881c396ce4c014359d8f497cc088cfab.tar.bz2
android_external_libxml2-0eafdef9881c396ce4c014359d8f497cc088cfab.zip
another patch from Richard Jinks for substring conformance update of the
* xpath.c: another patch from Richard Jinks for substring conformance * test/XPath/expr/floats test/XPath/expr/strings result/XPath/expr/floats result/XPath/expr/strings: update of the test suite to check those. Daniel
Diffstat (limited to 'xpath.c')
-rw-r--r--xpath.c54
1 files changed, 32 insertions, 22 deletions
diff --git a/xpath.c b/xpath.c
index 9de5bc9d..ad9c3ef8 100644
--- a/xpath.c
+++ b/xpath.c
@@ -6152,34 +6152,44 @@ xmlXPathSubstringFunction(xmlXPathParserContextPtr ctxt, int nargs) {
if (nargs != 3)
le = m;
- /*
- * To meet our requirements, initial index calculations
- * must be done before we convert to integer format
- *
- * First we normalize indices
+ /* Need to check for the special cases where either
+ * the index is NaN, the length is NaN, or both
+ * arguments are infinity (relying on Inf + -Inf = NaN)
*/
- in -= 1.0;
- le += in;
- if (in < 0.0)
- in = 0.0;
- if (le > (double)m)
- le = (double)m;
+ if (!xmlXPathIsNaN(in + le)) {
+ /*
+ * To meet our requirements, initial index calculations
+ * must be done before we convert to integer format
+ *
+ * First we normalize indices
+ */
+ 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;
- if (((double)i) != in) i++;
+ /*
+ * Now we go to integer form, rounding up
+ */
+ i = (int) in;
+ if (((double)i) != in) i++;
- l = (int) le;
- if (((double)l) != le) l++;
+ l = (int) le;
+ if (((double)l) != le) l++;
+
+ if (l > m) l=m;
- if (l > m) l=m;
+ /* number of chars to copy */
+ l -= i;
- /* number of chars to copy */
- l -= i;
+ ret = xmlUTF8Strsub(str->stringval, i, l);
+ }
+ else {
+ ret = NULL;
+ }
- ret = xmlUTF8Strsub(str->stringval, i, l);
if (ret == NULL)
valuePush(ctxt, xmlXPathNewCString(""));
else {