gate.util
Class Strings

java.lang.Object
  extended by gate.util.Strings

public class Strings
extends Object

Some utilities for use with Strings.


Field Summary
private static boolean DEBUG
          Debug flag
private static String fileSep
          Local fashion for file separators.
private static String newline
          Local fashion for newlines this year.
private static char padChar
          What character to pad with.
private static String pathSep
          Local fashion for path separators.
 
Constructor Summary
Strings()
           
 
Method Summary
static String addLineNumbers(String text)
          Helper method to add line numbers to a string
static String addLineNumbers(String text, int startLine)
           
static String addPadding(String pad, int n)
          Add n pad characters to pad.
static String crop(String text, int maxLength)
          Crop the text in the middle if too long.
static String getFileSep()
          Get local fashion for file separators (e.g. "/").
static String getNl()
          Get local fashion for newlines.
static String getPathSep()
          Get local fashion for path separators (e.g. ":").
static List<String> toList(String string, String separator)
          Get back a List of String from its String representation.
static Map<String,String> toMap(String string)
          Get back a Map of String*String from its String representation.
static String toString(List<String> list)
          Create a String representation of a List of String with the format [value, value].
static String toString(Map<String,String> map)
          Create a String representation of a Map of String*String with the format {key=value, key=value}.
static String toString(Object object)
          Convert about any object to a human readable string.
static String unescape(String str)
          A method to unescape Java strings, returning a string containing escape sequences into the respective character. i.e. "\" followed by "t" is turned into the tab character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG
Debug flag

See Also:
Constant Field Values

padChar

private static char padChar
What character to pad with.


newline

private static String newline
Local fashion for newlines this year.


pathSep

private static String pathSep
Local fashion for path separators.


fileSep

private static String fileSep
Local fashion for file separators.

Constructor Detail

Strings

public Strings()
Method Detail

getNl

public static String getNl()
Get local fashion for newlines.


getPathSep

public static String getPathSep()
Get local fashion for path separators (e.g. ":").


getFileSep

public static String getFileSep()
Get local fashion for file separators (e.g. "/").


addPadding

public static String addPadding(String pad,
                                int n)
Add n pad characters to pad.


addLineNumbers

public static String addLineNumbers(String text)
Helper method to add line numbers to a string


addLineNumbers

public static String addLineNumbers(String text,
                                    int startLine)

unescape

public static String unescape(String str)
A method to unescape Java strings, returning a string containing escape sequences into the respective character. i.e. "\" followed by "t" is turned into the tab character.

Parameters:
str - the string to unescape
Returns:
a new unescaped string of the one passed in

toString

public static String toString(Object object)
Convert about any object to a human readable string.
Use Arrays.deepToString(Object[]) to convert an array or a collection.

Parameters:
object - object to be converted to a string
Returns:
a string representation of the object, the empty string if null.

toString

public static String toString(List<String> list)
Create a String representation of a List of String with the format [value, value]. Escape with a backslash the separator character.

Parameters:
list - list to convert to one String
Returns:
a String that represent the list
See Also:
toList(String, String)

toString

public static String toString(Map<String,String> map)
Create a String representation of a Map of String*String with the format {key=value, key=value}. Escape with a backslash the separator characters.

Parameters:
map - map to convert to one String
Returns:
a String that represent the map
See Also:
toMap(String)

toList

public static List<String> toList(String string,
                                  String separator)
Get back a List of String from its String representation. Unescape backslashed separator characters.

Parameters:
string - String to convert to a List
separator - String that delimits the element of the list
Returns:
a List
See Also:
toString(java.util.List)

toMap

public static Map<String,String> toMap(String string)
Get back a Map of String*String from its String representation. Unescape backslashed separator characters.

Parameters:
string - String to convert to a Map
Returns:
a Map
See Also:
toString(java.util.Map)

crop

public static String crop(String text,
                          int maxLength)
Crop the text in the middle if too long.

Parameters:
text - text to crop
maxLength - maximum length of the text
Returns:
cropped text if needed otherwise the same text