Package de.intarsys.tools.string
Class StringTools
java.lang.Object
de.intarsys.tools.string.StringTools
A tool class for the handling of strings.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final StringAn empty string constantstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringAn single space constant -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbreakForced(String value, int max, String breakPattern) static Stringcapitalize(String text) Capitalizes the first letter of the text.static voidclear(char[] value) clear character array content.static StringCreate a string representation and formatvalueaccording to the instructions informat.protected static StringformatDate(Object value, String format) protected static StringformatDateDefault(Date date) protected static StringformatFloat(Object value, String format) protected static StringformatInteger(Object value, String format) protected static StringformatPath(Object value, String string) protected static StringformatString(Object value, String format) static StringgetCommonPrefix(String a, String b, boolean ignoreCase) static StringgetFirstLine(String text) The first line of text (all characters up to the first occurence of either "\n" or "\r".static StringgetLeading(String value, int count) static intgetLineCount(String text) The number of lines intext.static StringgetTrailing(String value, int count) static booleanisEmpty(char[] value) trueifvalueis "empty" in any respect.static booleantrueifvalueis "empty" in any respect.static booleantrueifvalueseems to be a numeric value.static StringJoins an array of Strings to a single one.static StringJoins a List of Strings to a single one.static Stringstatic Stringprotected static String[]protected static StringparseArgsString(String string) static String[]parseCommandline(String line) Parse a commandline string with the default escape character.static String[]parseCommandline(String line, char escape) Parse a commandline string.static StringsafeString(Object object) Create a string representation ofobjectthat is guaranteed not to fail in any case.static byte[]toByteArray(String value) Create a byte array from the string.static StringtoString(byte[] value) Create a string from the byte array.static StringtrimAlphaNumeric(String value) Create a string containing only the alphanumeric content ofvalue.static StringCreate a new string fromvaluewithout leading whitespace.static StringCreate a new string fromvaluewithout trailing whitespace.
-
Field Details
-
CR
- See Also:
-
CRLF
- See Also:
-
DATEFORMAT_SIMPLE
- See Also:
-
EMPTY
An empty string constant- See Also:
-
FORMAT_D
- See Also:
-
FORMAT_F
- See Also:
-
FORMAT_I
- See Also:
-
FORMAT_P
- See Also:
-
FORMAT_S
- See Also:
-
LF
- See Also:
-
SPACE
An single space constant- See Also:
-
-
Constructor Details
-
StringTools
public StringTools()
-
-
Method Details
-
breakForced
-
capitalize
Capitalizes the first letter of the text.- Parameters:
text-- Returns:
- a capitalized version of the text
-
clear
public static void clear(char[] value) clear character array content.- Parameters:
value- The value to be cleared
-
format
Create a string representation and formatvalueaccording to the instructions informat.If
valueis null, the empty string is returned. -
formatDate
-
formatDateDefault
- Parameters:
value-
-
formatFloat
-
formatInteger
-
formatPath
-
formatString
-
getCommonPrefix
-
getFirstLine
The first line of text (all characters up to the first occurence of either "\n" or "\r".- Parameters:
text- The text where the first line is looked up.- Returns:
- The first line of text
-
getLeading
-
getLineCount
The number of lines intext. This is 1 + the number of "\n" intext.- Parameters:
text- The text where the lines are counted.- Returns:
- The number of lines in
text. This is 1 + the number of "\n" intext.
-
getTrailing
-
isEmpty
public static boolean isEmpty(char[] value) trueifvalueis "empty" in any respect.This is the case when value == null, value has no characters or only whitespace.
- Parameters:
value- The value to be inspected for emptyness.- Returns:
trueifvalueis "empty" in any respect.
-
isEmpty
trueifvalueis "empty" in any respect.This is the case when value == null, value has no characters or only whitespace.
- Parameters:
value- The value to be inspected for emptyness.- Returns:
trueifvalueis "empty" in any respect.
-
isNumeric
trueifvalueseems to be a numeric value. To qualify only the first character is examined.valuequalifies as numeric if the first character is a digit, a "+", a "-" or a ".".- Parameters:
value-- Returns:
trueifvalueseems to be numeric.
-
join
Joins a List of Strings to a single one. All elements are separated by theseparator.- Parameters:
elements- List of Stringsseparator- a String used as a separator between two elements, e.g. "\n" for a new line. May benull.- Returns:
- the joined string
-
join
Joins an array of Strings to a single one. All elements are separated by theseparator.- Parameters:
elements- array of Stringsseparator- a String used as a separator between two elements, e.g. "\n" for a new line. May benull.- Returns:
- the joined string
-
padLeft
-
padRight
-
parseArgs
-
parseArgsString
-
parseCommandline
Parse a commandline string with the default escape character.- Parameters:
line- The commandline string.- Returns:
- The array of string tokens in the commandline string.
-
parseCommandline
Parse a commandline string.- Parameters:
line- The commandline string.- Returns:
- The array of string tokens in the commandline string.
-
safeString
Create a string representation ofobjectthat is guaranteed not to fail in any case.- Parameters:
object- The object to be printed.- Returns:
- Create a string representation of
objectthat is guaranteed not to fail in any case.
-
toByteArray
Create a byte array from the string. This is simply a fast version of getBytes, ignoring any encoding.If you use this, you should be sure you will encounter valid ascii characters only!
- Parameters:
value-- Returns:
- A byte array created from value, ignoring high byte.
-
toString
Create a string from the byte array. This is simply a fast version of new String(), ignoring any encoding.If you use this, you should be sure you will encounter valid ascii characters only!
- Parameters:
value-- Returns:
- A string created from the byte values in value.
-
trimAlphaNumeric
Create a string containing only the alphanumeric content ofvalue.- Parameters:
value- The string to be trimmed.- Returns:
- A string containing only the alphanumeric content of
value.
-
trimLeft
Create a new string fromvaluewithout leading whitespace.- Parameters:
value- The string to be stripped.- Returns:
- A copy of
valuewith leading whitespace stripped.
-
trimRight
Create a new string fromvaluewithout trailing whitespace.- Parameters:
value- The string to be stripped.- Returns:
- A copy of
valuewith trailing whitespace stripped.
-