org.eclipse.xtext.util
Class Strings

java.lang.Object
  extended by org.eclipse.xtext.util.Strings

public class Strings
extends java.lang.Object

Author:
Jan Köhnlein - Initial contribution and API

Field Summary
static java.lang.String[] EMPTY_ARRAY
           
static char SEPARATOR
           
 
Constructor Summary
Strings()
           
 
Method Summary
static java.lang.String concat(java.lang.String separator, java.util.List<java.lang.String> list)
           
static java.lang.String concat(java.lang.String separator, java.util.List<java.lang.String> list, int skip)
           
static java.lang.String convertFromJavaString(java.lang.String javaString, boolean useUnicode)
          Mostly copied from Properties.loadConvert(char[], int, int, char[])
static java.lang.String convertToJavaString(java.lang.String theString)
           
static java.lang.String convertToJavaString(java.lang.String theString, boolean useUnicode)
          Mostly copied from Properties.saveConvert(java.lang.String, boolean)
static int countLineBreaks(java.lang.CharSequence text)
          Counts the number of line breaks.
static int countLines(java.lang.String text)
          Counts the number of lines where separator is assumed to be a valid line break.
static int countLines(java.lang.String text, char[] separator)
           
static java.lang.String emptyIfNull(java.lang.String s)
           
static boolean equal(java.lang.String literal, java.lang.String name)
           
static boolean equalsIgnoreWhitespace(java.lang.String left, java.lang.String right)
           
static java.lang.String getLeadingWhiteSpace(java.lang.String original)
           
static boolean isEmpty(java.lang.String s)
           
static java.lang.String lastToken(java.lang.String value, java.lang.String separator)
           
static java.lang.String newLine()
           
static java.lang.String notNull(java.lang.Object o)
           
static java.lang.String pack(java.lang.String[] strings)
           
static java.lang.String removeLeadingWhitespace(java.lang.String indentationString)
           
static java.lang.String skipLastToken(java.lang.String value, java.lang.String separator)
           
static java.util.List<java.lang.String> split(java.lang.String value, char delimiter)
          Splits a string around matches of the given delimiter character.
static java.util.List<java.lang.String> split(java.lang.String value, java.lang.String delimiter)
          Splits a string around matches of the given delimiter string.
static java.lang.String toFirstLower(java.lang.String s)
           
static java.lang.String toFirstUpper(java.lang.String s)
           
static char toHex(int nibble)
          Copied from Properties
static
<T> java.lang.String
toString(java.util.Collection<T> list, com.google.common.base.Function<T,java.lang.String> toString, java.lang.String delim)
           
static java.lang.String[] unpack(java.lang.String packed)
           
static java.lang.String wordWrap(java.lang.String string, int maxCharsPerLine)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_ARRAY

public static final java.lang.String[] EMPTY_ARRAY

SEPARATOR

public static final char SEPARATOR
See Also:
Constant Field Values
Constructor Detail

Strings

public Strings()
Method Detail

equalsIgnoreWhitespace

public static boolean equalsIgnoreWhitespace(java.lang.String left,
                                             java.lang.String right)

equal

public static boolean equal(java.lang.String literal,
                            java.lang.String name)

notNull

public static java.lang.String notNull(java.lang.Object o)

emptyIfNull

public static java.lang.String emptyIfNull(java.lang.String s)

concat

public static java.lang.String concat(java.lang.String separator,
                                      java.util.List<java.lang.String> list)

toString

public static <T> java.lang.String toString(java.util.Collection<T> list,
                                            com.google.common.base.Function<T,java.lang.String> toString,
                                            java.lang.String delim)

concat

public static java.lang.String concat(java.lang.String separator,
                                      java.util.List<java.lang.String> list,
                                      int skip)

skipLastToken

public static java.lang.String skipLastToken(java.lang.String value,
                                             java.lang.String separator)

lastToken

public static java.lang.String lastToken(java.lang.String value,
                                         java.lang.String separator)

toFirstUpper

public static java.lang.String toFirstUpper(java.lang.String s)

isEmpty

public static boolean isEmpty(java.lang.String s)

newLine

public static java.lang.String newLine()

toFirstLower

public static java.lang.String toFirstLower(java.lang.String s)

convertFromJavaString

public static java.lang.String convertFromJavaString(java.lang.String javaString,
                                                     boolean useUnicode)
Mostly copied from Properties.loadConvert(char[], int, int, char[])


convertToJavaString

public static java.lang.String convertToJavaString(java.lang.String theString)

convertToJavaString

public static java.lang.String convertToJavaString(java.lang.String theString,
                                                   boolean useUnicode)
Mostly copied from Properties.saveConvert(java.lang.String, boolean)


toHex

public static char toHex(int nibble)
Copied from Properties


split

public static java.util.List<java.lang.String> split(java.lang.String value,
                                                     java.lang.String delimiter)
Splits a string around matches of the given delimiter string.

This method works similar to String.split(String) but does not treat the delimiter as a regular expression. This makes it perform better in most cases where this feature is not necessary. Furthermore this implies that trailing empty segments will not be part of the result.

For delimiters of length 1 it is preferred to use split(String, char) instead.

Parameters:
value - the string to split
delimiter - the delimiting string (e.g. "::")
Returns:
the list of strings computed by splitting the string around matches of the given delimiter without trailing empty segments. Never null and the list does not contain any null values.
Throws:
java.lang.NullPointerException - If the value or delimiter is null

split

public static java.util.List<java.lang.String> split(java.lang.String value,
                                                     char delimiter)
Splits a string around matches of the given delimiter character.

This method works similar to String.split(String) but does not treat the delimiter as a regular expression. This makes it perform better in most cases where this feature is not necessary. Furthermore this implies that trailing empty segments will not be part of the result.

Parameters:
value - the string to split
delimiter - the delimiting character (e.g. '.' or ':')
Returns:
the list of strings computed by splitting the string around matches of the given delimiter without trailing empty segments. Never null and the list does not contain any null values.
Throws:
java.lang.NullPointerException - If the value is null
Since:
2.3
See Also:
String.split(String)

pack

public static java.lang.String pack(java.lang.String[] strings)
Parameters:
strings - array of strings, may not be null and may not contain any null values.
Throws:
java.lang.NullPointerException - if the array of strings or any element in the array is null

unpack

public static java.lang.String[] unpack(java.lang.String packed)

removeLeadingWhitespace

public static java.lang.String removeLeadingWhitespace(java.lang.String indentationString)

countLineBreaks

public static int countLineBreaks(java.lang.CharSequence text)
Counts the number of line breaks. Assumes '\r', '\n' or '\r\n' to be valid line breaks.

Since:
2.3

countLines

public static int countLines(java.lang.String text)
Counts the number of lines where separator is assumed to be a valid line break.


countLines

public static int countLines(java.lang.String text,
                             char[] separator)

getLeadingWhiteSpace

public static java.lang.String getLeadingWhiteSpace(java.lang.String original)

wordWrap

public static java.lang.String wordWrap(java.lang.String string,
                                        int maxCharsPerLine)
Since:
2.1