Package de.intarsys.tools.string
Class StringTools
- java.lang.Object
-
- de.intarsys.tools.string.StringTools
-
public class StringTools extends java.lang.Object
A tool class for the handling of strings.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CR
static java.lang.String
CRLF
static java.lang.String
DATEFORMAT_SIMPLE
static java.lang.String
EMPTY
An empty string constantstatic java.lang.String
FORMAT_D
static java.lang.String
FORMAT_F
static java.lang.String
FORMAT_I
static java.lang.String
FORMAT_P
static java.lang.String
FORMAT_S
static java.lang.String
LF
static java.lang.String
SPACE
An single space constant
-
Constructor Summary
Constructors Constructor Description StringTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
breakForced(java.lang.String value, int max, java.lang.String breakPattern)
static java.lang.String
capitalize(java.lang.String text)
Capitalizes the first letter of the text.static void
clear(char[] value)
clear character array content.static java.lang.String
format(java.lang.Object value, java.lang.String format)
Create a string representation and formatvalue
according to the instructions informat
.protected static java.lang.String
formatDate(java.lang.Object value, java.lang.String format)
protected static java.lang.String
formatDateDefault(java.util.Date date)
protected static java.lang.String
formatFloat(java.lang.Object value, java.lang.String format)
protected static java.lang.String
formatInteger(java.lang.Object value, java.lang.String format)
protected static java.lang.String
formatPath(java.lang.Object value, java.lang.String string)
protected static java.lang.String
formatString(java.lang.Object value, java.lang.String format)
static java.lang.String
getCommonPrefix(java.lang.String a, java.lang.String b, boolean ignoreCase)
static java.lang.String
getFirstLine(java.lang.String text)
The first line of text (all characters up to the first occurence of either "\n" or "\r".static java.lang.String
getLeading(java.lang.String value, int count)
static int
getLineCount(java.lang.String text)
The number of lines intext
.static java.lang.String
getTrailing(java.lang.String value, int count)
static boolean
isEmpty(char[] value)
true
ifvalue
is "empty" in any respect.static boolean
isEmpty(java.lang.String value)
true
ifvalue
is "empty" in any respect.static boolean
isNumeric(java.lang.String value)
true
ifvalue
seems to be a numeric value.static java.lang.String
join(java.lang.String[] elements, java.lang.String separator)
Joins an array of Strings to a single one.static java.lang.String
join(java.util.List<java.lang.String> elements, java.lang.String separator)
Joins a List of Strings to a single one.static java.lang.String
padLeft(java.lang.String value, int count)
static java.lang.String
padRight(java.lang.String value, int count)
protected static java.lang.String[]
parseArgs(java.lang.String string)
protected static java.lang.String
parseArgsString(java.lang.String string)
static java.lang.String[]
parseCommandline(java.lang.String line)
Parse a commandline string with the default escape character.static java.lang.String[]
parseCommandline(java.lang.String line, char escape)
Parse a commandline string.static java.lang.String
safeString(java.lang.Object object)
Create a string representation ofobject
that is guaranteed not to fail in any case.static byte[]
toByteArray(java.lang.String value)
Create a byte array from the string.static java.lang.String
toString(byte[] value)
Create a string from the byte array.static java.lang.String
trimAlphaNumeric(java.lang.String value)
Create a string containing only the alphanumeric content ofvalue
.static java.lang.String
trimLeft(java.lang.String value)
Create a new string fromvalue
without leading whitespace.static java.lang.String
trimRight(java.lang.String value)
Create a new string fromvalue
without trailing whitespace.
-
-
-
Field Detail
-
CR
public static final java.lang.String CR
- See Also:
- Constant Field Values
-
CRLF
public static final java.lang.String CRLF
- See Also:
- Constant Field Values
-
DATEFORMAT_SIMPLE
public static final java.lang.String DATEFORMAT_SIMPLE
- See Also:
- Constant Field Values
-
EMPTY
public static final java.lang.String EMPTY
An empty string constant- See Also:
- Constant Field Values
-
FORMAT_D
public static final java.lang.String FORMAT_D
- See Also:
- Constant Field Values
-
FORMAT_F
public static final java.lang.String FORMAT_F
- See Also:
- Constant Field Values
-
FORMAT_I
public static final java.lang.String FORMAT_I
- See Also:
- Constant Field Values
-
FORMAT_P
public static final java.lang.String FORMAT_P
- See Also:
- Constant Field Values
-
FORMAT_S
public static final java.lang.String FORMAT_S
- See Also:
- Constant Field Values
-
LF
public static final java.lang.String LF
- See Also:
- Constant Field Values
-
SPACE
public static final java.lang.String SPACE
An single space constant- See Also:
- Constant Field Values
-
-
Method Detail
-
breakForced
public static java.lang.String breakForced(java.lang.String value, int max, java.lang.String breakPattern)
-
capitalize
public static java.lang.String capitalize(java.lang.String text)
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
public static java.lang.String format(java.lang.Object value, java.lang.String format)
Create a string representation and formatvalue
according to the instructions informat
.If
value
is null, the empty string is returned.
-
formatDate
protected static java.lang.String formatDate(java.lang.Object value, java.lang.String format)
-
formatDateDefault
protected static java.lang.String formatDateDefault(java.util.Date date)
- Parameters:
value
-
-
formatFloat
protected static java.lang.String formatFloat(java.lang.Object value, java.lang.String format)
-
formatInteger
protected static java.lang.String formatInteger(java.lang.Object value, java.lang.String format)
-
formatPath
protected static java.lang.String formatPath(java.lang.Object value, java.lang.String string)
-
formatString
protected static java.lang.String formatString(java.lang.Object value, java.lang.String format)
-
getCommonPrefix
public static java.lang.String getCommonPrefix(java.lang.String a, java.lang.String b, boolean ignoreCase)
-
getFirstLine
public static java.lang.String getFirstLine(java.lang.String text)
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
public static java.lang.String getLeading(java.lang.String value, int count)
-
getLineCount
public static int getLineCount(java.lang.String text)
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
public static java.lang.String getTrailing(java.lang.String value, int count)
-
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
public static boolean isEmpty(java.lang.String 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.
-
isNumeric
public static boolean isNumeric(java.lang.String value)
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
public static java.lang.String join(java.util.List<java.lang.String> elements, java.lang.String separator)
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
public static java.lang.String join(java.lang.String[] elements, java.lang.String separator)
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
public static java.lang.String padLeft(java.lang.String value, int count)
-
padRight
public static java.lang.String padRight(java.lang.String value, int count)
-
parseArgs
protected static java.lang.String[] parseArgs(java.lang.String string)
-
parseArgsString
protected static java.lang.String parseArgsString(java.lang.String string)
-
parseCommandline
public static java.lang.String[] parseCommandline(java.lang.String line)
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
public static java.lang.String[] parseCommandline(java.lang.String line, char escape)
Parse a commandline string.- Parameters:
line
- The commandline string.- Returns:
- The array of string tokens in the commandline string.
-
safeString
public static java.lang.String safeString(java.lang.Object object)
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
public static byte[] toByteArray(java.lang.String value)
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
public static java.lang.String toString(byte[] value)
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
public static java.lang.String trimAlphaNumeric(java.lang.String value)
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
public static java.lang.String trimLeft(java.lang.String value)
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
public static java.lang.String trimRight(java.lang.String value)
Create a new string fromvalue
without trailing whitespace.- Parameters:
value
- The string to be stripped.- Returns:
- A copy of
value
with trailing whitespace stripped.
-
-