Package org.eclipse.xtext.util
Class Strings
- java.lang.Object
-
- org.eclipse.xtext.util.Strings
-
public class Strings extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String[]EMPTY_ARRAYstatic charSEPARATOR
-
Constructor Summary
Constructors Constructor Description Strings()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Stringconcat(java.lang.String separator, java.util.List<java.lang.String> list)static java.lang.Stringconcat(java.lang.String separator, java.util.List<java.lang.String> list, int skip)static java.lang.StringconvertFromJavaString(java.lang.String string, boolean useUnicode)Resolve Java control character sequences with to the actual character value.static java.lang.StringconvertToJavaString(java.lang.String theString)Escapes control characters with a preceding backslash.static java.lang.StringconvertToJavaString(java.lang.String input, boolean useUnicode)Escapes control characters with a preceding backslash.static intcountLineBreaks(java.lang.CharSequence text)Counts the number of line breaks.static intcountLineBreaks(java.lang.CharSequence text, int startInclusive, int endExclusive)Counts the number of line breaks.static intcountLines(java.lang.String text)Counts the number of lines whereseparatoris assumed to be the only valid line break sequence.static intcountLines(java.lang.String text, char[] separator)Counts the number of lines where the given separator sequence is the only valid line break sequence.static intcountLines(java.lang.String text, char[] separator, int startInclusive, int endExclusive)Counts the number of lines betweenstartInclusiveandendExclusivewhere the given separator sequence is the only valid line break sequence.static java.lang.StringemptyIfNull(java.lang.String s)static booleanequal(java.lang.String literal, java.lang.String name)static booleanequalsIgnoreWhitespace(java.lang.String left, java.lang.String right)static java.lang.StringgetLeadingWhiteSpace(java.lang.String original)static intgetLevenshteinDistance(java.lang.String from, java.lang.String to)Calculates the Levenshtein text edit distance copied & adapted (cost = 1) from org.eclipse.jdt.internal.ui.text.spelling.engine.DefaultPhoneticDistanceAlgorithmstatic booleanisEmpty(java.lang.String s)static java.lang.StringlastToken(java.lang.String value, java.lang.String separator)static java.lang.StringnewLine()static java.lang.StringnotNull(java.lang.Object o)static java.lang.Stringpack(java.lang.String[] strings)static java.lang.StringremoveLeadingWhitespace(java.lang.String indentationString)static java.lang.StringskipLastToken(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.StringtoFirstLower(java.lang.String s)static java.lang.StringtoFirstUpper(java.lang.String s)static chartoHex(int i)static java.lang.StringtoPlatformLineSeparator(java.lang.CharSequence cs)static <T> java.lang.StringtoString(java.util.Collection<T> list, com.google.common.base.Function<T,java.lang.String> toString, java.lang.String delim)static java.lang.StringtoUnixLineSeparator(java.lang.CharSequence cs)static java.lang.CharSequencetrimTrailingLineBreak(java.lang.CharSequence s)Assumes'\r','\n'or'\r\n'to be valid line breaks.static java.lang.String[]unpack(java.lang.String packed)static java.lang.StringwordWrap(java.lang.String string, int maxCharsPerLine)
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final java.lang.String[] EMPTY_ARRAY
-
SEPARATOR
public static final char SEPARATOR
- See Also:
- Constant Field Values
-
-
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()
-
toPlatformLineSeparator
public static java.lang.String toPlatformLineSeparator(java.lang.CharSequence cs)
- Since:
- 2.13
-
toUnixLineSeparator
public static java.lang.String toUnixLineSeparator(java.lang.CharSequence cs)
- Since:
- 2.14
-
toFirstLower
public static java.lang.String toFirstLower(java.lang.String s)
-
convertFromJavaString
public static java.lang.String convertFromJavaString(java.lang.String string, boolean useUnicode)Resolve Java control character sequences with to the actual character value. Optionally handle unicode escape sequences, too.
-
convertToJavaString
public static java.lang.String convertToJavaString(java.lang.String theString)
Escapes control characters with a preceding backslash. Encodes special chars as unicode escape sequence. The resulting string is safe to be put into a Java string literal between the quotes.
-
convertToJavaString
public static java.lang.String convertToJavaString(java.lang.String input, boolean useUnicode)Escapes control characters with a preceding backslash. Optionally encodes special chars as unicode escape sequence. The resulting string is safe to be put into a Java string literal between the quotes.
-
toHex
public static char toHex(int i)
-
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 splitdelimiter- 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
nulland the list does not contain anynullvalues. - Throws:
java.lang.NullPointerException- If thevalueordelimiterisnull
-
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 splitdelimiter- 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
nulland the list does not contain anynullvalues. - Throws:
java.lang.NullPointerException- If thevalueisnull- 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 benulland may not contain anynullvalues.- Throws:
java.lang.NullPointerException- if the array of strings or any element in the array isnull
-
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. This follows the semantics of theLineNumberReader.- Since:
- 2.3
-
countLineBreaks
public static int countLineBreaks(java.lang.CharSequence text, int startInclusive, int endExclusive)Counts the number of line breaks. Assumes'\r','\n'or'\r\n'to be valid line breaks. This follows the semantics of theLineNumberReader.- Since:
- 2.9
-
trimTrailingLineBreak
public static java.lang.CharSequence trimTrailingLineBreak(java.lang.CharSequence s)
Assumes'\r','\n'or'\r\n'to be valid line breaks.- Since:
- 2.6
-
countLines
public static int countLines(java.lang.String text)
Counts the number of lines whereseparatoris assumed to be the only valid line break sequence. A string without any line separators returns0as the number of lines.
-
countLines
public static int countLines(java.lang.String text, char[] separator)Counts the number of lines where the given separator sequence is the only valid line break sequence. A string without any line separators returns0as the number of lines.
-
countLines
public static int countLines(java.lang.String text, char[] separator, int startInclusive, int endExclusive)Counts the number of lines betweenstartInclusiveandendExclusivewhere the given separator sequence is the only valid line break sequence. A string without any line separators in that range returns0as the number of lines.- Since:
- 2.9
-
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
-
getLevenshteinDistance
public static int getLevenshteinDistance(java.lang.String from, java.lang.String to)Calculates the Levenshtein text edit distance copied & adapted (cost = 1) from org.eclipse.jdt.internal.ui.text.spelling.engine.DefaultPhoneticDistanceAlgorithm- Parameters:
from- source string, may not be nullto- target string, may not be null- Returns:
- Levenshtein distance between from and to
- Since:
- 2.27
-
-