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 String
static final String
static final String
static final String
An empty string constantstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
An single space constant -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
breakForced
(String value, int max, String breakPattern) static String
capitalize
(String text) Capitalizes the first letter of the text.static void
clear
(char[] value) clear character array content.static String
Create a string representation and formatvalue
according to the instructions informat
.protected static String
formatDate
(Object value, String format) protected static String
formatDateDefault
(Date date) protected static String
formatFloat
(Object value, String format) protected static String
formatInteger
(Object value, String format) protected static String
formatPath
(Object value, String string) protected static String
formatString
(Object value, String format) static String
getCommonPrefix
(String a, String b, boolean ignoreCase) static String
getFirstLine
(String text) The first line of text (all characters up to the first occurence of either "\n" or "\r".static String
getLeading
(String value, int count) static int
getLineCount
(String text) The number of lines intext
.static String
getTrailing
(String value, int count) static boolean
isEmpty
(char[] value) true
ifvalue
is "empty" in any respect.static boolean
true
ifvalue
is "empty" in any respect.static boolean
true
ifvalue
seems to be a numeric value.static String
Joins an array of Strings to a single one.static String
Joins a List of Strings to a single one.static String
static String
protected static String[]
protected static String
parseArgsString
(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 String
safeString
(Object object) Create a string representation ofobject
that is guaranteed not to fail in any case.static byte[]
toByteArray
(String value) Create a byte array from the string.static String
toString
(byte[] value) Create a string from the byte array.static String
trimAlphaNumeric
(String value) Create a string containing only the alphanumeric content ofvalue
.static String
Create a new string fromvalue
without leading whitespace.static String
Create a new string fromvalue
without 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 formatvalue
according to the instructions informat
.If
value
is 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) true
ifvalue
is "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:
true
ifvalue
is "empty" in any respect.
-
isEmpty
true
ifvalue
is "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:
true
ifvalue
is "empty" in any respect.
-
isNumeric
true
ifvalue
seems to be a numeric value. To qualify only the first character is examined.value
qualifies as numeric if the first character is a digit, a "+", a "-" or a ".".- Parameters:
value
-- Returns:
true
ifvalue
seems 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 ofobject
that is guaranteed not to fail in any case.- Parameters:
object
- The object to be printed.- Returns:
- Create a string representation of
object
that 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 fromvalue
without leading whitespace.- Parameters:
value
- The string to be stripped.- Returns:
- A copy of
value
with leading whitespace stripped.
-
trimRight
Create a new string fromvalue
without trailing whitespace.- Parameters:
value
- The string to be stripped.- Returns:
- A copy of
value
with trailing whitespace stripped.
-