[kaffe] CVS kaffe (robilad): fix for debian bug 357427

Kaffe CVS cvs-commits at kaffe.org
Thu Mar 23 13:26:09 PST 2006


PatchSet 7164 
Date: 2006/03/23 20:48:57
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
fix for debian bug 357427

2006-03-23  Dalibor Topic  <robilad at kaffe.org>

        Fix for Debian bug #357427

        * libraries/javalib/vmspecific/java/lang/String.java
        (replace, offsetByCodePoints): Merged in from GNU Classpath's
        String implementation.

Members: 
	ChangeLog:1.4682->1.4683 
	libraries/javalib/vmspecific/java/lang/String.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4682 kaffe/ChangeLog:1.4683
--- kaffe/ChangeLog:1.4682	Thu Mar 23 20:00:08 2006
+++ kaffe/ChangeLog	Thu Mar 23 20:48:57 2006
@@ -5,6 +5,14 @@
 
 2006-03-23  Dalibor Topic  <robilad at kaffe.org>
 
+	Fix for Debian bug #357427
+
+	* libraries/javalib/vmspecific/java/lang/String.java 
+	(replace, offsetByCodePoints): Merged in from GNU Classpath's 
+	String implementation.
+
+2006-03-23  Dalibor Topic  <robilad at kaffe.org>
+
 	* README, WHATSNEW: Added information about Blackfin support.
 
 2006-03-23  Kang Shuo  <blackfin.kang at gmail.com>
Index: kaffe/libraries/javalib/vmspecific/java/lang/String.java
diff -u kaffe/libraries/javalib/vmspecific/java/lang/String.java:1.2 kaffe/libraries/javalib/vmspecific/java/lang/String.java:1.3
--- kaffe/libraries/javalib/vmspecific/java/lang/String.java:1.2	Sat Nov 26 20:30:30 2005
+++ kaffe/libraries/javalib/vmspecific/java/lang/String.java	Thu Mar 23 20:49:08 2006
@@ -977,4 +977,57 @@
   {
     return this.indexOf(s.toString()) != -1;
   }
+
+  /**
+   * Returns a string that is this string with all instances of the sequence
+   * represented by <code>target</code> replaced by the sequence in 
+   * <code>replacement</code>.
+   * @param target the sequence to be replaced
+   * @param replacement the sequence used as the replacement
+   * @return the string constructed as above
+   */
+  public String replace (CharSequence target, CharSequence replacement)
+  {
+    String targetString = target.toString();
+    String replaceString = replacement.toString();
+    int targetLength = target.length();
+    int replaceLength = replacement.length();
+    
+    int startPos = this.indexOf(targetString);
+    StringBuilder result = new StringBuilder(this);    
+    while (startPos != -1)
+      {
+        // Replace the target with the replacement
+        result.replace(startPos, startPos + targetLength, replaceString);
+
+        // Search for a new occurrence of the target
+        startPos = result.indexOf(targetString, startPos + replaceLength);
+      }
+    return result.toString();
+  }
+  
+  /**
+   * Return the index into this String that is offset from the given index by 
+   * <code>codePointOffset</code> code points.
+   * @param index the index at which to start
+   * @param codePointOffset the number of code points to offset
+   * @return the index into this String that is <code>codePointOffset</code>
+   * code points offset from <code>index</code>.
+   * 
+   * @throws IndexOutOfBoundsException if index is negative or larger than the
+   * length of this string.
+   * @throws IndexOutOfBoundsException if codePointOffset is positive and the
+   * substring starting with index has fewer than codePointOffset code points.
+   * @throws IndexOutOfBoundsException if codePointOffset is negative and the
+   * substring ending with index has fewer than (-codePointOffset) code points.
+   * @since 1.5
+   */
+  public int offsetByCodePoints(int index, int codePointOffset)
+  {
+    if (index < 0 || index > count)
+      throw new IndexOutOfBoundsException();
+    
+    return Character.offsetByCodePoints(value, offset, count, offset + index,
+                                        codePointOffset);
+  }
 }




More information about the kaffe mailing list