You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2004/04/29 02:17:25 UTC

cvs commit: cocoon-2.1/src/java/org/apache/cocoon/util StringUtils.java

joerg       2004/04/28 17:17:25

  Modified:    src/java/org/apache/cocoon/util StringUtils.java
  Log:
  reverted the move to o.a.commons.lang.StringUtils for split() as it behaves differently;
  for the other methods restored the implementations and only point out the deprecation - we should test if here is another behaviour too
  
  Revision  Changes    Path
  1.4       +21 -9     cocoon-2.1/src/java/org/apache/cocoon/util/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/util/StringUtils.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringUtils.java	28 Mar 2004 14:28:04 -0000	1.3
  +++ StringUtils.java	29 Apr 2004 00:17:25 -0000	1.4
  @@ -31,7 +31,7 @@
        * @return An array of whitespace-separated tokens
        */
       public static String[] split(String line) {
  -        return org.apache.commons.lang.StringUtils.split(line, " \t\n\r");
  +        return split(line, " \t\n\r");
       }
   
       /**
  @@ -40,11 +40,9 @@
        * @param line The string to be split
        * @param delimiter A string containing token separators
        * @return An array of token
  -     * @deprecated Use org.apache.commons.lang.StringUtils.split() instead
        */
       public static String[] split(String line, String delimiter) {
  -        return org.apache.commons.lang.StringUtils.split(line, delimiter);
  -        //return Tokenizer.tokenize(line, delimiter, false);
  +        return Tokenizer.tokenize(line, delimiter, false);
       }
   
       /**
  @@ -67,10 +65,15 @@
        * @param str The string to be tested
        * @param c the char to be counted
        * @return the occurrence of the character in the string.
  -     * @deprecated Use org.apache.commons.lang.StringUtils.countMatches
  +     * @deprecated Use {@link org.apache.commons.lang.StringUtils#countMatches(String, String)}
        */
       public static int count(String str, char c) {
  -        return org.apache.commons.lang.StringUtils.countMatches(str, String.valueOf(c));
  +        int index = 0;
  +        char[] chars = str.toCharArray();
  +        for (int i = 0; i < chars.length; i++) {
  +            if (chars[i] == c) index++;
  +        }
  +        return index;
       }
   
       /**
  @@ -79,10 +82,19 @@
        * @param a The first string
        * @param b The second string
        * @return the index where the two strings stop matching starting from 0
  -     * @deprecated Use org.apache.commons.lang.StringUtils.indexOfDifference()
  +     * @deprecated Use {@link org.apache.commons.lang.StringUtils#indexOfDifference(String, String)}
        */
       public static int matchStrings(String a, String b) {
  -        return org.apache.commons.lang.StringUtils.indexOfDifference(a, b);
  +        int i;
  +        char[] ca = a.toCharArray();
  +        char[] cb = b.toCharArray();
  +        int len = ( ca.length < cb.length ) ? ca.length : cb.length;
  +
  +        for (i = 0; i < len; i++) {
  +            if (ca[i] != cb[i]) break;
  +        }
  +
  +        return i;
       }
   
       /**