JAC project
AOPSYS
CEDRIC & LIP6 labs

org.objectweb.jac.util
Class Strings

java.lang.Object
  |
  +--org.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 boolean equalsUSAsciiNoCase(String a, String b)
          Compares the USAscii representation of two strings in a case insensitive manner.
static String getShortClassName(Class cl)
           
static String getShortClassName(String className)
           
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)
           
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 orgString, String oldString, String newString)
          A useful method that replaces all the occurences of a string.
static String slashify(String str)
          The reverse of unslashify.
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 toUSAscii(String 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' , "\_" -> ' ')


slashify

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


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)

join

public static String join(String[] items,
                          String separator)

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

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

getShortClassName

public static String getShortClassName(Class cl)

getShortClassName

public static String getShortClassName(String className)

toUSAscii

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

Parameters:
s - string to convert

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

Contact JAC development team:
Renaud Pawlak
Lionel Seinturier
Laurent Martelli