Package org.eclipse.lemminx.utils
Class StringUtils
java.lang.Object
org.eclipse.lemminx.utils.StringUtils
String utilities.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String[]static final Stringstatic final Stringstatic final Collection<String> -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcleanPathForWindows(String pathString) static StringconvertToQuotelessValue(String value) Returnsvaluewithout surrounding quotes.static StringescapeBackticks(String text) static intfindEndWord(String text, int offset, int max, Predicate<Character> isValidChar) Returns the end word offset from the right of the givenoffsetto the givenmaxand -1 if no word.static intfindEndWord(String text, int offset, Predicate<Character> isValidChar) Returns the end word offset from the right of the givenoffsetand -1 if no word.static intfindStartWord(String text, int offset, int min, Predicate<Character> isValidChar) Returns the start word offset from the left of the givenoffsetto the givenminand -1 if no word.static intfindStartWord(String text, int offset, Predicate<Character> isValidChar) Returns the start word offset from the left of the givenoffsetand -1 if no word.static StringgetDefaultString(String text) Given a string will give back a non null string that is either the given string, or an empty string.static intReturns the number of consecutive whitespace characters in front of textstatic intgetNumberOfNewLines(String text, boolean isWhitespace, String delimiter, int newLineLimit) Given a string that is only whitespace, this will return the amount of newline characters.static intgetOffsetAfterWhitespace(String text, int endOffset) Traverses backwards from the endOffset until it finds a whitespace character.static StringgetStartWhitespaces(String lineText) Returns the start whitespaces of the given line text.static Stringstatic intReturns the number of consecutive whitespace characters from the end of textstatic StringgetWhitespaces(String text, int start, int end) Returns the whitespaces from the given range start/end of the given text.static booleanChecks if a string is null or consists of only whitespace characters.static booleanstatic booleanisQuote(char c) static booleanReturns true ifvaluehas matching surrounding quotes and false otherwise.static booleanUses Levenshtein distance to determine similarity between stringsstatic booleanstatic booleanisWhitespace(String value) static booleanisWhitespace(String value, int index) static booleanisWhitespace(String value, int index, int end) static Stringstatic StringnormalizeSpace(String str) Returns the result of normalize space of the given string.static voidnormalizeSpace(String str, StringBuilder b) Normalizes the whitespace characters of a given string and applies it to the given string builder.static StringtrimNewLines(String value) static voidtrimNewLines(String value, StringBuilder s)
-
Field Details
-
EMPTY_STRING
-
TRUE
- See Also:
-
FALSE
- See Also:
-
TRUE_FALSE_ARRAY
-
-
Method Details
-
isEmpty
-
isQuote
public static boolean isQuote(char c) -
isWhitespace
-
isWhitespace
-
isWhitespace
-
isBlank
Checks if a string is null or consists of only whitespace characters.- Parameters:
value- The string to check- Returns:
trueif any of the below hold, and false otherwise:- The String is
null - The String is of length 0
- The String contains only whitespace characters
- The String is
-
normalizeSpace
Normalizes the whitespace characters of a given string and applies it to the given string builder.- Parameters:
str-
-
normalizeSpace
Returns the result of normalize space of the given string.- Parameters:
str-- Returns:
- the result of normalize space of the given string.
-
getStartWhitespaces
Returns the start whitespaces of the given line text.- Parameters:
lineText-- Returns:
- the start whitespaces of the given line text.
-
getWhitespaces
Returns the whitespaces from the given range start/end of the given text.- Parameters:
start- the range startend- the range endtext- the text- Returns:
- the whitespaces from the given range start/end of the given text.
-
trimNewLines
-
trimNewLines
-
lTrim
-
getNumberOfNewLines
public static int getNumberOfNewLines(String text, boolean isWhitespace, String delimiter, int newLineLimit) Given a string that is only whitespace, this will return the amount of newline characters. If the newLineCounter becomes > newLineLimit, then the value of newLineLimit is always returned.- Parameters:
text-isWhitespace-delimiter-- Returns:
-
getDefaultString
Given a string will give back a non null string that is either the given string, or an empty string.- Parameters:
text-- Returns:
-
getOffsetAfterWhitespace
Traverses backwards from the endOffset until it finds a whitespace character. The offset of the character after the whitespace is returned. (text = "abcd efg|h", endOffset = 8) -> 5- Parameters:
text-endOffset- non-inclusive- Returns:
- Start offset directly after the first whitespace.
-
getFrontWhitespaceLength
Returns the number of consecutive whitespace characters in front of text- Parameters:
text- String of interest- Returns:
- the number of consecutive whitespace characters in front of text
-
getTrailingWhitespaceLength
Returns the number of consecutive whitespace characters from the end of text- Parameters:
text- String of interest- Returns:
- the number of consecutive whitespace characters from the end of text
-
cleanPathForWindows
-
escapeBackticks
-
isTagOutsideOfBackticks
-
getString
-
findStartWord
Returns the start word offset from the left of the givenoffsetand -1 if no word.- Parameters:
text- the textoffset- the offsetisValidChar- predicate to check if current character belong to the word.- Returns:
- the start word offset from the left of the given
offsetand -1 if no word.
-
findStartWord
Returns the start word offset from the left of the givenoffsetto the givenminand -1 if no word.- Parameters:
text- the textoffset- the offsetmin- the minimum left offset.isValidChar- predicate to check if current character belong to the word.- Returns:
- the start word offset from the left of the given
offsetto the givenminand -1 if no word.
-
findEndWord
Returns the end word offset from the right of the givenoffsetand -1 if no word.- Parameters:
text- the textoffset- the offsetisValidChar- predicate to check if current character belong to the word.- Returns:
- the start word offset from the right of the given
offsetand -1 if no word.
-
findEndWord
Returns the end word offset from the right of the givenoffsetto the givenmaxand -1 if no word.- Parameters:
text- the textoffset- the offsetisValidChar- predicate to check if current character belong to the word.- Returns:
- the start word offset from the right of the given
offsetand -1 if no word.
-
convertToQuotelessValue
Returnsvaluewithout surrounding quotes. Ifvaluedoes not have matching surrounding quotes, returnsvalue.- Parameters:
value-- Returns:
valuewithout surrounding quotes.
-
isQuoted
Returns true ifvaluehas matching surrounding quotes and false otherwise.- Parameters:
value-- Returns:
- true if
valuehas matching surrounding quotes.
-
isSimilar
Uses Levenshtein distance to determine similarity between strings- Parameters:
reference- the string being compared tocurrent- the string compared- Returns:
- true if the two strings are similar, false otherwise
-