Class Strings

java.lang.Object
org.eclipse.jgit.ignore.internal.Strings

public class Strings extends Object
Various String related utility methods, written mostly to avoid generation of new String objects (e.g. via splitting Strings etc).
  • Field Details

  • Constructor Details

    • Strings

      public Strings()
  • Method Details

    • getPathSeparator

      static char getPathSeparator(Character pathSeparator)
    • stripTrailing

      public static String stripTrailing(String pattern, char c)
      Strip trailing characters
      Parameters:
      pattern - non null
      c - character to remove
      Returns:
      new string with all trailing characters removed
    • stripTrailingWhitespace

      public static String stripTrailingWhitespace(String pattern)
      Strip trailing whitespace characters
      Parameters:
      pattern - non null
      Returns:
      new string with all trailing whitespace removed
    • isDirectoryPattern

      public static boolean isDirectoryPattern(String pattern)
      Check if pattern is a directory pattern ending with a path separator
      Parameters:
      pattern - non null
      Returns:
      true if the last character, which is not whitespace, is a path separator
    • count

      static int count(String s, char c, boolean ignoreFirstLast)
    • split

      public static List<String> split(String pattern, char slash)
      Splits given string to substrings by given separator
      Parameters:
      pattern - non null
      slash - separator char
      Returns:
      list of substrings
    • isWildCard

      static boolean isWildCard(String pattern)
    • isComplexWildcard

      private static boolean isComplexWildcard(String pattern)
    • escapedByBackslash

      private static boolean escapedByBackslash(char nextChar)
    • checkWildCards

      static Strings.PatternState checkWildCards(String pattern)
    • convertGlob

      static Pattern convertGlob(String pattern) throws InvalidPatternException
      Conversion from glob to Java regex following two sources:
    • http://man7.org/linux/man-pages/man7/glob.7.html
    • org.eclipse.jgit.fnmatch.FileNameMatcher.java Seems that there are various ways to define what "glob" can be.
    • Parameters:
      pattern - non null pattern
      Returns:
      Java regex pattern corresponding to given glob pattern
      Throws:
      InvalidPatternException
    • lookBehind

      private static char lookBehind(StringBuilder buffer)
      Parameters:
      buffer -
      Returns:
      zero of the buffer is empty, otherwise the last character from buffer
    • lookAhead

      private static char lookAhead(String pattern, int i)
      Parameters:
      pattern -
      i - current pointer in the pattern
      Returns:
      zero of the index is out of range, otherwise the next character from given position
    • setNext

      private static void setNext(char[] buffer, char c)
    • reset

      private static void reset(char[] buffer)
    • checkPosixCharClass

      private static String checkPosixCharClass(char[] buffer)
    • deleteBackslash

      static String deleteBackslash(String s)