Class Strings

java.lang.Object
aQute.lib.strings.Strings

public class Strings extends Object
  • Field Details

    • COMMA

      private static final String COMMA
      See Also:
    • SIMPLE_LIST_SPLITTER

      private static final Pattern SIMPLE_LIST_SPLITTER
    • SIMPLE_LINE_SPLITTER

      private static final Pattern SIMPLE_LINE_SPLITTER
  • Constructor Details

    • Strings

      public Strings()
  • Method Details

    • join

      public static String join(String middle, Iterable<?> objects)
    • join

      public static String join(Iterable<?> objects)
    • join

      public static String join(String middle, Iterable<?> objects, Pattern pattern, String replace)
    • join

      public static void join(StringBuilder sb, String middle, Iterable<?> objects, Pattern pattern, String replace)
    • join

      public static String join(String middle, Object[] segments)
    • joining

      public static Collector<CharSequence,?,String> joining()
    • joining

      public static Collector<CharSequence,?,String> joining(CharSequence delimiter, CharSequence prefix, CharSequence suffix, CharSequence emptyValue)
    • display

      public static String display(Object o, Object... ifNull)
    • join

      public static String join(String... strings)
    • join

      public static String join(Object... strings)
    • getLastSegment

      public static String getLastSegment(String name, char c)
    • getLastSegment

      public static String getLastSegment(String name)
    • trim

      public static String trim(String s)
    • notEmpty

      public static boolean notEmpty(String s)
    • nonNullOrEmpty

      public static boolean nonNullOrEmpty(String s)
    • nonNullOrTrimmedEmpty

      public static boolean nonNullOrTrimmedEmpty(String s)
    • splitAsStream

      public static Stream<String> splitAsStream(String s)
    • splitAsStream

      public static Stream<String> splitAsStream(String s, Pattern splitter)
    • split

      public static List<String> split(String s)
    • split

      public static List<String> split(String s, Pattern splitter)
    • splitQuotedAsStream

      public static Stream<String> splitQuotedAsStream(String s)
    • splitQuotedAsStream

      public static Stream<String> splitQuotedAsStream(String s, String separators)
    • splitQuotedAsStream

      public static Stream<String> splitQuotedAsStream(String s, boolean retainQuotes)
    • splitQuotedAsStream

      public static Stream<String> splitQuotedAsStream(String s, String separators, boolean retainQuotes)
    • splitLinesAsStream

      public static Stream<String> splitLinesAsStream(String s)
    • splitLines

      public static List<String> splitLines(String s)
    • splitQuoted

      public static List<String> splitQuoted(String s)
    • splitQuoted

      public static List<String> splitQuoted(String s, String separators)
    • split

      public static List<String> split(String regex, String s)
    • in

      public static boolean in(String[] skip, String key)
    • charAt

      public static char charAt(String s, int n)
    • from

      public static String from(String s, int n)
    • substring

      public static String substring(String s, int begin, int end)
    • substring

      public static String substring(String s, int begin, int end, int stride)
    • delete

      public static String delete(String s, int begin, int end)
    • to

      public static String to(String s, int end)
    • adjustBegin

      public static int adjustBegin(String s, int n)
    • adjustEnd

      public static int adjustEnd(String s, int n)
    • extension

      public static String[] extension(String s)
      Split a string into a base and an extension.
      Parameters:
      s - the string that contains an extension
      Returns:
      null if no extension or an array of 2 elements, first is the prefix and second is the extension without a '.'
    • lastPathSegment

      public static String[] lastPathSegment(String s)
      Split a path (/ based) into a prefix and a last segment
      Parameters:
      s - the string that contains a path
      Returns:
      null if no extension or an array of 2 elements, first is the prefix and second is the last segment without a '/' at the start
    • last

      public static String[] last(String s, char separator)
      Split a string into a prefix and a suffix based on the last time the separator appears
      Parameters:
      s - the string that contains a path
      Returns:
      null if no suffix or an array of 2 elements, first is the prefix and second is the suffix without the separator at the start
    • first

      public static String[] first(String s, char separator)
    • stripPrefix

      public static String stripPrefix(String s, String prefix)
    • stripPrefix

      public static String stripPrefix(String s, Pattern p)
    • stripSuffix

      public static String stripSuffix(String s, String suffix)
    • stripSuffix

      public static String stripSuffix(String s, Pattern p)
    • ensureSuffix

      public static String ensureSuffix(String s, String suffix)
    • ensurePrefix

      public static String ensurePrefix(String s, String prefix)
    • times

      public static String times(String s, int times)
    • format

      public static String format(String string, Object... parms)
      This method is the same as String.format but it makes sure that any arrays are transformed to strings.
      Parameters:
      string -
      parms -
    • makePrintableArray

      private static Object[] makePrintableArray(Object array)
    • makePrintable

      private static Object makePrintable(Object object)
    • compareExcept

      public static boolean compareExcept(String a, String b, Pattern pattern)
      Compare two strings except for where the first group in pattern. The patterns is matched in the strings using find(). Only group 1 is ignored. Use ignored groups (?:...) to ignore irrelevant groups.
                      a = "abcdefxxxxghixxxxx678"
                      b = "abcdefxxghix678"
                      Pattern "(x+)"
       
      First developed to compare two XML files that only differed in their increment number, which was a time long.
      Parameters:
      a - the first string to compare
      b - the second string to compare
      pattern - where first group should be ignored in the comparison
      Returns:
      true if the strings are equal ignoring the first group's pattern matches
    • toString

      public static String toString(double n, String suffix)
    • escape

      public static String escape(String string, Pattern illegalCharacters, char escape)
      Escape illegal characters in a string with an escape character and the 4-digit hex Unicode encoding. A string escaped like this can be unescaped with unescape(String, char) using the same escape character.
      Parameters:
      string - a string to be escaped
      illegalCharacters - a pattern matching illegal characters, must include the escape character
      escape - an escape character, must be included in the illegalCharacters
      Returns:
      a string that does not contain the illegalCharacters except the escape
    • unescape

      public static Optional<String> unescape(String string, char escape)
      Unescape a string with the given escape character. There must be 4 hex digits after each escape character.
      Parameters:
      string - the string to unescape, can be null
      escape - the escape character
      Returns:
      an Optional, present if the escaping was successful
    • removeQuotes

      public static String removeQuotes(String s)