Class Strings


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

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  Strings.PatternState  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String DL  
      (package private) static java.util.List<java.lang.String> JAVA_CHAR_CLASSES  
      (package private) static java.util.List<java.lang.String> POSIX_CHAR_CLASSES  
      (package private) static java.util.regex.Pattern UNSUPPORTED  
    • Constructor Summary

      Constructors 
      Constructor Description
      Strings()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String checkPosixCharClass​(char[] buffer)  
      (package private) static Strings.PatternState checkWildCards​(java.lang.String pattern)  
      (package private) static java.util.regex.Pattern convertGlob​(java.lang.String pattern)
      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.
      (package private) static int count​(java.lang.String s, char c, boolean ignoreFirstLast)  
      (package private) static java.lang.String deleteBackslash​(java.lang.String s)  
      private static boolean escapedByBackslash​(char nextChar)  
      (package private) static char getPathSeparator​(java.lang.Character pathSeparator)  
      private static boolean isComplexWildcard​(java.lang.String pattern)  
      static boolean isDirectoryPattern​(java.lang.String pattern)
      Check if pattern is a directory pattern ending with a path separator
      (package private) static boolean isWildCard​(java.lang.String pattern)  
      private static char lookAhead​(java.lang.String pattern, int i)  
      private static char lookBehind​(java.lang.StringBuilder buffer)  
      private static void reset​(char[] buffer)  
      private static void setNext​(char[] buffer, char c)  
      static java.util.List<java.lang.String> split​(java.lang.String pattern, char slash)
      Splits given string to substrings by given separator
      static java.lang.String stripTrailing​(java.lang.String pattern, char c)
      Strip trailing characters
      static java.lang.String stripTrailingWhitespace​(java.lang.String pattern)
      Strip trailing whitespace characters
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • POSIX_CHAR_CLASSES

        static final java.util.List<java.lang.String> POSIX_CHAR_CLASSES
      • JAVA_CHAR_CLASSES

        static final java.util.List<java.lang.String> JAVA_CHAR_CLASSES
      • UNSUPPORTED

        static final java.util.regex.Pattern UNSUPPORTED
    • Constructor Detail

      • Strings

        public Strings()
    • Method Detail

      • getPathSeparator

        static char getPathSeparator​(java.lang.Character pathSeparator)
      • stripTrailing

        public static java.lang.String stripTrailing​(java.lang.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 java.lang.String stripTrailingWhitespace​(java.lang.String pattern)
        Strip trailing whitespace characters
        Parameters:
        pattern - non null
        Returns:
        new string with all trailing whitespace removed
      • isDirectoryPattern

        public static boolean isDirectoryPattern​(java.lang.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​(java.lang.String s,
                         char c,
                         boolean ignoreFirstLast)
      • split

        public static java.util.List<java.lang.String> split​(java.lang.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​(java.lang.String pattern)
      • isComplexWildcard

        private static boolean isComplexWildcard​(java.lang.String pattern)
      • escapedByBackslash

        private static boolean escapedByBackslash​(char nextChar)
      • convertGlob

        static java.util.regex.Pattern convertGlob​(java.lang.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