wt.util
Class WTStringUtilities

java.lang.Object
  extended bywt.util.WTStringUtilities

public class WTStringUtilities
extends Object

WTStringUtilities Additional String functions


Field Summary
private static String versionID
           
 
Constructor Summary
WTStringUtilities()
           
 
Method Summary
static String ascii2native(String in, String encoding)
          Not thoroughly tested.
static String capitalize(String string)
          Capitalize a string.
static String doubleQuote(String aString)
           
static void doubleQuote(StringBuffer buf, String aString)
           
static String escapeNewLines(String original)
          Insert escapes prior to each existence of a new line character.
static String getterName(String root)
          Convert a field name to its getter method name.
static String getterName(String root, String type)
          Convert a field name to its getter method name.
static String insert(String original, String insert, char beforeChar)
          Insert a string into another string, before a specified character.
static String insert(String original, String insert, int beforeIndex)
          Insert a string into another string, before a specified character.
static String insertEscapeChars(String theString)
          Insert escapes prior to each existence of a character that needs to be escaped.
static String insertEscapeChars(String aString, String characters)
          Insert escapes prior to each existence of the each of the characters in a string.
static boolean isEmpty(String target)
          Check a string to see if it contains anything.
static String loadConvert(String theString)
           
static String native2ascii(String in, String encoding)
          Not thoroughly tested.
static String padRight(String aString, int length, boolean trim)
          Pad the string to be the specified length, adding spaces to the end.
static String replace(String original, String insert, String remove)
          Replace a substring, within a string, with another string.
static String replaceAll(String original, String insert, String remove)
          Replace all occurances of a substring, within a string, with another string.
static String singleQuote(String aString)
           
static void singleQuote(StringBuffer buf, String aString)
           
static String tail(String aString, char aSeparator)
           
static String tail(String aString, char aSeparator, int level)
          Pull off the trailing token following the supplied separator to the level supplied.
static String tail(String aString, String separators)
          Pull off the trailing token following the last separator, of the supplied separator.
static String[] toArray(String delimitedlist, String separators)
          Convert a delimited String into a String array.
static String toConstant(String string)
          Convert a name to its constant name.
static String toDisplayName(String string)
          Convert a "programming" name to a displayable name.
static String trimTail(String aString, char aSeparator)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

versionID

private static final String versionID
See Also:
Constant Field Values
Constructor Detail

WTStringUtilities

public WTStringUtilities()
Method Detail

ascii2native

public static String ascii2native(String in,
                                  String encoding)
Not thoroughly tested.


capitalize

public static String capitalize(String string)
Capitalize a string.
   Example Usage:
  	WTStringUtilities.capitalize( "attribute" )	// returns "Attribute"
  
  

Parameters:
string - - a String
Returns:
The passed string, with the first character converted to upper case.

doubleQuote

public static String doubleQuote(String aString)

doubleQuote

public static void doubleQuote(StringBuffer buf,
                               String aString)

escapeNewLines

public static String escapeNewLines(String original)
Insert escapes prior to each existence of a new line character.
   Example Usage:
  	WTStringUtilities.escapeNewLines( "a"+ '\n' + "c" )	// returns "a\nc"
  
  

Parameters:
original - - the String to which escapes will be inserted
Returns:
The converted string.

getterName

public static String getterName(String root)
Convert a field name to its getter method name.
   Example Usage:
  	WTStringUtilities.getterName( "attribute" )	// returns "getAttribute"
  
  	WTStringUtilities.getterName( "theRole" )		// returns "getRole"
  
  

Returns:
The name of the getter method for the field.

getterName

public static String getterName(String root,
                                String type)
Convert a field name to its getter method name. Will use the "is" pattern for boolean types.
   Example Usage:
  	WTStringUtilities.getterName( "valid", "boolean" )		// returns "isValid"
  
  	WTStringUtilities.getterName( "attribute", "String" )	// returns "getAttribute"
  
  	WTStringUtilities.getterName( "theRole", "Object" )		// returns "getRole"
  
  

Parameters:
type - - a String, which is a Java type
Returns:
The name of the getter method for the field.

insert

public static String insert(String original,
                            String insert,
                            char beforeChar)
Insert a string into another string, before a specified character. If the character is not found, the insert string will be appended to the original string.
   Example Usage:
  	WTStringUtilities.insert( "abef", "cd", 'e' )	// returns "abcdef"
  
  	WTStringUtilities.insert( "abef", "cd", 'x' )	// returns "abefcd"
  
  	WTStringUtilities.insert( "abef", "cd", 'a' )	// returns "cdabef"
  
  	WTStringUtilities.insert( "af", "bcde", 'f' )	// returns "abcdef"
  
  

Parameters:
original - the string into which another string will be inserted
insert - the string to insert into the original string
beforeChar - the char before which the "insert" be placed
Returns:
The original string with the insert placed as requested.

insert

public static String insert(String original,
                            String insert,
                            int beforeIndex)
Insert a string into another string, before a specified character. If the character is not found, the insert string will be appended to the original string.
 
   Example Usage: 
   WTStringUtilities.insert( "abef", "cd", 3 ) // returns "abcdef" 
 
   WTStringUtilities.insert( "abef", "cd", 5 ) // returns "abefcd" 
 
   WTStringUtilities.insert( "abef", "cd", -1 ) // returns "abefcd" 
 
   WTStringUtilities.insert( "abef", "cd", 1 ) // returns "cdabef" 
 
   WTStringUtilities.insert( "af", "bcde", 2' ) // returns "abcdef" 
 
  

Parameters:
original - the string into which another string will be inserted
insert - the string to insert into the original string
beforeIndex - the index before which the "insert" be placed
Returns:
The original string with the insert placed as requested.

insertEscapeChars

public static String insertEscapeChars(String theString)
Insert escapes prior to each existence of a character that needs to be escaped. This is used for preparing a String to be printed to a file.
   Example Usage:
  	WTStringUtilities.insertEscapeChars( "a\"b\"c\n" )		// returns "a\"b\"c\n"
  
  

Parameters:
theString - - the String to which escapes will be inserted
Returns:
The converted string.

insertEscapeChars

public static String insertEscapeChars(String aString,
                                       String characters)
Insert escapes prior to each existence of the each of the characters in a string.
   Example Usage:
  	WTStringUtilities.insertEscapeChars( "a\"b\"c", "\"" )		// returns "a\"b\"c"
  
  

Parameters:
aString - - the String to which escapes will be inserted
characters - - the characters to escape
Returns:
The converted string.

loadConvert

public static String loadConvert(String theString)

native2ascii

public static String native2ascii(String in,
                                  String encoding)
Not thoroughly tested.


padRight

public static String padRight(String aString,
                              int length,
                              boolean trim)
Pad the string to be the specified length, adding spaces to the end.
   Example Usage:
  	WTStringUtilities.padRight( "abc", 5, true )    // returns "abc  "
  
  	WTStringUtilities.padRight( "abc", 2, true )    // returns "ab"
  
  	WTStringUtilities.padRight( "abc", 2, false )   // returns "abc"
  
  

Parameters:
aString - - the String to search
length - - the desired length of the returned string
trim - - if true, returned string not exceed desired length
Returns:
The padded string.

replace

public static String replace(String original,
                             String insert,
                             String remove)
Replace a substring, within a string, with another string. If the string is not found, the original string will be returned.
   Example Usage:
  	WTStringUtilities.replace( "abef", "cd", "e" )	// returns "abcdf"
  
  	WTStringUtilities.replace( "abef", "cd", "x" )	// returns "abef"
  
  	WTStringUtilities.replace( "abef", "c", "ab" )	// returns "cef"
  
  	WTStringUtilities.replace( "af", "bcde", "f" )	// returns "abcde"
  
  	WTStringUtilities.replace( "abcc", "cd", "cc" )	// returns "abcd"
  
  

Parameters:
original - the string into which another substring will be replaced
insert - the string to insert into the original string
remove - the substring that will be replaced by the insert string
Returns:
The original string with the substring replaced.

replaceAll

public static String replaceAll(String original,
                                String insert,
                                String remove)
Replace all occurances of a substring, within a string, with another string. If the substring is not found, the original string will be returned.
   Example Usage:
  	WTStringUtilities.replace( "abef", "cd", "e" )	// returns "abcdf"
  
  	WTStringUtilities.replace( "abef", "cd", "x" )	// returns "abef"
  
  	WTStringUtilities.replace( "abef", "cba", "ab" )// returns "cbaef"
  
  	WTStringUtilities.replace( "afbaf","z", "af" )	// returns "zbz"
  
  	WTStringUtilities.replace( "abcc", "d", "c" )	// returns "abdd"
  
  

Parameters:
original - the string into which another substring will be replaced
insert - the string to insert into the original string
remove - the substring that will be replaced by the insert string
Returns:
The original string with the substring replaced.

singleQuote

public static String singleQuote(String aString)

singleQuote

public static void singleQuote(StringBuffer buf,
                               String aString)

tail

public static String tail(String aString,
                          char aSeparator)

tail

public static String tail(String aString,
                          char aSeparator,
                          int level)
Pull off the trailing token following the supplied separator to the level supplied.
   Example Usage:
  	WTStringUtilities.tail( "wt.doc.WTDocument", '.', 2 )		// returns "doc.WTDocument"
  
  

Parameters:
aString - - the String to convert
aSeparator - - the separator to consider
level - - the level to consider
Returns:
The spedified portion of aString.

tail

public static String tail(String aString,
                          String separators)
Pull off the trailing token following the last separator, of the supplied separator.
   Example Usage:
  	WTStringUtilities.tail( "x.y.z", "." )		// returns "z"
  
  	WTStringUtilities.tail( "x.y>z", "." )		// returns "y>z"
  
  	WTStringUtilities.tail( "x.y>z", ".>" )	// returns "z"
  
  

Parameters:
aString - - the String to search
separators - - the separators to consider
Returns:
The tail token following the last separator.

toArray

public static String[] toArray(String delimitedlist,
                               String separators)
Convert a delimited String into a String array.
   Example Usage:
  	WTStringUtilities.toArray( "x,y,z", "," )		// returns ["x","y","z"]
  
  	WTStringUtilities.toArray( "x,y z", "," )		// returns ["x","y z"]
  
  	WTStringUtilities.toArray( "x,y z", ", " )	// returns ["x","y","z"]
  
  

Parameters:
delimitedlist - - the String to convert
separators - - the separators to consider
Returns:
A String array, which contains that Strings that were in the delimitedList.

toConstant

public static String toConstant(String string)
Convert a name to its constant name.
   Example Usage:
  	WTStringUtilities.toConstant( "valid" )				// returns "VALID"
  
  	WTStringUtilities.toConstant( "anAttribute" )		// returns "AN_ATTRIBUTE"
  
  	WTStringUtilities.toConstant( "theRole" )			// returns "ROLE"
  
  	WTStringUtilities.toConstant( "AProperty" )		// returns "APROPERTY"
  
  

Parameters:
string - - a String name
Returns:
The name of the constant for the name.

toDisplayName

public static String toDisplayName(String string)
Convert a "programming" name to a displayable name.
   Example Usage:
  	WTStringUtilities.toDisplayName( "valid" )				// returns "Valid"
  
  	WTStringUtilities.toDisplayName( "anAttribute" )		// returns "An Attribute"
  
  	WTStringUtilities.toDisplayName( "theRole" )			// returns "Role"
  
  	WTStringUtilities.toDisplayName( "myOwnProperty" )	// returns "My Own Property"
  
  

Parameters:
string - - a String name
Returns:
The name as displayable name.

isEmpty

public static boolean isEmpty(String target)
Check a string to see if it contains anything.
   Example Usage:
  	WTStringUtilities.isEmpty( null )	// returns true

  	WTStringUtilities.isEmpty( "" )	   // returns true

  	WTStringUtilities.isEmpty( " " )	   // returns false

  

Parameters:
target - the string to check
Returns:
True if it is null or an empty String "".

trimTail

public static String trimTail(String aString,
                              char aSeparator)