org.metasyntactic.text
Class StringUtilities

java.lang.Object
  |
  +--org.metasyntactic.text.StringUtilities

public class StringUtilities
extends java.lang.Object

Privides some useful methods for manipulating strings


Field Summary
static java.lang.String NEW_LINE
          Constant equal to the platform dependent new line string.
static java.lang.String WHITE_SPACE
           
 
Method Summary
static java.util.List asList(java.lang.String S)
           
static java.lang.String center(java.lang.String string, int width)
          Pads "string" with spaces on both sides until it is 'width' long
static java.lang.String center(java.lang.String string, int width, char pad)
          Pads this string on both ends with 'pad' until it is exactly width long
static java.util.Iterator characterIterator(java.lang.String string)
          Iterates over this String returning each char as a Character Object.
static void difference(java.lang.String S, java.lang.String T)
           
static boolean isBalanced(java.lang.String str, char open, char close)
           
static boolean isLowerCase(java.lang.String str)
           
static boolean isUpperCase(java.lang.String str)
           
static void main(java.lang.String[] args)
           
static java.lang.String repeat(java.lang.String string, int times)
          Returns a new String which is the same as 'str' repeated 'times' times.
static java.lang.String replace(boolean ignoreCase, java.lang.String source, java.lang.String original, java.lang.String replace)
          Finds all occurances of "original" in "source", and replaces it with "replace"
static java.lang.String replace(java.lang.String source, java.lang.String original, java.lang.String replace)
           
static java.lang.String reverse(java.lang.String str)
          Reverses the order of the characters in this string
static java.lang.String reverse(java.lang.String str, int offset, int length)
          Reverses the characters in a certain range of this string
static java.util.Iterator stringIterator(java.lang.String string)
          Iterates over this string returning each char as a String Object.
static java.lang.String toJavaCode(java.lang.String string)
          Tough to explain...
static java.lang.String toString(java.lang.Object[][] table)
           
static java.lang.String toString(java.lang.Object[][] objTable, boolean replaceNull)
           
static java.lang.String trim(java.lang.String str)
          Trims the given string on both sides of whitepaces and ISOControl characters.
static java.lang.String trimLeft(java.lang.String str)
           
static java.lang.String trimRight(java.lang.String str)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NEW_LINE

public static java.lang.String NEW_LINE
Constant equal to the platform dependent new line string. On unix this is \n


WHITE_SPACE

public static java.lang.String WHITE_SPACE
Method Detail

center

public static java.lang.String center(java.lang.String string,
                                      int width,
                                      char pad)
Pads this string on both ends with 'pad' until it is exactly width long

Parameters:
string - The string to center
width - The width you want the resulting string to be
pad - The character you want to pad string with
Returns:
A new string with a length if 'width' with 'string' centered in it

center

public static java.lang.String center(java.lang.String string,
                                      int width)
Pads "string" with spaces on both sides until it is 'width' long

Parameters:
string - The string to pad
width - The width of the padded string
Returns:
A new string of length 'width', which is equal to the old string padded with spaces

repeat

public static java.lang.String repeat(java.lang.String string,
                                      int times)
Returns a new String which is the same as 'str' repeated 'times' times. This code is about as optimal as possible, in terms of both time and memory complexity

Parameters:
times - The number of times to repeat 'str'
string - The string to repeat
Returns:
The new String that is 'str' repeated 'times' times

toJavaCode

public static java.lang.String toJavaCode(java.lang.String string)
Tough to explain... just try it out :-) Useful for getting a string with all the proper escapes that can then be used to create a java source file.


replace

public static java.lang.String replace(boolean ignoreCase,
                                       java.lang.String source,
                                       java.lang.String original,
                                       java.lang.String replace)
Finds all occurances of "original" in "source", and replaces it with "replace"


replace

public static java.lang.String replace(java.lang.String source,
                                       java.lang.String original,
                                       java.lang.String replace)

reverse

public static java.lang.String reverse(java.lang.String str)
Reverses the order of the characters in this string


reverse

public static java.lang.String reverse(java.lang.String str,
                                       int offset,
                                       int length)
Reverses the characters in a certain range of this string


toString

public static java.lang.String toString(java.lang.Object[][] table)

toString

public static java.lang.String toString(java.lang.Object[][] objTable,
                                        boolean replaceNull)
Parameters:
objTable -
replaceNull -
Returns:

characterIterator

public static java.util.Iterator characterIterator(java.lang.String string)
Iterates over this String returning each char as a Character Object. i.e. Cyrus becomes --> 'C' 'y' 'r' 'u' 's'


stringIterator

public static java.util.Iterator stringIterator(java.lang.String string)
Iterates over this string returning each char as a String Object. i.s. Cyrus becomes --> "C" "y" "r" "u" "s"


isUpperCase

public static boolean isUpperCase(java.lang.String str)

isLowerCase

public static boolean isLowerCase(java.lang.String str)

trim

public static java.lang.String trim(java.lang.String str)
Trims the given string on both sides of whitepaces and ISOControl characters. If null is passed in, it is returned.

Returns:
a new String equivalent to the string passed in, without spaces or control characters.

trimLeft

public static java.lang.String trimLeft(java.lang.String str)

trimRight

public static java.lang.String trimRight(java.lang.String str)

isBalanced

public static boolean isBalanced(java.lang.String str,
                                 char open,
                                 char close)

difference

public static void difference(java.lang.String S,
                              java.lang.String T)

asList

public static final java.util.List asList(java.lang.String S)

main

public static void main(java.lang.String[] args)