util
Class StringUtils

java.lang.Object
  extended by util.StringUtils

public class StringUtils
extends java.lang.Object

Static string processing utility data methods.


Field Summary
static java.lang.String EOL
          The end-of-line string for the current platform.
 
Method Summary
static java.lang.String intField(int i, int w)
          Generates the string representation of an integer value, left justified in a field of the specified width (using a space as the padding character).
static int iVal(java.lang.String s, java.lang.String errmsg)
          Decode a String as an integer value, and output an error message in the case of a format error.
static java.lang.String[] linesToAllStrings(java.lang.String lns)
          Converts the given multi-line string into an array of strings, retaining any blank lines present in the original.
static java.lang.String linesToOneString(java.lang.String[] lnstrs)
          Converts the given array of strings representing lines into a single multi-line string.
static java.lang.String linesToOneString(java.lang.String[] lnstrs, int estlen)
          Converts the given array of strings representing lines into a single multi-line string.
static java.lang.String[] linesToStrings(java.lang.String lns)
          Converts the given multi-line string into an array of strings that excludes any blank lines.
static int nnProp(java.lang.String s, java.lang.String ptag)
          Finds and decodes a non-negative integer property value, as defined in the given string.
static int nnVal(java.lang.String s, int b, java.lang.String errmsg)
          Parses the given string to give a non-negative integer value relative to the given base, and outputs an error message in the case of a format error.
static int nnVal(java.lang.String s, java.lang.String errmsg)
          Parses the given string to give a non-negative integer value (assuming base 10), and outputs an error message in the case of a format error.
static java.lang.String[] readLines(java.io.InputStream ins)
          Reads lines of text from the given input stream, returning them as an array of strings.
static java.lang.String readText(java.io.InputStream ins)
          Reads lines of text from the given input stream, and returns the result as a single string in which adjacent lines are separated by the platform line separator.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOL

public static final java.lang.String EOL
The end-of-line string for the current platform.

Method Detail

intField

public static java.lang.String intField(int i,
                                        int w)
Generates the string representation of an integer value, left justified in a field of the specified width (using a space as the padding character).

Parameters:
i - The integer value whose representation is required.
w - The required length for the result String. Not expected to be negative (treated as zero if so).
Returns:
A string representing the given integer, padded to the required width if necessary. (The String is not truncated if the length of the integer representation exceeds that required.)

nnVal

public static int nnVal(java.lang.String s,
                        int b,
                        java.lang.String errmsg)
Parses the given string to give a non-negative integer value relative to the given base, and outputs an error message in the case of a format error.

Parameters:
s - The string to be parsed.
b - The base relative to which s is to be parsed.
errmsg - The error message to be displayed on the standard error stream in the case of a NumberFormatException, or null if no message is to be displayed.
Returns:
The non-negative integer value corresponding to the given string, or -1 in the case of a format error.

nnVal

public static int nnVal(java.lang.String s,
                        java.lang.String errmsg)
Parses the given string to give a non-negative integer value (assuming base 10), and outputs an error message in the case of a format error.

Parameters:
s - The string to be parsed.
errmsg - The error message to be displayed on the standard error stream in the case of a NumberFormatException, or null if no message is to be displayed.
Returns:
The non-negative integer value corresponding to the given String, or -1 in the case of a format error.

iVal

public static int iVal(java.lang.String s,
                       java.lang.String errmsg)
Decode a String as an integer value, and output an error message in the case of a format error.

Parameters:
s - The String to be decoded.
errmsg - The error message to be displayed on the standard error stream in the case of a NumberFormatException, or null if no message is to be displayed.
Returns:
The integer value corresponding to the given String, or zero in the case of a format error.

nnProp

public static int nnProp(java.lang.String s,
                         java.lang.String ptag)
Finds and decodes a non-negative integer property value, as defined in the given string.

Parameters:
s - The String to be searched (for a substring of the form "ptag=NNNN").
ptag - The property name to be searched for.
Returns:
The integer value defined for this property name, or -1 in the case of any kind of format error.

linesToStrings

public static java.lang.String[] linesToStrings(java.lang.String lns)
Converts the given multi-line string into an array of strings that excludes any blank lines.

Parameters:
lns - The multi-line string to be converted.
Returns:
An array of strings representing the non-empty lines in lns.

linesToAllStrings

public static java.lang.String[] linesToAllStrings(java.lang.String lns)
Converts the given multi-line string into an array of strings, retaining any blank lines present in the original.

Parameters:
lns - The multi-line string to be converted.
Returns:
An array of strings representing the lines in lns.

linesToOneString

public static java.lang.String linesToOneString(java.lang.String[] lnstrs)
Converts the given array of strings representing lines into a single multi-line string.

Parameters:
lnstrs - The array of line strings.
Returns:
The string obtained by stringing together the elements of lnstrs, using the standard line separator.

linesToOneString

public static java.lang.String linesToOneString(java.lang.String[] lnstrs,
                                                int estlen)
Converts the given array of strings representing lines into a single multi-line string.

Parameters:
lnstrs - The array of line strings.
estlen - An estimate of the average length of each line (used to determine size of pre-allocated storage).
Returns:
The string obtained by stringing together the elements of lnstrs, using the standard line separator.

readText

public static final java.lang.String readText(java.io.InputStream ins)
                                       throws java.io.IOException
Reads lines of text from the given input stream, and returns the result as a single string in which adjacent lines are separated by the platform line separator. as an array of strings.

Parameters:
ins - The stream to be read (standard encoding assumed).
Returns:
A string containing the lines of input text separated from one another by standard line separators.
Throws:
java.io.IOException - An I/O error occurred.

readLines

public static final java.lang.String[] readLines(java.io.InputStream ins)
                                          throws java.io.IOException
Reads lines of text from the given input stream, returning them as an array of strings.

Parameters:
ins - The stream to be read (standard encoding assumed).
Returns:
The lines as an array of strings.
Throws:
java.io.IOException - An I/O error occurred.