Class StringUtils

java.lang.Object
org.eclipse.lemminx.utils.StringUtils

public class StringUtils extends Object
String utilities.
  • Field Details

  • Method Details

    • isEmpty

      public static boolean isEmpty(String value)
    • isQuote

      public static boolean isQuote(char c)
    • getString

      public static String getString(CharSequence text, int start, int end)
      Returns a String from the given CharSequence between the given start and end offsets.
      Parameters:
      text - the character sequence.
      start - the start offset.
      end - the end offset.
      Returns:
      a String from the given CharSequence between the given start and end offsets.
    • indexOf

      public static int indexOf(CharSequence text, char ch, int fromIndex)
      Returns the index within the given CharSequence of the first occurrence of the specified character, starting the search at the given index.
      Parameters:
      text - the character sequence.
      ch - the character to search for.
      fromIndex - the index to start the search from.
      Returns:
      the index of the first occurrence of the character, or -1 if not found.
    • isWhitespace

      public static boolean isWhitespace(String value, int index)
    • isWhitespace

      public static boolean isWhitespace(CharSequence value, int index, int end)
    • isWhitespace

      public static boolean isWhitespace(String value)
    • isBlank

      public static boolean isBlank(String value)
      Checks if a string is null or consists of only whitespace characters.
      Parameters:
      value - The string to check
      Returns:
      true if any of the below hold, and false otherwise:
      • The String is null
      • The String is of length 0
      • The String contains only whitespace characters
    • normalizeSpace

      public static void normalizeSpace(String str, StringBuilder b)
      Normalizes the whitespace characters of a given string and applies it to the given string builder.
      Parameters:
      str -
    • normalizeSpace

      public static String normalizeSpace(String str)
      Returns the result of normalize space of the given string.
      Parameters:
      str -
      Returns:
      the result of normalize space of the given string.
    • getStartWhitespaces

      public static String getStartWhitespaces(String lineText)
      Returns the start whitespaces of the given line text.
      Parameters:
      lineText -
      Returns:
      the start whitespaces of the given line text.
    • getWhitespaces

      public static String getWhitespaces(CharSequence text, int start, int end)
      Returns the whitespaces from the given range start/end of the given text.
      Parameters:
      text - the text
      start - the range start
      end - the range end
      Returns:
      the whitespaces from the given range start/end of the given text.
    • trimNewLines

      public static void trimNewLines(String value, StringBuilder s)
    • trimNewLines

      public static String trimNewLines(String value)
    • lTrim

      public static String lTrim(String value)
    • 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

      public static String getDefaultString(String text)
      Given a string will give back a non null string that is either the given string, or an empty string.
      Parameters:
      text -
      Returns:
    • getOffsetAfterWhitespace

      public static int getOffsetAfterWhitespace(String text, int endOffset)
      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

      public static int getFrontWhitespaceLength(String text)
      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

      public static int getTrailingWhitespaceLength(String text)
      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

      public static String cleanPathForWindows(String pathString)
    • escapeBackticks

      public static String escapeBackticks(String text)
    • isTagOutsideOfBackticks

      public static boolean isTagOutsideOfBackticks(String text)
    • getString

      public static String getString(Object obj)
    • findStartWord

      public static int findStartWord(CharSequence text, int offset, Predicate<Character> isValidChar)
      Returns the start word offset from the left of the given offset and -1 if no word.
      Parameters:
      text - the text
      offset - the offset
      isValidChar - predicate to check if current character belong to the word.
      Returns:
      the start word offset from the left of the given offset and -1 if no word.
    • findStartWord

      public static int findStartWord(CharSequence text, int offset, int min, Predicate<Character> isValidChar)
      Returns the start word offset from the left of the given offset to the given min and -1 if no word.
      Parameters:
      text - the text
      offset - the offset
      min - 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 offset to the given min and -1 if no word.
    • findEndWord

      public static int findEndWord(CharSequence text, int offset, Predicate<Character> isValidChar)
      Returns the end word offset from the right of the given offset and -1 if no word.
      Parameters:
      text - the text
      offset - the offset
      isValidChar - predicate to check if current character belong to the word.
      Returns:
      the start word offset from the right of the given offset and -1 if no word.
    • findEndWord

      public static int findEndWord(CharSequence text, int offset, int max, Predicate<Character> isValidChar)
      Returns the end word offset from the right of the given offset to the given max and -1 if no word.
      Parameters:
      text - the text
      offset - the offset
      isValidChar - predicate to check if current character belong to the word.
      Returns:
      the start word offset from the right of the given offset and -1 if no word.
    • convertToQuotelessValue

      public static String convertToQuotelessValue(String value)
      Returns value without surrounding quotes. If value does not have matching surrounding quotes, returns value.
      Parameters:
      value -
      Returns:
      value without surrounding quotes.
    • isQuoted

      public static boolean isQuoted(String value)
      Returns true if value has matching surrounding quotes and false otherwise.
      Parameters:
      value -
      Returns:
      true if value has matching surrounding quotes.
    • isSimilar

      public static boolean isSimilar(String reference, String current)
      Uses Levenshtein distance to determine similarity between strings
      Parameters:
      reference - the string being compared to
      current - the string compared
      Returns:
      true if the two strings are similar, false otherwise