classpathx-xml
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Classpathx-xml] Patch for substring function


From: Julian Scheid
Subject: [Classpathx-xml] Patch for substring function
Date: Sat, 27 Nov 2004 14:52:24 +0100
User-agent: Mozilla Thunderbird 0.8 (X11/20040913)

This fixes a bug in substring() which would copy one character short if the length is specified explicitly.

Julian
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);
   }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]