net.sf.mmm.util.lang.api
Interface StringUtil

All Known Implementing Classes:
StringUtilImpl

@ComponentSpecification
public interface StringUtil

This is the interface for a collection of utility functions that help with String handling and manipulation.

Since:
1.0.2
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)
See Also:
StringUtilImpl.getInstance(), UnicodeUtil

Field Summary
static char[] EMPTY_CHAR_ARRAY
          An empty char array.
static String[] EMPTY_STRING_ARRAY
          An empty String array.
static String FALSE
          a string representing the boolean value false
static String LINE_SEPARATOR
          The platform-specific line-separator string.
static String LINE_SEPARATOR_CR
          The line-separator with a single carriage-return.
static String LINE_SEPARATOR_CRLF
          The Windows line-separator (carriage-return line-feed).
static String LINE_SEPARATOR_LF
          The Unix line-separator (line-feed).
static String LINE_SEPARATOR_LFCR
          The Mac line-separator (line-feed carriage-return).
static String TRUE
          a string representing the boolean value true
 
Method Summary
 String fromCamlCase(String string, char separator)
          This method converts the given string from caml-case syntax to lower-case using the given separator as word-boundary.
 boolean isEmpty(String string)
          This method determines if the given string contains no information.
 boolean isEmpty(String string, boolean trim)
          This method determines if the given string is empty.
 boolean isSubstring(char[] string, String substring, int offset)
          This method checks if the given string contains the given substring at the given offset.
 boolean isSubstring(String string, String substring, int offset)
          This method checks if the given string contains the given substring at the given offset.
 String padNumber(long number, int digits)
          This method formats a positive number to a string with at least the given number of digits padding it with leading zeros.
 String padNumber(long number, int digits, int radix)
          This method formats a positive number to a string using the given radix with at least the given number of digits padding it with leading zeros.
 Boolean parseBoolean(String booleanValue)
          This method parses a boolean value given as string.
 void replace(char[] string, char oldChar, char newChar)
          This method replaces all occurrences of oldChar in the char-array given by string with newChar.
 String replace(String string, String match, String replace)
          This method replaces all occurrences of the string match with the string replace in the given string.
 String replaceSuffixWithCase(String string, int suffixLength, String newSuffixLowerCase)
          This method delegates to replaceSuffixWithCase(String, int, String, Locale) using Locale.ENGLISH.
 String replaceSuffixWithCase(String string, int suffixLength, String newSuffixLowerCase, Locale locale)
          This method replaces the last suffixLength number of characters from string with the lower-case string newSuffixLowerCase with respect to the original case of the given string.
 String toCamlCase(String string)
          This method converts the given string to caml-case syntax using the default separators ' ', '-', '_' and '.'
 String toCamlCase(String string, char... separators)
          This method converts the given string to caml-case syntax.
 

Field Detail

TRUE

static final String TRUE
a string representing the boolean value true


FALSE

static final String FALSE
a string representing the boolean value false


LINE_SEPARATOR

static final String LINE_SEPARATOR
The platform-specific line-separator string. Should be one of LINE_SEPARATOR_LF, LINE_SEPARATOR_CRLF, LINE_SEPARATOR_LFCR, LINE_SEPARATOR_CR.


LINE_SEPARATOR_CR

static final String LINE_SEPARATOR_CR
The line-separator with a single carriage-return.

See Also:
Constant Field Values

LINE_SEPARATOR_LF

static final String LINE_SEPARATOR_LF
The Unix line-separator (line-feed).

See Also:
Constant Field Values

LINE_SEPARATOR_CRLF

static final String LINE_SEPARATOR_CRLF
The Windows line-separator (carriage-return line-feed).

See Also:
Constant Field Values

LINE_SEPARATOR_LFCR

static final String LINE_SEPARATOR_LFCR
The Mac line-separator (line-feed carriage-return).

See Also:
Constant Field Values

EMPTY_STRING_ARRAY

static final String[] EMPTY_STRING_ARRAY
An empty String array.


EMPTY_CHAR_ARRAY

static final char[] EMPTY_CHAR_ARRAY
An empty char array.

Since:
2.0.0
Method Detail

parseBoolean

Boolean parseBoolean(String booleanValue)
This method parses a boolean value given as string.

Parameters:
booleanValue - is the boolean value as string.
Returns:
true if the given string equals to true, false if it equals to false and null in any other case.
See Also:
Boolean.valueOf(String)

replace

void replace(char[] string,
             char oldChar,
             char newChar)
This method replaces all occurrences of oldChar in the char-array given by string with newChar.

Parameters:
string - is the char-array where the replacement should take place.
oldChar - is the character to be replaced.
newChar - is the replacement for oldChar.
See Also:
String.replace(char, char)

replace

String replace(String string,
               String match,
               String replace)
This method replaces all occurrences of the string match with the string replace in the given string.

Parameters:
string - is the string where to replace.
match - is the string that is searched and replaced.
replace - is the string match is substituted with.
Returns:
the given string with all occurrences of match replaced by replace.

replaceSuffixWithCase

String replaceSuffixWithCase(String string,
                             int suffixLength,
                             String newSuffixLowerCase)
This method delegates to replaceSuffixWithCase(String, int, String, Locale) using Locale.ENGLISH.

Parameters:
string - is the string to replace.
suffixLength - is the length of the suffix from string to replace.
newSuffixLowerCase - is the new suffix for the given string in lower-case.
Returns:
the given string with the last suffixLength characters cut off and replaced by newSuffixLowerCase with respect to the original case of string.
See Also:
replaceSuffixWithCase(String, int, String, Locale)

replaceSuffixWithCase

String replaceSuffixWithCase(String string,
                             int suffixLength,
                             String newSuffixLowerCase,
                             Locale locale)
This method replaces the last suffixLength number of characters from string with the lower-case string newSuffixLowerCase with respect to the original case of the given string.
Here are some examples for Locale.ENGLISH:
string suffixLength newSuffixLowerCase replaceSuffixWithCase(String, int, String)
foobar 3 foo foofoo
FOOBAR 3 foo FOOFOO
FooBar 3 foo FooFoo
FooBar 2 foo FooBfoo

Parameters:
string - is the string to replace.
suffixLength - is the length of the suffix from string to replace.
newSuffixLowerCase - is the new suffix for the given string in lower-case.
locale - is the locale used for case transformation.
Returns:
the given string with the last suffixLength characters cut off and replaced by newSuffixLowerCase with respect to the original case of string.

isEmpty

boolean isEmpty(String string)
This method determines if the given string contains no information.

Parameters:
string - is the string to check.
Returns:
true if the given string is null or has a trimmed length of zero, false otherwise.
See Also:
isEmpty(String, boolean)

isEmpty

boolean isEmpty(String string,
                boolean trim)
This method determines if the given string is empty.

Parameters:
string - is the string to check.
trim - if whitespaces should be ignored and a string with a trimmed length of zero is considered as empty.
Returns:
true if the given string is null or has a (trimmed) length of zero, false otherwise.

padNumber

String padNumber(long number,
                 int digits)
This method formats a positive number to a string with at least the given number of digits padding it with leading zeros.
Examples:

Parameters:
number - is the positive number to format.
digits - is the (minimum) number of digits required.
Returns:
the number as string with the length of (at least) digits. If the number is less, leading zeros are appended.

padNumber

String padNumber(long number,
                 int digits,
                 int radix)
This method formats a positive number to a string using the given radix with at least the given number of digits padding it with leading zeros.
Examples: To pad a number to a constant length you can use the following value for digits:
Radix byte short int long
2 8 16 32 64
8 3 6 9 12
10 3 5 9 19
16 2 4 8 16

Parameters:
number - is the positive number to format.
digits - is the (minimum) number of digits required.
radix - is the radix to use.
Returns:
the number as string with the length of (at least) digits. If the number is less, leading zeros are appended.

toCamlCase

String toCamlCase(String string)
This method converts the given string to caml-case syntax using the default separators ' ', '-', '_' and '.'.

Parameters:
string - is the string to convert.
Returns:
the given string in caml-case syntax.
See Also:
toCamlCase(String, char[])

toCamlCase

String toCamlCase(String string,
                  char... separators)
This method converts the given string to caml-case syntax.
In caml-case syntax words are written without a separator but each new word starts with a capitalized letter. This method removes all characters from the given string that are in the list given by separators and capitalizes the first character of the following word.
Examples for separators ' ', '-', '_', '.':
string toCamlCase(string)
foo bar fooBar
aAa-bBB-CcC aAaBBBCcC
X--m_._l.. XML

Parameters:
string - is the string to convert.
separators - is the list of characters that are treated as word-separators.
Returns:
the given string in caml-case syntax.

fromCamlCase

String fromCamlCase(String string,
                    char separator)
This method converts the given string from caml-case syntax to lower-case using the given separator as word-boundary.
Example:
string separator fromCamlCase(string, separator)
FooBar - foo-bar
someWordMix . some.word.mix
AbbreviationsLikeXMLshouldNotBeCapitalized _ abbreviations_like_xmlshould_not_be_capitalized
FOO_BAR * foo_bar

Parameters:
string - is the string to convert.
separator - is the character to insert at word-boundaries indicated by a switch from lower- to upper-case.
Returns:
the given string in lower-case with the given separator inserted at word-boundaries.
See Also:
toCamlCase(String, char...)

isSubstring

boolean isSubstring(String string,
                    String substring,
                    int offset)
This method checks if the given string contains the given substring at the given offset.
This is an efficient implementation of
string.indexOf(substring, offset) == offset
or
string.substring(offset).beginsWith(substring)

Parameters:
string - is the string potentially containing substring.
substring - is the substring that should be contained in string at the given offset.
offset - is the offset in string where to check for substring.
Returns:
true if the given string contains the given substring at the given offset and false otherwise.

isSubstring

boolean isSubstring(char[] string,
                    String substring,
                    int offset)
This method checks if the given string contains the given substring at the given offset.
This is an efficient implementation of
string.indexOf(substring, offset) == offset
or
string.substring(offset).beginsWith(substring)

Parameters:
string - is the char[] representing the string potentially containing substring.
substring - is the substring that should be contained in string at the given offset.
offset - is the offset in string where to check for substring.
Returns:
true if the given string contains the given substring at the given offset and false otherwise.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.