commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang StringUtils.java
Date Wed, 10 Mar 2004 23:54:48 GMT
scolebourne    2004/03/10 15:54:48

  Modified:    lang/src/test/org/apache/commons/lang StringUtilsTest.java
               lang/src/java/org/apache/commons/lang StringUtils.java
  Log:
  Fix replaceChars() to complete bug 25454
  
  Revision  Changes    Path
  1.59      +5 -5      jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java
  
  Index: StringUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- StringUtilsTest.java	18 Feb 2004 23:06:19 -0000	1.58
  +++ StringUtilsTest.java	10 Mar 2004 23:54:48 -0000	1.59
  @@ -471,8 +471,7 @@
           assertEquals("ayzya", StringUtils.replaceChars("abcba", "bc", "yzx"));
           
           assertEquals("abcba", StringUtils.replaceChars("abcba", "z", "w"));
  -        // Comment out for now, delete later when discussion completes [Gary Gregory, Dec
14 2003]
  -        //assertSame("abcba", StringUtils.replaceChars("abcba", "z", "w"));
  +        assertSame("abcba", StringUtils.replaceChars("abcba", "z", "w"));
           
           // Javadoc examples:
           assertEquals("jelly", StringUtils.replaceChars("hello", "ho", "jy"));
  @@ -482,8 +481,9 @@
           
           // From http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25454
           assertEquals("bcc", StringUtils.replaceChars("abc", "ab", "bc"));
  -        assertEquals("q651.506bera", StringUtils.replaceChars("d216.102oren", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789",
  -                "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM567891234"));
  +        assertEquals("q651.506bera", StringUtils.replaceChars("d216.102oren",
  +            "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789",
  +            "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM567891234"));
       }
       
       public void testOverlayString_StringStringIntInt() {
  
  
  
  1.129     +11 -5     jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
  retrieving revision 1.128
  retrieving revision 1.129
  diff -u -r1.128 -r1.129
  --- StringUtils.java	24 Feb 2004 22:31:42 -0000	1.128
  +++ StringUtils.java	10 Mar 2004 23:54:48 -0000	1.129
  @@ -2675,19 +2675,25 @@
           if (replaceChars == null) {
               replaceChars = "";
           }
  -        StringBuffer buffer = new StringBuffer(str.length());
  +        boolean modified = false;
  +        StringBuffer buf = new StringBuffer(str.length());
           for (int i = 0; i < str.length(); i++) {
               char ch = str.charAt(i);
               int index = searchChars.indexOf(ch);
               if (index >= 0) {
  +                modified = true;
                   if (index < replaceChars.length()) {
  -                    buffer.append(replaceChars.charAt(index));
  +                    buf.append(replaceChars.charAt(index));
                   }
               } else {
  -                buffer.append(ch);
  +                buf.append(ch);
               }
           }
  -        return buffer.toString();
  +        if (modified) {
  +            return buf.toString();
  +        } else {
  +            return str;
  +        }
       }
   
       // Overlay
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message