com.limegroup.gnutella.util
Class StringUtils

java.lang.Object
  extended bycom.limegroup.gnutella.util.StringUtils

public class StringUtils
extends java.lang.Object

Various static routines for manipulating strings.


Constructor Summary
StringUtils()
           
 
Method Summary
static int compareIgnoreCase(java.lang.String s1, java.lang.String s2)
          Exactly the same as s1.compareToIgnoreCase(s2), which unfortunately doesn't exist in Java 1.1.8.
static boolean contains(java.lang.String input, java.lang.String pattern)
          Returns true if input contains the given pattern, which may contain the wildcard character '*'.
static boolean contains(java.lang.String input, java.lang.String pattern, boolean ignoreCase)
          Exactly like contains(input, pattern), but case is ignored if ignoreCase==true.
static java.lang.String getEntriesAsString(java.util.Collection collection)
          Returns the entries in the set in a string form, that can be used in HTTP headers (among other purposes)
static java.util.Set getSetofValues(java.lang.String values)
          Returns the entries passed in the string form as a Set fo strings
static java.lang.String replace(java.lang.String str, java.lang.String old_str, java.lang.String new_str)
          Replaces all occurrences of old_str in str with new_str
static java.lang.String[] split(java.lang.String s, char delimeter)
          Exactly like split(s, Character.toString(delimeter))
static java.lang.String[] split(java.lang.String s, java.lang.String delimeters)
          Returns the tokens of s delimited by the given delimeter, without returning the delimeter.
static java.lang.String[] splitNoCoalesce(java.lang.String s, char delimeter)
          Exactly like splitNoCoalesce(s, Character.toString(delimeter))
static java.lang.String[] splitNoCoalesce(java.lang.String s, java.lang.String delimeters)
          Similar to split(s, delimeters) except that subsequent delimeters are not coalesced, so the returned array may contain empty strings.
static boolean startsWithIgnoreCase(java.lang.String s, java.lang.String prefix)
          Returns true iff s starts with prefix, ignoring case.
static char toOtherCase(char c)
          If c is a lower case ASCII character, returns Character.toUpperCase(c).
static java.lang.String truncate(java.lang.String string, int maxLen)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

contains

public static final boolean contains(java.lang.String input,
                                     java.lang.String pattern)
Returns true if input contains the given pattern, which may contain the wildcard character '*'. TODO: need more formal definition. Examples:
  StringUtils.contains("", "") ==> true
  StringUtils.contains("abc", "") ==> true
  StringUtils.contains("abc", "b") ==> true
  StringUtils.contains("abc", "d") ==> false
  StringUtils.contains("abcd", "a*d") ==> true
  StringUtils.contains("abcd", "*a**d*") ==> true
  StringUtils.contains("abcd", "d*a") ==> false
  


contains

public static final boolean contains(java.lang.String input,
                                     java.lang.String pattern,
                                     boolean ignoreCase)
Exactly like contains(input, pattern), but case is ignored if ignoreCase==true.


toOtherCase

public static final char toOtherCase(char c)
If c is a lower case ASCII character, returns Character.toUpperCase(c). Else if c is an upper case ASCII character, returns Character.toLowerCase(c), Else returns c. Note that this is not internationalized; but it is fast.


split

public static java.lang.String[] split(java.lang.String s,
                                       char delimeter)
Exactly like split(s, Character.toString(delimeter))


split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String delimeters)
Returns the tokens of s delimited by the given delimeter, without returning the delimeter. Repeated sequences of delimeters are treated as one. Examples:
    split("a//b/ c /","/")=={"a","b"," c "}
    split("a b", "/")=={"a b"}.
    split("///", "/")=={}.
  
Note that whitespace is preserved if it is not part of the delimeter. An older version of this trim()'ed each token of whitespace.


splitNoCoalesce

public static java.lang.String[] splitNoCoalesce(java.lang.String s,
                                                 char delimeter)
Exactly like splitNoCoalesce(s, Character.toString(delimeter))


splitNoCoalesce

public static java.lang.String[] splitNoCoalesce(java.lang.String s,
                                                 java.lang.String delimeters)
Similar to split(s, delimeters) except that subsequent delimeters are not coalesced, so the returned array may contain empty strings. If s starts (ends) with a delimeter, the returned array starts (ends) with an empty strings. If s contains N delimeters, N+1 strings are always returned. Examples:
    split("a//b/ c /","/")=={"a","","b"," c ", ""}
    split("a b", "/")=={"a b"}.
    split("///", "/")=={"","","",""}.
  

Returns:
an array A s.t. s.equals(A[0]+d0+A[1]+d1+...+A[N]), where for all dI, dI.size()==1 && delimeters.indexOf(dI)>=0; and for all c in A[i], delimeters.indexOf(c)<0

compareIgnoreCase

public static int compareIgnoreCase(java.lang.String s1,
                                    java.lang.String s2)
Exactly the same as s1.compareToIgnoreCase(s2), which unfortunately doesn't exist in Java 1.1.8.


startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String s,
                                           java.lang.String prefix)
Returns true iff s starts with prefix, ignoring case.

Returns:
true iff s.toUpperCase().startsWith(prefix.toUpperCase())

getEntriesAsString

public static java.lang.String getEntriesAsString(java.util.Collection collection)
Returns the entries in the set in a string form, that can be used in HTTP headers (among other purposes)

Returns:
the entries in the set in a string form. e.g. For a collection with entries ("a", "b"), the string returned will be "a,b"

getSetofValues

public static java.util.Set getSetofValues(java.lang.String values)
Returns the entries passed in the string form as a Set fo strings

Parameters:
values - The string representation of entries to be split. The entries in the string are separated by Constants.ENTRY_SEPARATOR
Returns:
the entries in the set form. e.g. For string "a,b", the Set returned will have 2 entries: "a" & "b"

replace

public static java.lang.String replace(java.lang.String str,
                                       java.lang.String old_str,
                                       java.lang.String new_str)
Replaces all occurrences of old_str in str with new_str

Parameters:
str - the String to modify
old_str - the String to be replaced
new_str - the String to replace old_str with
Returns:
the modified str.

truncate

public static java.lang.String truncate(java.lang.String string,
                                        int maxLen)