de.hunsicker.util
Class StringHelper

java.lang.Object
  |
  +--de.hunsicker.util.StringHelper

public final class StringHelper
extends java.lang.Object

String related helper functions.

Version:
$Revision: 1.4.2.1 $
Author:
Marco Hunsicker

Field Summary
static int TRIM_ALL
          Trim both leading and trailing whitespace.
static int TRIM_LEADING
          Trim only leading whitespace.
static int TRIM_NONE
          No trimming.
 
Method Summary
static boolean containsUppercase(java.lang.String str)
          Returns true if the given string contains at least one uppercase letter.
static java.lang.String getClassName(java.lang.String qualifiedName)
          Returns the name part of the given qualified java class name.
static java.lang.String getPackageName(java.lang.String name)
          Returns the package name of the given Java class name.
static int indexOf(char character, java.lang.String str, int x)
          Returns the index within the given string of the x. occurrence of the specified character.
static int indexOfNonWhitespace(java.lang.String str)
          Returns the offset of the first non-whitespace character of the given string.
static int indexOfNonWhitespace(java.lang.String str, int beginOffset)
          Returns the offset of the first non-whitespace character of the given string.
static boolean isNumber(java.lang.String str)
          Checks whether the given string represents a number.
static boolean isUppercase(char letter)
          Returns true if the given letter is uppercase.
static java.lang.String leftPad(java.lang.String str, int size)
          Left pad a String with spaces.
static java.lang.String leftPad(java.lang.String str, int size, java.lang.String delim)
          Left pad a String with a specified string.
static java.lang.String lowercaseFirst(java.lang.String str)
          Returns the given string with the first letter converted to lower case.
static int occurs(char character, char[] string)
          Returns the number of occurrences of character in string.
static int occurs(char character, java.lang.String string)
          Returns the number of occurrences of character in string.
static java.lang.String repeat(java.lang.String str, int repeat)
          Repeat a string n times to form a new string.
static java.lang.String replace(java.lang.String original, java.lang.String replaceFrom, java.lang.String replaceTo)
          Searchs and replaces fixed string matches within the given string.
static java.lang.String[] split(java.lang.String str, java.lang.String delim)
          Splits the given string into chunks.
static boolean startsWithUppercase(java.lang.String str)
          Returns true if the given string starts with an uppercase letter.
static java.lang.String trimTrailing(java.lang.String str)
          Removes trailing whitespace from the given string.
static java.lang.String wrapString(java.lang.String str, int width, boolean removeNewLines)
          Wraps multi-line strings.
static java.lang.String[] wrapStringToArray(java.lang.String str, int width, java.text.BreakIterator breakIter, java.lang.String lineSeparator, boolean removeNewLines, int trimPolicy)
          Wraps multi-line strings (and get the individual lines).
static java.lang.String[] wrapStringToArray(java.lang.String str, int width, java.lang.String lineSeparator, boolean removeNewLines, int trimPolicy)
          Wraps multi-line strings (and returns the individual lines).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRIM_ALL

public static final int TRIM_ALL
Trim both leading and trailing whitespace.

See Also:
Constant Field Values

TRIM_LEADING

public static final int TRIM_LEADING
Trim only leading whitespace.

See Also:
Constant Field Values

TRIM_NONE

public static final int TRIM_NONE
No trimming.

See Also:
Constant Field Values
Method Detail

getClassName

public static java.lang.String getClassName(java.lang.String qualifiedName)
Returns the name part of the given qualified java class name.

Parameters:
qualifiedName - name for which the name part should be returned.
Returns:
name part of the given name. Returns null if the given name was null itself.
See Also:
getPackageName(java.lang.String)

isNumber

public static boolean isNumber(java.lang.String str)
Checks whether the given string represents a number.

Parameters:
str - string to check.
Returns:
true if str represents a number.

getPackageName

public static java.lang.String getPackageName(java.lang.String name)
Returns the package name of the given Java class name.

Parameters:
name - class name for which the package name should be returned.
Returns:
package name of the given class name. Returns the empty string if the given name contains no package name (the default package).
See Also:
getClassName(java.lang.String)

isUppercase

public static boolean isUppercase(char letter)
Returns true if the given letter is uppercase.

Parameters:
letter - letter to check for capitalization.
Returns:
true if the given letter is uppercase.

containsUppercase

public static boolean containsUppercase(java.lang.String str)
Returns true if the given string contains at least one uppercase letter.

Parameters:
str - string to check for uppercase letters.
Returns:
true if the given string contains at least one uppercase letter.

indexOf

public static int indexOf(char character,
                          java.lang.String str,
                          int x)
Returns the index within the given string of the x. occurrence of the specified character.

Parameters:
character - character to search.
str - the string to search.
x - x. occurrence of the character to search for.
Returns:
s the index within the given string of the x. occurrence of the given character. Returns -1 if the specified character is not contained in the given string or it occurs less than the specified occurrence to look for.

indexOfNonWhitespace

public static int indexOfNonWhitespace(java.lang.String str)
Returns the offset of the first non-whitespace character of the given string.

Parameters:
str - a string.
Returns:
the offset of the first non-whitespace character in the given string. Returns -1 if no non-whitespace character could be found.

indexOfNonWhitespace

public static int indexOfNonWhitespace(java.lang.String str,
                                       int beginOffset)
Returns the offset of the first non-whitespace character of the given string.

Parameters:
str - a string.
beginOffset - DOCUMENT ME!
Returns:
the offset of the first non-whitespace character in the given string. Returns -1 if no non-whitespace character could be found.
Throws:
java.lang.IllegalArgumentException - DOCUMENT ME!

leftPad

public static java.lang.String leftPad(java.lang.String str,
                                       int size)
Left pad a String with spaces. Pad to a size of n.

Parameters:
str - String to pad out
size - int size to pad to
Returns:
DOCUMENT ME!

leftPad

public static java.lang.String leftPad(java.lang.String str,
                                       int size,
                                       java.lang.String delim)
Left pad a String with a specified string. Pad to a size of n.

Parameters:
str - String to pad out
size - int size to pad to
delim - String to pad with
Returns:
DOCUMENT ME!

lowercaseFirst

public static java.lang.String lowercaseFirst(java.lang.String str)
Returns the given string with the first letter converted to lower case.

Parameters:
str - string to transform.
Returns:
the transformed string. If the string already begins with a lower case letter or is the empty string, the original string is returned.

occurs

public static int occurs(char character,
                         char[] string)
Returns the number of occurrences of character in string.

Parameters:
character - character to search for.
string - character array to search.
Returns:
number of occurrences of character in string. Returns 0 if no occurrences could be found.

occurs

public static int occurs(char character,
                         java.lang.String string)
Returns the number of occurrences of character in string.

Parameters:
character - character to search for.
string - string to search.
Returns:
number of occurrences of character in string. Returns 0 if no occurrences could be found.

repeat

public static java.lang.String repeat(java.lang.String str,
                                      int repeat)
Repeat a string n times to form a new string.

Parameters:
str - String to repeat
repeat - int number of times to repeat
Returns:
String with repeated string

replace

public static java.lang.String replace(java.lang.String original,
                                       java.lang.String replaceFrom,
                                       java.lang.String replaceTo)
Searchs and replaces fixed string matches within the given string.

Parameters:
original - the original string.
replaceFrom - the substring to be find.
replaceTo - the substring to replace it with.
Returns:
new string with all occurrences replaced.

split

public static java.lang.String[] split(java.lang.String str,
                                       java.lang.String delim)
Splits the given string into chunks.

Parameters:
str - string to split into chunks.
delim - the delimeter to use for splitting.
Returns:
array with the individual chunks.
Since:
1.0b8

startsWithUppercase

public static boolean startsWithUppercase(java.lang.String str)
Returns true if the given string starts with an uppercase letter.

Parameters:
str - string to check.
Returns:
true if the given string starts with an uppercase letter.

trimTrailing

public static java.lang.String trimTrailing(java.lang.String str)
Removes trailing whitespace from the given string.

Parameters:
str - the string to trim.
Returns:
a copy of the string with trailing whitespace removed, or the original string if no trailing whitespace could be removed.

wrapString

public static java.lang.String wrapString(java.lang.String str,
                                          int width,
                                          boolean removeNewLines)
Wraps multi-line strings.

Parameters:
str - the string to wrap.
width - the maximum width of lines.
removeNewLines - if true, any newlines in the original string are ignored.
Returns:
the whole string with embedded newlines.

wrapStringToArray

public static java.lang.String[] wrapStringToArray(java.lang.String str,
                                                   int width,
                                                   java.lang.String lineSeparator,
                                                   boolean removeNewLines,
                                                   int trimPolicy)
Wraps multi-line strings (and returns the individual lines).

Parameters:
str - the string to wrap.
width - the maximum width of each line.
lineSeparator - the lineSeparator string used for newlines.
removeNewLines - if true, any newlines in the original string are ignored.
trimPolicy - trim the resulting lines according to the given policy.
Returns:
the lines after wrapping.

wrapStringToArray

public static java.lang.String[] wrapStringToArray(java.lang.String str,
                                                   int width,
                                                   java.text.BreakIterator breakIter,
                                                   java.lang.String lineSeparator,
                                                   boolean removeNewLines,
                                                   int trimPolicy)
Wraps multi-line strings (and get the individual lines).

Parameters:
str - the string to wrap.
width - the maximum width of each line.
breakIter - the iterator to use to break the string into chunks.
lineSeparator - the lineSeparator string used for newlines.
removeNewLines - if true, any newlines in the original string are ignored.
trimPolicy - trim the resulting lines according to the given policy.
Returns:
the lines after wrapping.


Copyright © 1997-2005 Jalopy. All Rights Reserved.