cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2004-08-21 Thread bayard
bayard  2004/08/21 20:40:27

  Modified:lang/src/java/org/apache/commons/lang StringUtils.java
   lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Added the split variant from #24910 in which the separator may be a full String 
rather than a String of characters. Rather than the issues suggested boolean 
parameter, the name has been changed to splitByWholeSeparator
  
  Revision  ChangesPath
  1.134 +114 -1
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.133
  retrieving revision 1.134
  diff -u -r1.133 -r1.134
  --- StringUtils.java  15 Aug 2004 23:47:05 -  1.133
  +++ StringUtils.java  22 Aug 2004 03:40:27 -  1.134
  @@ -2060,6 +2060,119 @@
   return splitWorker(str, separatorChars, max, false);
   }
   
  +/**
  + * pSplits the provided text into an array, separator string specified./p
  + *
  + * pThe separator(s) will not be included in the returned String array.
  + * Adjacent separators are treated as one separator./p
  + *
  + * pA codenull/code input String returns codenull/code.
  + * A codenull/code separator splits on whitespace./p
  + *
  + * pre
  + * StringUtils.split(null, *)= null
  + * StringUtils.split(, *)  = []
  + * StringUtils.split(ab de fg, null)   = [ab, de, fg]
  + * StringUtils.split(ab   de fg, null) = [ab, de, fg]
  + * StringUtils.split(ab:cd:ef, :)= [ab, cd, ef]
  + * StringUtils.split(abstemiouslyaeiouyabstemiously, aeiouy)  = [bst, 
m, sl, bst, m, sl]
  + * StringUtils.split(abstemiouslyaeiouyabstemiously, aeiouy)  = 
[abstemiously, abstemiously]
  + * /pre
  + *
  + * @param str  the String to parse, may be null
  + * @param separator  String containing the String to be used as a delimiter,
  + *  codenull/code splits on whitespace
  + * @return an array of parsed Strings, codenull/code if null String was 
input
  + */
  +public static String[] splitByWholeSeparator(String str, String separator) {
  +return splitByWholeSeparator( str, separator, -1 ) ;
  +}
  +
  +/**
  + * pSplits the provided text into an array, separator string specified.
  + * Returns a maximum of codemax/code substrings./p
  + *
  + * pThe separator(s) will not be included in the returned String array.
  + * Adjacent separators are treated as one separator./p
  + *
  + * pA codenull/code input String returns codenull/code.
  + * A codenull/code separator splits on whitespace./p
  + *
  + * pre
  + * StringUtils.splitByWholeSeparator(null, *, *)   = null
  + * StringUtils.splitByWholeSeparator(, *, *) = []
  + * StringUtils.splitByWholeSeparator(ab de fg, null, 0)  = [ab, de, 
fg]
  + * StringUtils.splitByWholeSeparator(ab   de fg, null, 0)= [ab, de, 
fg]
  + * StringUtils.splitByWholeSeparator(ab:cd:ef, :, 2)   = [ab, cd]
  + * StringUtils.splitByWholeSeparator(abstemiouslyaeiouyabstemiously, 
aeiouy, 2) = [bst, m]
  + * StringUtils.splitByWholeSeparator(abstemiouslyaeiouyabstemiously, 
aeiouy, 2)  = [abstemiously, abstemiously]
  + * /pre
  + *
  + * @param str  the String to parse, may be null
  + * @param separator  String containing the String to be used as a delimiter,
  + *  codenull/code splits on whitespace
  + * @param max  the maximum number of elements to include in the returned
  + *  array. A zero or negative value implies no limit.
  + * @return an array of parsed Strings, codenull/code if null String was 
input
  + */
  +public static String[] splitByWholeSeparator( String str, String separator, int 
max ) {
  +if (str == null) {
  +return null;
  +}
  +
  +int len = str.length() ;
  +
  +if (len == 0) {
  +return ArrayUtils.EMPTY_STRING_ARRAY;
  +}
  +
  +if ( ( separator == null ) || ( .equals( separator ) ) ) {
  +// Split on whitespace.
  +return split( str, null, max ) ;
  +}
  +
  +
  +int separatorLength = separator.length() ;
  +
  +ArrayList substrings = new ArrayList() ;
  +int numberOfSubstrings = 0 ;
  +int beg = 0 ;
  +int end = 0 ;
  +while ( end  len ) {
  +end = str.indexOf( separator, beg ) ;
  +
  +if ( end  -1 ) {
  +if ( end  beg ) {
  +numberOfSubstrings += 1 ;
  +
  +if ( numberOfSubstrings == max ) {
  +end = len ;
  +substrings.add( str.substring( beg ) ) ;
  +} 

cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2004-07-11 Thread stevencaswell
stevencaswell2004/07/11 09:49:07

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  added tests for new splitPreserveAllTokens methods 
(http://issues.apache.org/bugzilla/show_bug.cgi?id=22692)
  
  Revision  ChangesPath
  1.60  +314 -1
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.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- StringUtilsTest.java  10 Mar 2004 23:54:48 -  1.59
  +++ StringUtilsTest.java  11 Jul 2004 16:49:07 -  1.60
  @@ -360,6 +360,319 @@
   assertEquals(msg, str.substring(2), res[1]);
   }
   
  +public void testSplitPreserveAllTokens_String() {
  +assertEquals(null, StringUtils.splitPreserveAllTokens(null));
  +assertEquals(0, StringUtils.splitPreserveAllTokens().length);
  +
  +String str = a b .c;
  +String[] res = StringUtils.splitPreserveAllTokens(str);
  +assertEquals(3, res.length);
  +assertEquals(a, res[0]);
  +assertEquals(b, res[1]);
  +assertEquals(.c, res[2]);
  +
  +str =  a b .c;
  +res = StringUtils.splitPreserveAllTokens(str);
  +assertEquals(4, res.length);
  +assertEquals(, res[0]);
  +assertEquals(a, res[1]);
  +assertEquals(b, res[2]);
  +assertEquals(.c, res[3]);
  +
  +str = a  b  .c;
  +res = StringUtils.splitPreserveAllTokens(str);
  +assertEquals(5, res.length);
  +assertEquals(a, res[0]);
  +assertEquals(, res[1]);
  +assertEquals(b, res[2]);
  +assertEquals(, res[3]);
  +assertEquals(.c, res[4]);
  +
  +str =  a  ;
  +res = StringUtils.splitPreserveAllTokens(str);
  +assertEquals(4, res.length);
  +assertEquals(, res[0]);
  +assertEquals(a, res[1]);
  +assertEquals(, res[2]);
  +assertEquals(, res[3]);
  +
  +str =  a  b;
  +res = StringUtils.splitPreserveAllTokens(str);
  +assertEquals(4, res.length);
  +assertEquals(, res[0]);
  +assertEquals(a, res[1]);
  +assertEquals(, res[2]);
  +assertEquals(b, res[3]);
  +
  +str = a + WHITESPACE + b + NON_WHITESPACE + c;
  +res = StringUtils.splitPreserveAllTokens(str);
  +assertEquals(WHITESPACE.length() + 1, res.length);
  +assertEquals(a, res[0]);
  +for(int i = 1; i  WHITESPACE.length()-1; i++)
  +{
  +  assertEquals(, res[i]);
  +}
  +assertEquals(b + NON_WHITESPACE + c, res[WHITESPACE.length()]); 
  
  +}
  +
  +public void testSplitPreserveAllTokens_StringChar() {
  +assertEquals(null, StringUtils.splitPreserveAllTokens(null, '.'));
  +assertEquals(0, StringUtils.splitPreserveAllTokens(, '.').length);
  +
  +String str = a.b. c;
  +String[] res = StringUtils.splitPreserveAllTokens(str, '.');
  +assertEquals(3, res.length);
  +assertEquals(a, res[0]);
  +assertEquals(b, res[1]);
  +assertEquals( c, res[2]);
  +
  +str = a.b.. c;
  +res = StringUtils.splitPreserveAllTokens(str, '.');
  +assertEquals(4, res.length);
  +assertEquals(a, res[0]);
  +assertEquals(b, res[1]);
  +assertEquals(, res[2]);
  +assertEquals( c, res[3]);
  +
  +str = .a.;
  +res = StringUtils.splitPreserveAllTokens(str, '.');
  +assertEquals(3, res.length);
  +assertEquals(, res[0]);
  +assertEquals(a, res[1]);
  +assertEquals(, res[2]);
  +   
  +str = .a..;
  +res = StringUtils.splitPreserveAllTokens(str, '.');
  +assertEquals(4, res.length);
  +assertEquals(, res[0]);
  +assertEquals(a, res[1]);
  +assertEquals(, res[2]);
  +assertEquals(, res[3]);
  +
  +str = ..a.;
  +res = StringUtils.splitPreserveAllTokens(str, '.');
  +assertEquals(4, res.length);
  +assertEquals(, res[0]);
  +assertEquals(, res[1]);
  +assertEquals(a, res[2]);
  +assertEquals(, res[3]);
  +
  +str = ..a;
  +res = StringUtils.splitPreserveAllTokens(str, '.');
  +assertEquals(3, res.length);
  +assertEquals(, res[0]);
  +assertEquals(, res[1]);
  +assertEquals(a, res[2]);
  +
  +str = a b c;
  +res = StringUtils.splitPreserveAllTokens(str,' ');
  +assertEquals(3, res.length);
  +assertEquals(a, res[0]);
  +assertEquals(b, res[1]);
  +assertEquals(c, res[2]);
  +
  +str = a  b  

cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-12-14 Thread ggregory
ggregory2003/12/14 17:52:32

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25454
  StringUtils.replaceChars(String,String,String).
  
  Revision  ChangesPath
  1.57  +17 -6 
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.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- StringUtilsTest.java  23 Nov 2003 20:44:39 -  1.56
  +++ StringUtilsTest.java  15 Dec 2003 01:52:32 -  1.57
  @@ -74,7 +74,7 @@
* @author Holger Krauth
* @author a href=[EMAIL PROTECTED]Henning P. Schmiedehausen/a
* @author Phil Steitz
  - * @author a href=mailto:[EMAIL PROTECTED]Gary Gregory/a
  + * @author Gary D. Gregory
* @author Al Chou
* @version $Id$
*/
  @@ -437,7 +437,7 @@
   assertEquals(, StringUtils.replace(foofoofoo, foo, ));
   assertEquals(barbarbar, StringUtils.replace(foofoofoo, foo, bar));
   assertEquals(farfarfar, StringUtils.replace(foofoofoo, oo, ar));
  -}
  +   }
   
   public void testReplace_StringStringStringInt() {
   assertEquals(null, StringUtils.replace(null, null, null, 2));
  @@ -480,8 +480,6 @@
   }
   
   public void testReplaceChars_StringStringString() {
  -assertEquals(jelly, StringUtils.replaceChars(hello, ho, jy));
  -
   assertEquals(null, StringUtils.replaceChars(null, null, null));
   assertEquals(null, StringUtils.replaceChars(null, , null));
   assertEquals(null, StringUtils.replaceChars(null, a, null));
  @@ -510,7 +508,20 @@
   assertEquals(ayya, StringUtils.replaceChars(abcba, bc, y));
   assertEquals(ayzya, StringUtils.replaceChars(abcba, bc, yzx));
   
  -assertSame(abcba, StringUtils.replaceChars(abcba, z, w));
  +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));
  +
  +// Javadoc examples:
  +assertEquals(jelly, StringUtils.replaceChars(hello, ho, jy));
  +assertEquals(ayzya, StringUtils.replaceChars(abcba, bc, yz));
  +assertEquals(ayya, StringUtils.replaceChars(abcba, bc, y));
  +assertEquals(ayzya, StringUtils.replaceChars(abcba, bc, yzx));
  +
  +// 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));
   }
   
   public void testOverlayString_StringStringIntInt() {
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-11-23 Thread psteitz
psteitz 2003/11/23 12:44:39

  Modified:lang/src/java/org/apache/commons/lang StringUtils.java
   lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Fixed error in javadoc for StringUtils.split and improved tests.
  Pr: 24911
  Submitted by Al Chou.
  
  Revision  ChangesPath
  1.118 +9 -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.117
  retrieving revision 1.118
  diff -u -r1.117 -r1.118
  --- StringUtils.java  4 Nov 2003 21:00:22 -   1.117
  +++ StringUtils.java  23 Nov 2003 20:44:39 -  1.118
  @@ -2087,22 +2087,26 @@
   }
   
   /**
  - * pSplits the provided text into an array, separators specified.
  - * This is an alternative to using StringTokenizer./p
  + * pSplits the provided text into an array with a maximum length, 
  + * separators specified./p
*
* pThe separator is not included in the returned String array.
* Adjacent separators are treated as one separator./p
*
* pA codenull/code input String returns codenull/code.
* A codenull/code separatorChars splits on whitespace./p
  - * 
  + *
  + * pIf more than codemax/code delimited substrings are found, the last 
  + * returned string includes all characters after the first codemax - 1/code
  + * returned strings (including separator characters)./p
  + *
* pre
* StringUtils.split(null, *, *)= null
* StringUtils.split(, *, *)  = []
* StringUtils.split(ab de fg, null, 0)   = [ab, cd, ef]
* StringUtils.split(ab   de fg, null, 0) = [ab, cd, ef]
* StringUtils.split(ab:cd:ef, :, 0)= [ab, cd, ef]
  - * StringUtils.split(ab:cd:ef, :, 2)= [ab, cdef]
  + * StringUtils.split(ab:cd:ef, :, 2)= [ab, cd:ef]
* /pre
* 
* @param str  the String to parse, may be null
  
  
  
  1.56  +20 -4 
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.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- StringUtilsTest.java  1 Nov 2003 19:20:35 -   1.55
  +++ StringUtilsTest.java  23 Nov 2003 20:44:39 -  1.56
  @@ -75,6 +75,7 @@
* @author a href=[EMAIL PROTECTED]Henning P. Schmiedehausen/a
* @author Phil Steitz
* @author a href=mailto:[EMAIL PROTECTED]Gary Gregory/a
  + * @author Al Chou
* @version $Id$
*/
   public class StringUtilsTest extends TestCase {
  @@ -280,14 +281,14 @@
   public void testSplit_String() {
   assertEquals(null, StringUtils.split(null));
   assertEquals(0, StringUtils.split().length);
  -
  +
   String str = a b  .c;
   String[] res = StringUtils.split(str);
   assertEquals(3, res.length);
   assertEquals(a, res[0]);
   assertEquals(b, res[1]);
   assertEquals(.c, res[2]);
  -
  +
   str =  a ;
   res = StringUtils.split(str);
   assertEquals(1, res.length);
  @@ -297,7 +298,7 @@
   res = StringUtils.split(str);
   assertEquals(2, res.length);
   assertEquals(a, res[0]);
  -assertEquals(b + NON_WHITESPACE + c, res[1]);
  +assertEquals(b + NON_WHITESPACE + c, res[1]);   
   }
   
   public void testSplit_StringChar() {
  @@ -339,6 +340,21 @@
   innerTestSplit(WHITESPACE.charAt(i), null, 
NON_WHITESPACE.charAt(j));
   innerTestSplit(WHITESPACE.charAt(i), 
String.valueOf(WHITESPACE.charAt(i)), NON_WHITESPACE.charAt(j));
   }
  +}
  +
  +String[] results = null;
  +String[] expectedResults = {ab, de fg};
  +results = StringUtils.split(ab   de fg, null, 2);
  +assertEquals(expectedResults.length, results.length);
  +for (int i = 0; i  expectedResults.length; i++) {
  +assertEquals(expectedResults[i], results[i]);
  +}
  +
  +String[] expectedResults2 = {ab, cd:ef};
  +results = StringUtils.split(ab:cd:ef,:, 2);
  +assertEquals(expectedResults2.length, results.length);
  +for (int i = 0; i  expectedResults2.length; i++) {
  +assertEquals(expectedResults2[i], results[i]);
   }
   }
   
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-10-28 Thread ggregory
ggregory2003/10/28 17:50:15

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Added  public static String removeStart(String str, String remove).
  
  Revision  ChangesPath
  1.53  +18 -1 
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.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- StringUtilsTest.java  21 Aug 2003 22:13:24 -  1.52
  +++ StringUtilsTest.java  29 Oct 2003 01:50:14 -  1.53
  @@ -986,5 +986,22 @@
   assertNotNull(StringUtils.EMPTY);
   assertEquals(, StringUtils.EMPTY);
   }
  +
  +public void testRemoveStart() {
  +// StringUtils.removeStart(, *)= 
  +assertNull(StringUtils.removeStart(null, null));
  +assertNull(StringUtils.removeStart(null, ));
  +assertNull(StringUtils.removeStart(null, a));
  +
  +// StringUtils.removeStart(*, null)  = *
  +assertEquals(StringUtils.removeStart(, null), );
  +assertEquals(StringUtils.removeStart(, ), );
  +assertEquals(StringUtils.removeStart(, a), );
  +
  +// All others:
  +assertEquals(StringUtils.removeStart(www.domain.com, www.), 
domain.com);
  +assertEquals(StringUtils.removeStart(domain.com, www.), domain.com);
  +assertEquals(StringUtils.removeStart(domain.com, ), domain.com);  
  
  +}
   }
   
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-10-28 Thread ggregory
ggregory2003/10/28 18:16:30

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Added  public static String removeEnd(String str, String remove).
  
  Revision  ChangesPath
  1.54  +18 -3 
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.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- StringUtilsTest.java  29 Oct 2003 01:50:14 -  1.53
  +++ StringUtilsTest.java  29 Oct 2003 02:16:30 -  1.54
  @@ -277,8 +277,6 @@
   assertEquals(foo2, StringUtils.concatenate(MIXED_TYPE_LIST));
   }
   
  -
  -
   public void testSplit_String() {
   assertEquals(null, StringUtils.split(null));
   assertEquals(0, StringUtils.split().length);
  @@ -1002,6 +1000,23 @@
   assertEquals(StringUtils.removeStart(www.domain.com, www.), 
domain.com);
   assertEquals(StringUtils.removeStart(domain.com, www.), domain.com);
   assertEquals(StringUtils.removeStart(domain.com, ), domain.com);  
  
  +}
  +
  +public void testRemoveEnd() {
  +// StringUtils.removeEnd(, *)= 
  +assertNull(StringUtils.removeEnd(null, null));
  +assertNull(StringUtils.removeEnd(null, ));
  +assertNull(StringUtils.removeEnd(null, a));
  +
  +// StringUtils.removeEnd(*, null)  = *
  +assertEquals(StringUtils.removeEnd(, null), );
  +assertEquals(StringUtils.removeEnd(, ), );
  +assertEquals(StringUtils.removeEnd(, a), );
  +
  +// All others:
  +assertEquals(StringUtils.removeEnd(www.domain.com, .com), www.domain);
  +assertEquals(StringUtils.removeEnd(www.domain, .com), www.domain);
  +assertEquals(StringUtils.removeEnd(domain.com, ), domain.com);   
   }
   }
   
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-08-14 Thread ggregory
ggregory2003/08/13 18:15:51

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  A couple more cap/uncap tests.
  
  Revision  ChangesPath
  1.48  +53 -33
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.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- StringUtilsTest.java  14 Aug 2003 00:04:20 -  1.47
  +++ StringUtilsTest.java  14 Aug 2003 01:15:51 -  1.48
  @@ -119,11 +119,11 @@
   private static final String TEXT_LIST_CHAR = foo;bar;baz;
   private static final String TEXT_LIST_NOSEP = foobarbaz;
   
  -private static final String FOO = foo;
  -private static final String BAR = bar;
  -private static final String CAP_FOO = Foo;
  +private static final String FOO_UNCAP = foo;
  +private static final String FOO_CAP = Foo;
   
  -private static final String SENTENCE = foo bar baz;
  +private static final String SENTENCE_UNCAP = foo bar baz;
  +private static final String SENTENCE_CAP = Foo Bar Baz;
   
   public StringUtilsTest(String name) {
   super(name);
  @@ -168,25 +168,45 @@
   assertEquals(null, StringUtils.uncapitalizeAllWords(null));
   
   assertEquals(capitalize(String) failed,
  - CAP_FOO, StringUtils.capitalize(FOO) );
  + FOO_CAP, StringUtils.capitalize(FOO_UNCAP) );
   assertEquals(capitalize(empty-string) failed,
, StringUtils.capitalize() );
   assertEquals(capitalize(single-char-string) failed,
X, StringUtils.capitalize(x) );
   assertEquals(capitalizeAllWords(String) failed,
  - Foo Bar Baz, StringUtils.capitalizeAllWords(SENTENCE) );
  + Foo Bar Baz, StringUtils.capitalizeAllWords(SENTENCE_UNCAP) 
);
   assertEquals(capitalizeAllWords(empty-string) failed,
, StringUtils.capitalizeAllWords() );
   assertEquals(uncapitalize(String) failed,
  - FOO, StringUtils.uncapitalize(CAP_FOO) );
  + FOO_UNCAP, StringUtils.uncapitalize(FOO_CAP) );
   assertEquals(uncapitalize(empty-string) failed,
, StringUtils.uncapitalize() );
   assertEquals(uncapitalize(single-char-string) failed,
x, StringUtils.uncapitalize(X) );
   assertEquals(uncapitalizeAllWords(String) failed,
  - SENTENCE, StringUtils.uncapitalizeAllWords(Foo Bar Baz) );
  + SENTENCE_UNCAP, StringUtils.uncapitalizeAllWords(Foo Bar 
Baz) );
   assertEquals(uncapitalizeAllWords(empty-string) failed,
, StringUtils.uncapitalizeAllWords() );
  + 
  +// reflection type of tests: Sentences.
  +assertEquals(uncapitalizeAllWords(capitalizeAllWords(String)) failed,
  + SENTENCE_UNCAP, 
StringUtils.uncapitalizeAllWords(StringUtils.capitalizeAllWords(SENTENCE_UNCAP)) );
  +assertEquals(capitalizeAllWords(uncapitalizeAllWords(String)) failed,
  + SENTENCE_CAP, 
StringUtils.capitalizeAllWords(StringUtils.uncapitalizeAllWords(SENTENCE_CAP)) );
  +assertEquals(uncapitalize(capitalize(String)) failed,
  + SENTENCE_UNCAP, 
StringUtils.uncapitalize(StringUtils.capitalize(SENTENCE_UNCAP)) );
  +assertEquals(capitalize(uncapitalize(String)) failed,
  + SENTENCE_CAP, 
StringUtils.capitalize(StringUtils.uncapitalize(SENTENCE_CAP)) );
  +
  +// reflection type of tests: One word.
  +assertEquals(uncapitalizeAllWords(capitalizeAllWords(String)) failed,
  + FOO_UNCAP, 
StringUtils.uncapitalizeAllWords(StringUtils.capitalizeAllWords(FOO_UNCAP)) );
  +assertEquals(capitalizeAllWords(uncapitalizeAllWords(String)) failed,
  + FOO_CAP, 
StringUtils.capitalizeAllWords(StringUtils.uncapitalizeAllWords(FOO_CAP)) );
  +assertEquals(uncapitalize(capitalize(String)) failed,
  +FOO_UNCAP, 
StringUtils.uncapitalize(StringUtils.capitalize(FOO_UNCAP)) );
  +assertEquals(capitalize(uncapitalize(String)) failed,
  +FOO_CAP, 
StringUtils.capitalize(StringUtils.uncapitalize(FOO_CAP)) );
   
   assertEquals(upperCase(String) failed,
FOO TEST THING, StringUtils.upperCase(fOo test THING) );
  @@ -492,7 +512,7 @@
   
   public void testOverlayString_StringStringIntInt() {
   assertEquals(overlayString(String, String, int, int) failed,
  - foo foor baz, StringUtils.overlayString(SENTENCE, FOO, 4, 6) 

cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-08-14 Thread scolebourne
scolebourne2003/08/13 16:08:06

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Remove specific reference to Assert class.
  (conforms to general style of lang test cases)
  
  Revision  ChangesPath
  1.46  +3 -4  
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.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- StringUtilsTest.java  13 Aug 2003 21:32:27 -  1.45
  +++ StringUtilsTest.java  13 Aug 2003 23:08:06 -  1.46
  @@ -58,7 +58,6 @@
   import java.util.Arrays;
   import java.util.Iterator;
   
  -import junit.framework.Assert;
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -975,8 +974,8 @@
* A sanity check for [EMAIL PROTECTED] StringUtils.EMPTY}.
*/
   public void testEMPTY() {
  -Assert.assertNotNull(StringUtils.EMPTY);
  -Assert.assertEquals(, StringUtils.EMPTY);
  +assertNotNull(StringUtils.EMPTY);
  +assertEquals(, StringUtils.EMPTY);
   }
   }
   
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-08-14 Thread bayard
bayard  2003/08/13 17:04:20

  Modified:lang/src/java/org/apache/commons/lang StringUtils.java
   lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Deprecated the 'capitalise' spelling and introduced the 'capitalize' spelling.
  Despite the UK [or international] English base of many of the developers on
  Lang, it was felt that it would be better to match Jakarta as a whole.
  
  Also none of us cared enough to make it an issue.
  
  Revision  ChangesPath
  1.94  +60 -32
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.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- StringUtils.java  13 Aug 2003 23:30:58 -  1.93
  +++ StringUtils.java  14 Aug 2003 00:04:20 -  1.94
  @@ -84,7 +84,7 @@
*  - removes the last part of a String
*  libLeftPad/RightPad/Center/Repeat/b
*  - pads a String
  - *  libUpperCase/LowerCase/SwapCase/Capitalise/Uncapitalise/b
  + *  libUpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize/b
*  - change the case of a String
*  libNestedString/b
*  - returns a substring nested within other Strings
  @@ -3410,22 +3410,22 @@
   }
   
   /**
  - * pCapitalises a String changing the first letter to title case as
  + * pCapitalizes a String changing the first letter to title case as
* per [EMAIL PROTECTED] Character#toTitleCase(char)}. No other letters are 
changed./p
* 
* pA codenull/code input String returns codenull/code./p
* 
* pre
  - * StringUtils.capitalise(null)  = null
  - * StringUtils.capitalise()= 
  - * StringUtils.capitalise(cat) = Cat
  - * StringUtils.capitalise(cAt) = CAt
  + * StringUtils.capitalize(null)  = null
  + * StringUtils.capitalize()= 
  + * StringUtils.capitalize(cat) = Cat
  + * StringUtils.capitalize(cAt) = CAt
* /pre
* 
  - * @param str  the String to capitalise, may be null
  - * @return the capitalised String, codenull/code if null String input
  + * @param str  the String to capitalize, may be null
  + * @return the capitalized String, codenull/code if null String input
*/
  -public static String capitalise(String str) {
  +public static String capitalize(String str) {
   int strLen;
   if (str == null || (strLen = str.length()) == 0) {
   return str;
  @@ -3437,22 +3437,29 @@
   }
   
   /**
  - * pUncapitalises a String changing the first letter to title case as
  + * @deprecated Use the standardly named [EMAIL PROTECTED] #capitalize(String)}.
  + */
  +public static String capitalise(String str) {
  +return capitalize(str);
  +}
  +
  +/**
  + * pUncapitalizes a String changing the first letter to title case as
* per [EMAIL PROTECTED] Character#toLowerCase(char)}. No other letters are 
changed./p
* 
* pA codenull/code input String returns codenull/code./p
* 
* pre
  - * StringUtils.uncapitalise(null)  = null
  - * StringUtils.uncapitalise()= 
  - * StringUtils.uncapitalise(Cat) = cat
  - * StringUtils.uncapitalise(CAT) = cAT
  + * StringUtils.uncapitalize(null)  = null
  + * StringUtils.uncapitalize()= 
  + * StringUtils.uncapitalize(Cat) = cat
  + * StringUtils.uncapitalize(CAT) = cAT
* /pre
* 
  - * @param str  the String to uncapitalise, may be null
  - * @return the uncapitalised String, codenull/code if null String input
  + * @param str  the String to uncapitalize, may be null
  + * @return the uncapitalized String, codenull/code if null String input
*/
  -public static String uncapitalise(String str) {
  +public static String uncapitalize(String str) {
   int strLen;
   if (str == null || (strLen = str.length()) == 0) {
   return str;
  @@ -3464,6 +3471,13 @@
   }
   
   /**
  + * @deprecated Use the standardly named [EMAIL PROTECTED] 
#uncapitalize(String)}.
  + */
  +public static String uncapitalise(String str) {
  +return uncapitalize(str);
  +}
  +
  +/**
* pSwaps the case of a String using a word based algorithm./p
* 
* ul
  @@ -3518,22 +3532,22 @@
   }
   
   /**
  - * pCapitalises all the whitespace separated words in a String.
  + * pCapitalizes all the whitespace separated words in a String.
* Only the first letter of each word is changed./p
*
* pWhitespace is defined by [EMAIL PROTECTED] Character#isWhitespace(char)}.
* A codenull/code input String returns codenull/code./p
*
* pre
  - * 

cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-08-14 Thread ggregory
ggregory2003/08/13 14:32:28

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  
  Refactor  string literals to use the new:
  public static final String EMPTY = 
  I made EMPTY public since I plan on using it when replacing most of our internal 
StringUtil class with this StringUtil.
  
  Revision  ChangesPath
  1.45  +9 -1  
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.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- StringUtilsTest.java  1 Aug 2003 23:20:06 -   1.44
  +++ StringUtilsTest.java  13 Aug 2003 21:32:27 -  1.45
  @@ -58,6 +58,7 @@
   import java.util.Arrays;
   import java.util.Iterator;
   
  +import junit.framework.Assert;
   import junit.framework.Test;
   import junit.framework.TestCase;
   import junit.framework.TestSuite;
  @@ -970,5 +971,12 @@
   }
   }
   
  +/**
  + * A sanity check for [EMAIL PROTECTED] StringUtils.EMPTY}.
  + */
  +public void testEMPTY() {
  +Assert.assertNotNull(StringUtils.EMPTY);
  +Assert.assertEquals(, StringUtils.EMPTY);
  +}
   }
   
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-07-31 Thread scolebourne
scolebourne2003/07/31 13:38:26

  Modified:lang/src/java/org/apache/commons/lang CharSetUtils.java
StringUtils.java
   lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Add  replaceChars()  to StringUtils
  Deprecate  translate()  on CharSetUtils
  
  Revision  ChangesPath
  1.17  +3 -1  
jakarta-commons/lang/src/java/org/apache/commons/lang/CharSetUtils.java
  
  Index: CharSetUtils.java
  ===
  RCS file: 
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/CharSetUtils.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- CharSetUtils.java 30 Jul 2003 22:17:00 -  1.16
  +++ CharSetUtils.java 31 Jul 2003 20:38:26 -  1.17
  @@ -345,6 +345,8 @@
* @throws NullPointerException if codewith/code or coderepl/code 
*  is codenull/code
* @throws ArrayIndexOutOfBoundsException if codewith/code is empty ()
  + * @deprecated Use [EMAIL PROTECTED] StringUtils#replaceChars(String, String, 
String)}.
  + * Method will be removed in Commons Lang 3.0.
*/
   public static String translate(String str, String searchChars, String 
replaceChars) {
   if (str == null || str.length() == 0) {
  
  
  
  1.83  +104 -1
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.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- StringUtils.java  30 Jul 2003 22:17:49 -  1.82
  +++ StringUtils.java  31 Jul 2003 20:38:26 -  1.83
  @@ -2261,6 +2261,109 @@
   buf.append(text.substring(start));
   return buf.toString();
   }
  +
  +// Replace, character based
  +//---
  +
  +/**
  + * pReplaces all occurrances of a character in a String with another.
  + * This is a null-safe version of [EMAIL PROTECTED] String#replace(char, 
char)}./p
  + *
  + * pA codenull/code string input returns codenull/code.
  + * An empty () string input returns an empty string./p
  + * 
  + * pre
  + * StringUtils.replaceChars(null, *, *)= null
  + * StringUtils.replaceChars(, *, *)  = 
  + * StringUtils.replaceChars(abcba, 'b', 'y') = aycya
  + * StringUtils.replaceChars(abcba, 'z', 'y') = abcba
  + * /pre
  + * 
  + * @param str  String to replace characters in, may be null
  + * @param searchChar  the character to search for, may be null
  + * @param replaceChar  the character to replace, may be null
  + * @return modified String, codenull/code if null string input
  + */
  +public static String replaceChars(String str, char searchChar, char 
replaceChar) {
  +if (str == null) {
  +return null;
  +}
  +return str.replace(searchChar, replaceChar);
  +}
  +
  +/**
  + * pReplaces multiple characters in a String in one go.
  + * This method can also be used to delete characters./p
  + *
  + * pFor example:br /
  + * codereplaceChars(quot;helloquot;, quot;hoquot;, quot;jyquot;) = 
jelly/code./p
  + * 
  + * pA codenull/code string input returns codenull/code.
  + * An empty () string input returns an empty string.
  + * A null or empty set of search characters returns the input string./p
  + * 
  + * pThe length of the search characters should normally equal the length
  + * of the replace characters.
  + * If the search characters is longer, then the extra search characters
  + * are deleted.
  + * If the search characters is shorter, then the extra replace characters
  + * are ignored./p
  + * 
  + * pre
  + * StringUtils.replaceChars(null, *, *)   = null
  + * StringUtils.replaceChars(, *, *) = 
  + * StringUtils.replaceChars(abc, null, *)   = abc
  + * StringUtils.replaceChars(abc, , *) = abc
  + * StringUtils.replaceChars(abc, b, null) = ac
  + * StringUtils.replaceChars(abc, b, )   = ac
  + * StringUtils.replaceChars(abcba, bc, yz)  = ayzya
  + * StringUtils.replaceChars(abcba, bc, y)   = ayya
  + * StringUtils.replaceChars(abcba, bc, yzx) = ayzya
  + * /pre
  + * 
  + * @param str  String to replace characters in, may be null
  + * @param searchChars  a set of characters to search for, may be null
  + * @param replaceChars  a set of characters to replace, may be null
  + * @return modified String, codenull/code if null string input
  + */
  +public static String replaceChars(String str, String searchChars, String 

cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-07-19 Thread scolebourne
scolebourne2003/07/19 16:28:23

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Move IndexOf and Contains tests to StringUtilsEqualsIndexOfTest
  
  Revision  ChangesPath
  1.30  +1 -126
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.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- StringUtilsTest.java  19 Jul 2003 18:10:30 -  1.29
  +++ StringUtilsTest.java  19 Jul 2003 23:28:23 -  1.30
  @@ -685,131 +685,6 @@
1, StringUtils.getLevenshteinDistance(hello, hallo) );
   }
   
  -public void testContainsOnlyString() {
  -String str1 = a;
  -String str2 = b;
  -String str3 = ab;
  -String chars1= b;
  -String chars2= a;
  -String chars3= ab;
  -String emptyChars = ;
  -assertEquals(containsOnly(null, null) failed, false, 
StringUtils.containsOnly(null, (String) null));
  -assertEquals(containsOnly(empty-string, null) failed, false, 
StringUtils.containsOnly(, (String) null));
  -assertEquals(containsOnly(null, empty-string) failed, false, 
StringUtils.containsOnly(null, emptyChars));
  -assertEquals(containsOnly(str1, empty-char-array) failed, false, 
StringUtils.containsOnly(str1, emptyChars));
  -assertEquals(containsOnly(empty-string, empty-char-array) failed, true, 
StringUtils.containsOnly(, emptyChars));
  -assertEquals(containsOnly(empty-string, chars1) failed, true, 
StringUtils.containsOnly(, chars1));
  -assertEquals(containsOnly(str1, chars1) failed, false, 
StringUtils.containsOnly(str1, chars1));
  -assertEquals(containsOnly(str1, chars2) success, true, 
StringUtils.containsOnly(str1, chars2));
  -assertEquals(containsOnly(str1, chars3) success, true, 
StringUtils.containsOnly(str1, chars3));
  -assertEquals(containsOnly(str2, chars1) success, true, 
StringUtils.containsOnly(str2, chars1));
  -assertEquals(containsOnly(str2, chars2) failed, false, 
StringUtils.containsOnly(str2, chars2));
  -assertEquals(containsOnly(str2, chars3) success, true, 
StringUtils.containsOnly(str2, chars3));
  -assertEquals(containsOnly(String3, chars1) failed, false, 
StringUtils.containsOnly(str3, chars1));
  -assertEquals(containsOnly(String3, chars2) failed, false, 
StringUtils.containsOnly(str3, chars2));
  -assertEquals(containsOnly(String3, chars3) success, true, 
StringUtils.containsOnly(str3, chars3));
  -}
  -
  -public void testContainsOnlyCharArray() {
  -String str1 = a;
  -String str2 = b;
  -String str3 = ab;
  -char[] chars1= {'b'};
  -char[] chars2= {'a'};
  -char[] chars3= {'a', 'b'};
  -char[] emptyChars = new char[0];
  -assertEquals(containsOnly(null, null) failed, false, 
StringUtils.containsOnly(null, (char[]) null));
  -assertEquals(containsOnly(empty-string, null) failed, false, 
StringUtils.containsOnly(, (char[]) null));
  -assertEquals(containsOnly(null, empty-string) failed, false, 
StringUtils.containsOnly(null, emptyChars));
  -assertEquals(containsOnly(str1, empty-char-array) failed, false, 
StringUtils.containsOnly(str1, emptyChars));
  -assertEquals(containsOnly(empty-string, empty-char-array) failed, true, 
StringUtils.containsOnly(, emptyChars));
  -assertEquals(containsOnly(empty-string, chars1) failed, true, 
StringUtils.containsOnly(, chars1));
  -assertEquals(containsOnly(str1, chars1) failed, false, 
StringUtils.containsOnly(str1, chars1));
  -assertEquals(containsOnly(str1, chars2) success, true, 
StringUtils.containsOnly(str1, chars2));
  -assertEquals(containsOnly(str1, chars3) success, true, 
StringUtils.containsOnly(str1, chars3));
  -assertEquals(containsOnly(str2, chars1) success, true, 
StringUtils.containsOnly(str2, chars1));
  -assertEquals(containsOnly(str2, chars2) failed, false, 
StringUtils.containsOnly(str2, chars2));
  -assertEquals(containsOnly(str2, chars3) success, true, 
StringUtils.containsOnly(str2, chars3));
  -assertEquals(containsOnly(String3, chars1) failed, false, 
StringUtils.containsOnly(str3, chars1));
  -assertEquals(containsOnly(String3, chars2) failed, false, 
StringUtils.containsOnly(str3, chars2));
  -assertEquals(containsOnly(String3, chars3) success, true, 
StringUtils.containsOnly(str3, chars3));
  -}
  -
  -public void testContainsNoneString() {
  -String str1 = a;
  -String str2 = b;
  -String str3 = ab.;
  -String chars1= b;
  -String chars2= .;
  -String chars3= 

cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-06-21 Thread bayard
bayard  2003/06/21 15:24:56

  Modified:lang/src/java/org/apache/commons/lang StringUtils.java
   lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Bug #20652 fixed.
  
  Submitted by: Fredrik Westermarck
  
  Revision  ChangesPath
  1.47  +4 -1  
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.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- StringUtils.java  8 Jun 2003 14:10:54 -   1.46
  +++ StringUtils.java  21 Jun 2003 22:24:55 -  1.47
  @@ -1048,6 +1048,9 @@
*/
   public static String chopNewline(String str) {
   int lastIdx = str.length() - 1;
  +if (lastIdx == 0) {
  +return ;
  +}
   char last = str.charAt(lastIdx);
   if (last == '\n') {
   if (str.charAt(lastIdx - 1) == '\r') {
  
  
  
  1.20  +22 -1 
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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- StringUtilsTest.java  16 Apr 2003 04:37:33 -  1.19
  +++ StringUtilsTest.java  21 Jun 2003 22:24:56 -  1.20
  @@ -333,6 +333,27 @@
   foo, StringUtils.chomp(foo, f));
   }
   
  +public void testChopNewLine() {
  +
  +String[][] newLineCases = {
  +{ FOO + \r\n, FOO } ,
  +{ FOO + \n , FOO } ,
  +{ FOO + \r, FOO + \r },
  +{ FOO, FOO },
  +{ FOO + \n + FOO , FOO + \n + FOO },
  +{ FOO + \n\n, FOO + \n},
  +{ \n,  },
  +{ \r\n,  }
  +  };
  +
  +  for (int i = 0; i  newLineCases.length; i++) {
  +  String original = newLineCases[i][0];
  +  String expectedResult = newLineCases[i][1];
  +  assertEquals(chopNewline(String) failed,
  +  expectedResult, StringUtils.chopNewline(original));
  +  }
  +}
  +
   public void testSliceFunctions() {
   
   String[][] sliceCases = {
  
  
  

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-03-29 Thread alex
alex2003/03/29 08:17:21

  Modified:lang/src/java/org/apache/commons/lang StringUtils.java
   lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  changed chomp() to match Perl
  deprecated chomp* methods in favor of new slice methods
  improved unit tests and documentation
  
  Revision  ChangesPath
  1.40  +162 -23   
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.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- StringUtils.java  25 Mar 2003 00:15:58 -  1.39
  +++ StringUtils.java  29 Mar 2003 16:17:21 -  1.40
  @@ -820,36 +820,72 @@
   
   // Chomping
   //--
  -
  -/** 
  - * pRemove the last newline, and everything after it from a String./p
  +
  +/**
  + * pRemove one newline from end of a String if it's there,
  + * otherwise leave it alone.  A newline is \n, \r, or \r\n.
  + * p
  + * Note that this behavior has changed from 1.0.  It
  + * now more closely matches Perl chomp.  For the previous behavior,
  + * use slice(String).
*
  - * @param str String to chomp the newline from
  - * @return String without chomped newline
  + * @param str String to chomp a newline from
  + * @return String without newline
* @throws NullPointerException if str is codenull/code
*/
   public static String chomp(String str) {
  -return chomp(str, \n);
  +if (str.length() == 0) {
  +return str;
  +}
  +
  +if (str.length() == 1) {
  +if (\r.equals(str) || \n.equals(str)) {
  +return ;
  +}
  +else {
  +return str;
  +}
  +}
  +
  +int lastIdx = str.length() - 1;
  +char last = str.charAt(lastIdx);
  +
  +if (last == '\n') {
  +if (str.charAt(lastIdx - 1) == '\r') {
  +lastIdx--;
  +}
  +} else if (last == '\r') {
  +
  +} else {
  +lastIdx++;
  +}
  +return str.substring(0, lastIdx);
   }
  -
  -/** 
  - * pRemove the last value of a supplied String, and everything after
  - * it from a String./p
  +
  +/**
  + * pRemove one string (the separator) from the end of another
  + * string if it's there, otherwise leave it alone.
  + * p
*
  - * @param str String to chomp from
  - * @param sep String to chomp
  - * @return String without chomped ending
  - * @throws NullPointerException if str or sep is codenull/code
  + * Note that this behavior has changed from 1.0.  It
  + * now more closely matches Perl chomp.  For the previous behavior,
  + * use slice(String,String).
  + *
  + * @param str string to chomp from
  + * @param separator separator string
  + * @return String without trailing separator
  + * @throws NullPointerException if str is codenull/code
*/
  -public static String chomp(String str, String sep) {
  -int idx = str.lastIndexOf(sep);
  -if (idx != -1) {
  -return str.substring(0, idx);
  -} else {
  +public static String chomp(String str, String separator) {
  +if (str.length() == 0) {
   return str;
   }
  +if (str.endsWith(separator)) {
  +return str.substring(0, str.length() - separator.length());
  +}
  +return str;
   }
  -
  +
   /**
* pRemove a newline if and only if it is at the end
* of the supplied String./p
  @@ -857,6 +893,7 @@
* @param str String to chomp from
* @return String without chomped ending
* @throws NullPointerException if str is codenull/code
  + * @deprecated use chomp(String) instead
*/
   public static String chompLast(String str) {
   return chompLast(str, \n);
  @@ -869,6 +906,7 @@
* @param sep String to chomp
* @return String without chomped ending
* @throws NullPointerException if str or sep is codenull/code
  + * @deprecated use chomp(String,String) instead
*/
   public static String chompLast(String str, String sep) {
   if (str.length() == 0) {
  @@ -884,12 +922,14 @@
   
   /** 
* pRemove everything and return the last value of a supplied String, and
  - * everything after it from a String./p
  + * everything after it from a String.
  + * [That makes no sense. Just use sliceRemainder() :-)]/p
*
* @param str String to chomp from
* @param sep String to chomp
* @return String chomped
   

Re: cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2003-03-17 Thread robert burrell donkin
hi alex

now you're a lang committer, could add your name to the STATUS.html. (see 
http://jakarta.apache.org/commons/charter.html)

- robert

On Monday, March 17, 2003, at 05:28 AM, [EMAIL PROTECTED] wrote:

alex2003/03/16 21:28:37

  Modified:lang/src/java/org/apache/commons/lang StringUtils.java
   lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Purpletech code import:  abbreviate, difference, differenceAt
  Revision  ChangesPath
  1.33  +91 -1 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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- StringUtils.java	20 Jan 2003 22:15:13 -	1.32
  +++ StringUtils.java	17 Mar 2003 05:28:36 -	1.33
  @@ -74,6 +74,7 @@
* @author Stephen Colebourne
* @author a href=mailto:[EMAIL PROTECTED]Fredrik 
Westermarck/a
* @author Holger Krauth
  + * @author a href=mailto:[EMAIL PROTECTED]Alexander Day Chaffee
/a
* @since 1.0
* @version $Id$
*/
  @@ -1744,6 +1745,95 @@
   j--;
   i++;
   }
  +}
  +
  +// Abbreviating
  +
//--
  +
  +/**
  + * Turn Now is the time for all good men into Now is the time 
for...
  + * p
  + * Specifically:
  + * p
  + * If str is less than max characters long, return it.
  + * Else abbreviate it to (substring(str, 0, max-3) + ...).
  + * If maxWidth is less than 3, throw an IllegalArgumentException.
  + * In no case will it return a string of length greater than 
maxWidth.
  + *
  + * @param maxWidth maximum length of result string
  + **/
  +public static String abbreviate(String s, int maxWidth) {
  +return abbreviate(s, 0, maxWidth);
  +}
  +
  +/**
  + * Turn Now is the time for all good men into ...is the time 
for...
  + * p
  + * Works like abbreviate(String, int), but allows you to specify a 
left edge
  + * offset.  Note that this left edge is not necessarily going to 
be the leftmost
  + * character in the result, or the first
  + * character following the ellipses, but it will appear somewhere 
in the result.
  + * In no case will it return a string of length greater than 
maxWidth.
  + *
  + * @param offset left edge of source string
  + * @param maxWidth maximum length of result string
  + **/
  +public static String abbreviate(String s, int offset, int maxWidth)
 {
  +if (maxWidth  4)
  +throw new IllegalArgumentException(Minimum abbreviation 
width is 4);
  +if (s.length() = maxWidth)
  +return s;
  +if (offset  s.length())
  +offset = s.length();
  +if ((s.length() - offset)  (maxWidth-3))
  +offset = s.length() - (maxWidth-3);
  +if (offset = 4)
  +return s.substring(0, maxWidth-3) + ...;
  +if (maxWidth  7)
  +throw new IllegalArgumentException(Minimum abbreviation 
width with offset is 7);
  +if ((offset + (maxWidth-3))  s.length())
  +return ... + abbreviate(s.substring(offset), maxWidth-3)
;
  +return ... + s.substring(s.length() - (maxWidth-3));
  +}
  +
  +// Difference
  +
//--
  +
  +/**
  + * Compare two strings, and return the portion where they differ.
  + * (More precisely, return the remainder of the second string,
  + * starting from where it's different from the first.)
  + * p
  + * E.g. strdiff(i am a machine, i am a robot) - robot
  + *
  + * @return the portion of s2 where it differs from s1; returns the 
empty string () if they are equal
  + **/
  +public static String difference(String s1, String s2) {
  +int at = differenceAt(s1, s2);
  +if (at == -1)
  +return ;
  +return s2.substring(at);
  +}
  +
  +/**
  + * Compare two strings, and return the index at which the strings 
begin to differ
  + * p
  + * E.g. strdiff(i am a machine, i am a robot) - 7
  + *
  + * @return the index where s2 and s1 begin to differ; -1 if they 
are equal
  + **/
  +public static int differenceAt(String s1, String s2)
  +{
  +int i;
  +for (i=0; is1.length()  is2.length(); ++i) {
  +if (s1.charAt(i) != s2.charAt(i)) {
  +break;
  +}
  +}
  +if (is2.length() || is1.length()) {
  +return i;
  +}
  +return -1;
   }





  1.14  +70 -1 jakarta-
commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java
  Index: 

cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2002-12-07 Thread bayard
bayard  2002/12/07 13:50:30

  Modified:lang STATUS.html
   lang/src/java/org/apache/commons/lang StringUtils.java
   lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Added the StringUtils.unescape method, UnitTest and STATUS change.
  
  Revision  ChangesPath
  1.28  +3 -2  jakarta-commons/lang/STATUS.html
  
  Index: STATUS.html
  ===
  RCS file: /home/cvs/jakarta-commons/lang/STATUS.html,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- STATUS.html   15 Nov 2002 00:07:26 -  1.27
  +++ STATUS.html   7 Dec 2002 21:50:29 -   1.28
  @@ -72,6 +72,7 @@
   ul
   liCharRange.UNSET - will have problems if we introduce reverse ranges that go 
down to \u./lI
   liNull effects - the classes are not standardised in how they handle null./li
  +liWhen running the TestFactoryUtils test, sometimes the CPU speed is not quick 
enough and 'assertEquals((double) System.currentTimeMillis(), (double) ((Date) 
created).getTime(), 0.01d);' fails. /li
   /ul
   /p
   
  @@ -90,7 +91,7 @@
   liDateRange/li
   liCloneUtils - utility class to enable cloning via various different mechanisms. 
This code exists in [pattern] at present./li
   liStringUtils truncateNicely method - A substring with some extra power to choose 
where to cut off. It was in Avalon and was added separately to String Taglib from a 
code submission. This suggests it may have some commonality. [CODED]/li
  -liStringUtils unescape method - String Taglib has shown that this method is 
missing from StringUtils. It would take a String with \n in and convert it to the 
Java character. unescape and escape should be symmetric. /li
  +liStringUtils unescape method - String Taglib has shown that this method is 
missing from StringUtils. It would take a String with \n in and convert it to the 
Java character. unescape and escape should be symmetric - [DONE. Test symmetry] /li
   liArrayUtils - opinion seems to be that this belongs with [lang] and not 
[collections]
   liGUID and other Identifier generators - these may belong in [util], some code 
exists in [pattern] at the moment
   liCharUtils - Utilities to work on a char[] in the same way as a String
  
  
  
  1.28  +74 -2 
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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- StringUtils.java  27 Nov 2002 22:54:29 -  1.27
  +++ StringUtils.java  7 Dec 2002 21:50:29 -   1.28
  @@ -55,9 +55,10 @@
*/
   
   import java.util.StringTokenizer;
  -
   import java.util.Iterator;
   
  +import org.apache.commons.lang.exception.NestableRuntimeException;
  +
   /**
* pCommon codeString/code manipulation routines./p
*
  @@ -952,6 +953,77 @@
   break;
   }
   }
  +}
  +return buffer.toString();
  +}
  +
  +/**
  + * Unescapes any Java literals found in the String. For example, 
  + * it will turn a sequence of '\' and 'n' into a newline character, 
  + * unless the '\' is preceded by another '\'.
  + */
  +public static String unescape(String str) {
  +int sz = str.length();
  +StringBuffer buffer = new StringBuffer(sz);
  +StringBuffer unicode = new StringBuffer(4);
  +boolean hadSlash = false;
  +boolean inUnicode = false;
  +for (int i = 0; i  sz; i++) {
  +char ch = str.charAt(i);
  +if(inUnicode) {
  +// if in unicode, then we're reading unicode 
  +// values in somehow
  +if(unicode.length() == 4) {
  +// unicode now contains the four hex digits 
  +// which represents our unicode chacater
  +try {
  +int value = Integer.parseInt(unicode.toString(), 16);
  +buffer.append( (char)value );
  +unicode.setLength(0);
  +unicode.setLength(4);
  +inUnicode = false;
  +hadSlash = false;
  +} catch(NumberFormatException nfe) {
  +throw new NestableRuntimeException(Unable to parse unicode 
value: +unicode, nfe);
  +}
  +} else {
  +unicode.append(ch);
  +continue;
  +}
  +}
  +if(hadSlash) {
  +// handle an escaped value
  +hadSlash = false;
  +switch(ch) {
  +case '\\': 

cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2002-11-22 Thread bayard
bayard  2002/11/22 16:41:19

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Added unit test to detect bug # 14062.
  
  Revision  ChangesPath
  1.9   +6 -1  
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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- StringUtilsTest.java  22 Nov 2002 23:33:34 -  1.8
  +++ StringUtilsTest.java  23 Nov 2002 00:41:19 -  1.9
  @@ -186,6 +186,11 @@
   assertEquals(split(Object[], String, int) failed, expected[i],
result[i]);
   }
  +
  +result = StringUtils.split(one two three four five six, null, 2);
  +assertEquals(split(Object[], null, int)[0] failed, one, result[0]);
  +assertEquals(split(Object[], null, int)[1] failed, two, result[1]);
  +assertEquals(split(Object[], null, int)[2] failed, three four five six, 
result[2]);
   }
   
   public void testReplaceFunctions()
  
  
  

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2002-11-22 Thread bayard
bayard  2002/11/22 16:51:34

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  So my test was wrong. I was using the split method wrongly.
  
  Revision  ChangesPath
  1.10  +2 -2  
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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- StringUtilsTest.java  23 Nov 2002 00:41:19 -  1.9
  +++ StringUtilsTest.java  23 Nov 2002 00:51:34 -  1.10
  @@ -187,7 +187,7 @@
result[i]);
   }
   
  -result = StringUtils.split(one two three four five six, null, 2);
  +result = StringUtils.split(one two three four five six, null, 3);
   assertEquals(split(Object[], null, int)[0] failed, one, result[0]);
   assertEquals(split(Object[], null, int)[1] failed, two, result[1]);
   assertEquals(split(Object[], null, int)[2] failed, three four five six, 
result[2]);
  
  
  

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java

2002-11-07 Thread bayard
bayard  2002/11/07 13:52:44

  Modified:lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Removed unused UPPER_FOO variable.
  
  Revision  ChangesPath
  1.7   +1 -2  
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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StringUtilsTest.java  28 Oct 2002 04:33:29 -  1.6
  +++ StringUtilsTest.java  7 Nov 2002 21:52:44 -   1.7
   -81,7 +81,6 
   private static final String FOO = foo;
   private static final String BAR = bar;
   private static final String CAP_FOO = Foo;
  -private static final String UPPER_FOO = FOO;
   
   private static final String SENTENCE = foo bar baz;
   
  
  
  

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