Patch for substring function

Julian Scheid <[email protected]>
Newsgroups gmane.comp.java.classpath.extensions.xml
Message-ID <[email protected]>
This fixes a bug in substring() which would copy one character short if 
the length is specified explicitly.

Julian

_______________________________________________
Classpathx-xml mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpathx-xml
gnujaxp-substring.patch (text/x-patch, 1.3 KB)
Index: source/gnu/xml/xpath/SubstringFunction.java
===================================================================
RCS file: /cvsroot/classpathx/jaxp/source/gnu/xml/xpath/SubstringFunction.java,v
retrieving revision 1.2
diff -u -r1.2 SubstringFunction.java
--- source/gnu/xml/xpath/SubstringFunction.java	19 Nov 2004 21:53:16 -0000	1.2
+++ source/gnu/xml/xpath/SubstringFunction.java	27 Nov 2004 13:34:34 -0000
@@ -75,28 +75,26 @@
     int p = (val2 instanceof Double) ?
       ((Double) val2).intValue() :
         (int) Math.round(_number(context, val2));
-    int l = s.length() + 1;
-    if (arg3 != null)
-      {
-        Object val3 = arg3.evaluate(context, pos, len);
-        l = (val3 instanceof Double) ?
-          ((Double) val3).intValue() :
-            (int) Math.round(_number(context, val3));
-      }
     p--;
-    l--;
     if (p < 0)
       {
         p = 0;
       }
-    if (l > s.length())
-      {
-        l = s.length();
-      }
-    if (l < 0)
+
+    int l = s.length() - p;
+
+    if (arg3 != null)
       {
-        l = 0;
+        Object val3 = arg3.evaluate(context, pos, len);
+        int v3 = (val3 instanceof Double) ?
+          ((Double) val3).intValue() :
+            (int) Math.round(_number(context, val3));
+        if (v3 < l) 
+          {
+            l = v3;
+          }
       }
+
     return s.substring(p, p + l);
   }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.