org.objectweb.jac.util
Class Strings

java.lang.Object
  extended byorg.objectweb.jac.util.Strings

public class Strings
extends Object

Various often used string functions


Constructor Summary
Strings()
           
 
Method Summary
static String createPathString(Collection paths)
          Create a path string, using the appropriate path separator
static void deleteChars(String delChars, StringBuffer s)
          Delete occurences of characters from a StringBuffer
static boolean equalsUSAsciiNoCase(String a, String b)
          Compares the USAscii representation of two strings in a case insensitive manner.
static String fromISO8859_1(String s)
          Convert a String to a string with onlu iso-8859-1 characters.
static String getShortClassName(Class cl)
           
static String getShortClassName(String className)
           
static String hash(Object o)
           
static String hex(Object o)
          Build a String representation of an object of the form <classname>@<hashcode>
static boolean isEmpty(String str)
          Tells if a string is empty (is null, has a zero length, or contains only whitespaces)
static String join(Collection items, String separator)
          Builds a string formed by the toString() of items from a collection separated by a separator string.
static String join(String[] items, String separator)
           
static String newString(char c, int length)
          Build a string with a given length and all the characters equals.
static String replace(String oldChars, char newChar, String s)
          Replaces all occurences of some characters by a character
static void replace(String oldChars, char newChar, StringBuffer s)
          Replaces all occurences of some characters by a character
static String replace(String orgString, String oldString, String newString)
          A useful method that replaces all the occurences of a string.
static String safeJoin(Collection items, String separator)
          Builds a string formed by the toString() of items from a collection separated by a separator string.
static String slashify(String str)
          The reverse of unslashify. slashify(unslashify(str)).equals(str).
static String[] split(String source, String separator)
          Split a string into an array
static String[] splitPath(String paths)
          Split a list of paths separated by path.separator
static List splitToList(String source, String separator)
          Split a string into a list of strings
static String toISO8599_1(String s)
          Convert a String to a string with onlu iso-8859-1 characters.
static void toLowerCase(StringBuffer s)
          Lowers all characters of a StringBuffer
static String toString(Collection list)
          Build a String representation of a vector in the way as Vector.toString(), but without brackets.
static String toString(Map map)
           
static void toUpperCase(StringBuffer s)
          Uppers all characters of a StringBuffer
static String toUSAscii(String s)
           
static void toUSAscii(StringBuffer s)
          Replace accented chars with their non-accented value.
static String trimWSAndCRLF(String str)
          Removes all whitespace and CR/LF characters at the beginning or at the end of a string.
static String unslashify(String str)
          Replace slashed characters ("\t" -> '\t',"\r" -> '\t', "\n" -> '\n' ,"\f" -> '\f' , "\_" -> ' ')
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

public Strings()
Method Detail

unslashify

public static String unslashify(String str)
Replace slashed characters ("\t" -> '\t',"\r" -> '\t', "\n" -> '\n' ,"\f" -> '\f' , "\_" -> ' ')

See Also:
slashify(String)

slashify

public static String slashify(String str)
The reverse of unslashify. slashify(unslashify(str)).equals(str).

See Also:
unslashify(String)

split

public static String[] split(String source,
                             String separator)
Split a string into an array

Parameters:
source - string to split
separator - the separator
Returns:
an array of strings
See Also:
splitToList(String,String)

splitToList

public static List splitToList(String source,
                               String separator)
Split a string into a list of strings

Parameters:
source - string to split
separator - the separator
Returns:
a list of strings
See Also:
split(String,String)

join

public static String join(Collection items,
                          String separator)
Builds a string formed by the toString() of items from a collection separated by a separator string.

Parameters:
items - the collection. It must not contain null values
separator - the separator string
See Also:
join(String[],String)

safeJoin

public static String safeJoin(Collection items,
                              String separator)
Builds a string formed by the toString() of items from a collection separated by a separator string.

Parameters:
items - the collection. It may contain null values.
separator - the separator string
See Also:
join(String[],String)

join

public static String join(String[] items,
                          String separator)
See Also:
join(Collection,String)

splitPath

public static String[] splitPath(String paths)
Split a list of paths separated by path.separator

Returns:
an array of path

createPathString

public static String createPathString(Collection paths)
Create a path string, using the appropriate path separator

Parameters:
paths - a collection of File
Returns:
the filenames of paths, separated by the appropriate path separator

hex

public static String hex(Object o)
Build a String representation of an object of the form <classname>@<hashcode>

Parameters:
o - the object to stringify
Returns:
a String representation of the object

hash

public static String hash(Object o)

toString

public static String toString(Collection list)
Build a String representation of a vector in the way as Vector.toString(), but without brackets.

Parameters:
list - the vector to stringify
Returns:
a String representation of the vector

toString

public static String toString(Map map)

newString

public static String newString(char c,
                               int length)
Build a string with a given length and all the characters equals.

Parameters:
c - the character to fill the string with
length - the length of the string
Returns:
a string with the required length where string.charAt(i)==c for all i between 0 and lenght-1.

replace

public static String replace(String orgString,
                             String oldString,
                             String newString)
A useful method that replaces all the occurences of a string.

Parameters:
orgString - the original string
oldString - the string to replace (if found) in the original string
newString - the string that replaces all the occurences of old string
Returns:
a new string with the occurences replaced

replace

public static void replace(String oldChars,
                           char newChar,
                           StringBuffer s)
Replaces all occurences of some characters by a character

Parameters:
oldChars - the characters that should be replaced
newChar - the character by which to replace
s - the string buffer whose's characters must be replaced

replace

public static String replace(String oldChars,
                             char newChar,
                             String s)
Replaces all occurences of some characters by a character

Parameters:
oldChars - the characters that should be replaced
newChar - the character by which to replace
s - the string whose's characters must be replaced

deleteChars

public static void deleteChars(String delChars,
                               StringBuffer s)
Delete occurences of characters from a StringBuffer

Parameters:
delChars - the characters to delete
s - the StringBuffer to remlove the characters from

getShortClassName

public static String getShortClassName(Class cl)

getShortClassName

public static String getShortClassName(String className)

toUSAscii

public static String toUSAscii(String s)

toLowerCase

public static void toLowerCase(StringBuffer s)
Lowers all characters of a StringBuffer


toUpperCase

public static void toUpperCase(StringBuffer s)
Uppers all characters of a StringBuffer


toUSAscii

public static void toUSAscii(StringBuffer s)
Replace accented chars with their non-accented value. For instance, 'é' becomes 'e'.

Parameters:
s - string to convert
Returns:
converted string

equalsUSAsciiNoCase

public static boolean equalsUSAsciiNoCase(String a,
                                          String b)
Compares the USAscii representation of two strings in a case insensitive manner.

Parameters:
a - first string to compare
b - second string to compare
Returns:
true if a and b are equals

isEmpty

public static boolean isEmpty(String str)
Tells if a string is empty (is null, has a zero length, or contains only whitespaces)

Parameters:
str - string to test
Returns:
true if str is null, str.length()==0 or str.trim().length()==0

trimWSAndCRLF

public static String trimWSAndCRLF(String str)
Removes all whitespace and CR/LF characters at the beginning or at the end of a string.

Parameters:
str - the string to trim

toISO8599_1

public static String toISO8599_1(String s)
Convert a String to a string with onlu iso-8859-1 characters. Non iso-8859-1 characters are encoded with \\u

Parameters:
s - strng to encode
See Also:
fromISO8859_1(String)

fromISO8859_1

public static String fromISO8859_1(String s)
Convert a String to a string with onlu iso-8859-1 characters. Non iso-8859-1 characters are encoded with \\u

Parameters:
s - string to decode
See Also:
fromISO8859_1(String)