commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject cvs commit: jakarta-commons/lang/src/java/org/apache/commons/lang StringUtils.java
Date Wed, 13 Aug 2003 21:32:10 GMT
ggregory    2003/08/13 14:32:10

  Modified:    lang/src/java/org/apache/commons/lang StringUtils.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  Changes    Path
  1.92      +29 -24    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.91
  retrieving revision 1.92
  diff -u -r1.91 -r1.92
  --- StringUtils.java	1 Aug 2003 23:58:30 -0000	1.91
  +++ StringUtils.java	13 Aug 2003 21:32:10 -0000	1.92
  @@ -164,6 +164,11 @@
       // (not sure who tested this)
       
       /**
  +     * The empty String <code>""</code>.
  +     */
  +    public static final String EMPTY = "";
  +    
  +    /**
        * <p>The maximum size to which the padding constant(s) can expand.</p>
        */
       private static final int PAD_LIMIT = 8192;
  @@ -310,7 +315,7 @@
        *             Method will be removed in Commons Lang 3.0.
        */
       public static String clean(String str) {
  -        return (str == null ? "" : str.trim());
  +        return (str == null ? EMPTY : str.trim());
       }
   
       /**
  @@ -387,7 +392,7 @@
        * @return the trimmed String, or an empty String if <code>null</code>
input
        */
       public static String trimToEmpty(String str) {
  -        return (str == null ? "" : str.trim());
  +        return (str == null ? EMPTY : str.trim());
       }
       
       // Stripping
  @@ -470,7 +475,7 @@
        * @return the trimmed String, or an empty String if <code>null</code>
input
        */
       public static String stripToEmpty(String str) {
  -        return (str == null ? "" : strip(str, null));
  +        return (str == null ? EMPTY : strip(str, null));
       }
       
       /**
  @@ -1423,7 +1428,7 @@
               start = 0;
           }
           if (start > str.length()) {
  -            return "";
  +            return EMPTY;
           }
   
           return str.substring(start);
  @@ -1484,7 +1489,7 @@
   
           // if start is greater than end, return ""
           if (start > end) {
  -            return "";
  +            return EMPTY;
           }
   
           if (start < 0) {
  @@ -1524,7 +1529,7 @@
               return null;
           }
           if (len < 0) {
  -            return "";
  +            return EMPTY;
           }
           if (str.length() <= len) {
               return str;
  @@ -1558,7 +1563,7 @@
               return null;
           }
           if (len < 0) {
  -            return "";
  +            return EMPTY;
           }
           if (str.length() <= len) {
               return str;
  @@ -1596,7 +1601,7 @@
               return null;
           }
           if (len < 0 || pos > str.length()) {
  -            return "";
  +            return EMPTY;
           }
           if (pos < 0) {
               pos = 0;
  @@ -1639,7 +1644,7 @@
               return str;
           }
           if (separator.length() == 0) {
  -            return "";
  +            return EMPTY;
           }
           int pos = str.indexOf(separator);
           if (pos == -1) {
  @@ -1678,11 +1683,11 @@
               return str;
           }
           if (separator == null) {
  -            return "";
  +            return EMPTY;
           }
           int pos = str.indexOf(separator);
           if (pos == -1) {
  -            return "";
  +            return EMPTY;
           }
           return str.substring(pos + separator.length());
       }
  @@ -1753,11 +1758,11 @@
               return str;
           }
           if (separator == null || separator.length() == 0) {
  -            return "";
  +            return EMPTY;
           }
           int pos = str.lastIndexOf(separator);
           if (pos == -1 || pos == (str.length() - separator.length())) {
  -            return "";
  +            return EMPTY;
           }
           return str.substring(pos + separator.length());
       }
  @@ -2210,7 +2215,7 @@
               return null;
           }
           if (separator == null) {
  -            separator = "";
  +            separator = EMPTY;
           }
           int arraySize = array.length;
   
  @@ -2624,7 +2629,7 @@
               return null;
           }
           if (overlay == null) {
  -            overlay = "";
  +            overlay = EMPTY;
           }
           int len = str.length();
           if (start < 0) {
  @@ -2686,7 +2691,7 @@
           if (str.length() == 1) {
               char ch = str.charAt(0);
               if (ch == '\r' || ch == '\n') {
  -                return "";
  +                return EMPTY;
               } else {
                   return str;
               }
  @@ -2798,7 +2803,7 @@
           } else if (idx != -1) {
               return str.substring(idx);
           } else {
  -            return "";
  +            return EMPTY;
           }
       }
   
  @@ -2839,7 +2844,7 @@
           if (idx != -1) {
               return str.substring(0, idx + sep.length());
           } else {
  -            return "";
  +            return EMPTY;
           }
       }
   
  @@ -2874,7 +2879,7 @@
           }
           int strLen = str.length();
           if (strLen < 2) {
  -            return "";
  +            return EMPTY;
           }
           int lastIdx = strLen - 1;
           String ret = str.substring(0, lastIdx);
  @@ -2900,7 +2905,7 @@
       public static String chopNewline(String str) {
           int lastIdx = str.length() - 1;
           if (lastIdx <= 0) {
  -            return "";
  +            return EMPTY;
           }
           char last = str.charAt(lastIdx);
           if (last == '\n') {
  @@ -2963,7 +2968,7 @@
               return null;
           }
           if (repeat <= 0) {
  -            return "";
  +            return EMPTY;
           }
           int inputLength = str.length();
           if (repeat == 1 || inputLength == 0) {
  @@ -3877,7 +3882,7 @@
        *  was <code>null</code>
        */
       public static String defaultString(String str) {
  -        return (str == null ? "" : str);
  +        return (str == null ? EMPTY : str);
       }
   
       /**
  @@ -4121,7 +4126,7 @@
           }
           int at = differenceAt(str1, str2);
           if (at == -1) {
  -            return "";
  +            return EMPTY;
           }
           return str2.substring(at);
       }
  
  
  

Mime
View raw message