intarsys runtime library

de.intarsys.tools.string
Class StringTools

java.lang.Object
  extended by de.intarsys.tools.string.StringTools

public class StringTools
extends Object

A tool class for the handling of strings.


Field Summary
static String CR
           
static String CRLF
           
static String DATEFORMAT_SIMPLE
           
static String EMPTY
          An empty string constant
static String FORMAT_D
           
static String FORMAT_F
           
static String FORMAT_I
           
static String FORMAT_P
           
static String FORMAT_S
           
static String LF
           
static String SPACE
          An single space constant
 
Constructor Summary
StringTools()
           
 
Method Summary
static String capitalize(String text)
          Capitalizes the first letter of the text.
static void clear(char[] value)
          clear character array content.
static String format(Object value, String format)
          Create a string representation and format value according to the instructions in 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 in text.
static String getTrailing(String value, int count)
           
static boolean isEmpty(char[] value)
          true if value is "empty" in any respect.
static boolean isEmpty(String value)
          true if value is "empty" in any respect.
static boolean isNumeric(String value)
          true if value seems to be a numeric value.
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 of object 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 of value.
static String trimLeft(String value)
          Create a new string from value without leading whitespace.
static String trimRight(String value)
          Create a new string from value without trailing whitespace.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LF

public static final String LF
See Also:
Constant Field Values

CRLF

public static final String CRLF
See Also:
Constant Field Values

CR

public static final String CR
See Also:
Constant Field Values

DATEFORMAT_SIMPLE

public static final String DATEFORMAT_SIMPLE
See Also:
Constant Field Values

FORMAT_P

public static final String FORMAT_P
See Also:
Constant Field Values

FORMAT_D

public static final String FORMAT_D
See Also:
Constant Field Values

FORMAT_I

public static final String FORMAT_I
See Also:
Constant Field Values

FORMAT_F

public static final String FORMAT_F
See Also:
Constant Field Values

FORMAT_S

public static final String FORMAT_S
See Also:
Constant Field Values

EMPTY

public static final String EMPTY
An empty string constant

See Also:
Constant Field Values

SPACE

public static final String SPACE
An single space constant

See Also:
Constant Field Values
Constructor Detail

StringTools

public StringTools()
Method Detail

capitalize

public static String capitalize(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 String format(Object value,
                            String format)
Create a string representation and format value according to the instructions in format.

If value is null, the empty string is returned.


getCommonPrefix

public static String getCommonPrefix(String a,
                                     String b,
                                     boolean ignoreCase)

getFirstLine

public static String getFirstLine(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 String getLeading(String value,
                                int count)

getLineCount

public static int getLineCount(String text)
The number of lines in text. This is 1 + the number of "\n" in text.

Parameters:
text - The text where the lines are counted.
Returns:
The number of lines in text. This is 1 + the number of "\n" in text.

getTrailing

public static String getTrailing(String value,
                                 int count)

isEmpty

public static boolean isEmpty(char[] value)
true if value 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 if value is "empty" in any respect.

isEmpty

public static boolean isEmpty(String value)
true if value 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 if value is "empty" in any respect.

isNumeric

public static boolean isNumeric(String value)
true if value 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:
pageSizeString -
Returns:
true if value seems to be numeric.

parseCommandline

public static String[] parseCommandline(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 String[] parseCommandline(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 String safeString(Object object)
Create a string representation of object 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(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 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 String trimAlphaNumeric(String value)
Create a string containing only the alphanumeric content of value.

Parameters:
value - The string to be trimmed.
Returns:
A string containing only the alphanumeric content of value.

trimLeft

public static String trimLeft(String value)
Create a new string from value without leading whitespace.

Parameters:
value - The string to be stripped.
Returns:
A copy of value with leading whitespace stripped.

trimRight

public static String trimRight(String value)
Create a new string from value without trailing whitespace.

Parameters:
value - The string to be stripped.
Returns:
A copy of value with trailing whitespace stripped.

intarsys runtime library

Copyright © 2008 intarsys consulting GmbH. All Rights Reserved.