Package aQute.lib.strings
Class Strings
java.lang.Object
aQute.lib.strings.Strings
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static enum
Convert a number to a string using SI magnitude prefixes like Mega, Giga, etc. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
adjustBegin
(String s, int n) static int
static char
static boolean
compareExcept
(String a, String b, Pattern pattern) Compare two strings except for where the first group in pattern.static String
static String
static String
ensurePrefix
(String s, String prefix) static String
ensureSuffix
(String s, String suffix) static String
Escape illegal characters in a string with an escape character and the 4-digit hex Unicode encoding.static String[]
Split a string into a base and an extension.static String[]
static String
This method is the same as String.format but it makes sure that any arrays are transformed to strings.static String
static String
getLastSegment
(String name) static String
getLastSegment
(String name, char c) static boolean
static String
static String
static String
static void
static String
static String
static String
static Collector<CharSequence,
?, String> joining()
static Collector<CharSequence,
?, String> joining
(CharSequence delimiter, CharSequence prefix, CharSequence suffix, CharSequence emptyValue) static String[]
Split a string into a prefix and a suffix based on the last time the separator appearsstatic String[]
Split a path (/ based) into a prefix and a last segmentprivate static Object
makePrintable
(Object object) private static Object[]
makePrintableArray
(Object array) static boolean
static boolean
static boolean
static String
splitAsStream
(String s, Pattern splitter) splitLines
(String s) splitQuoted
(String s, String separators) splitQuotedAsStream
(String s, boolean retainQuotes) splitQuotedAsStream
(String s, String separators) splitQuotedAsStream
(String s, String separators, boolean retainQuotes) static String
stripPrefix
(String s, String prefix) static String
stripPrefix
(String s, Pattern p) static String
stripSuffix
(String s, String suffix) static String
stripSuffix
(String s, Pattern p) static String
static String
static String
static String
static String
static String
Unescape a string with the given escape character.
-
Field Details
-
COMMA
- See Also:
-
SIMPLE_LIST_SPLITTER
-
SIMPLE_LINE_SPLITTER
-
-
Constructor Details
-
Strings
public Strings()
-
-
Method Details
-
join
-
join
-
join
-
join
public static void join(StringBuilder sb, String middle, Iterable<?> objects, Pattern pattern, String replace) -
join
-
joining
-
joining
public static Collector<CharSequence,?, joiningString> (CharSequence delimiter, CharSequence prefix, CharSequence suffix, CharSequence emptyValue) -
display
-
join
-
join
-
getLastSegment
-
getLastSegment
-
trim
-
notEmpty
-
nonNullOrEmpty
-
nonNullOrTrimmedEmpty
-
splitAsStream
-
splitAsStream
-
split
-
split
-
splitQuotedAsStream
-
splitQuotedAsStream
-
splitQuotedAsStream
-
splitQuotedAsStream
-
splitLinesAsStream
-
splitLines
-
splitQuoted
-
splitQuoted
-
split
-
in
-
charAt
-
from
-
substring
-
substring
-
delete
-
to
-
adjustBegin
-
adjustEnd
-
extension
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
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
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
-
stripPrefix
-
stripPrefix
-
stripSuffix
-
stripSuffix
-
ensureSuffix
-
ensurePrefix
-
times
-
format
This method is the same as String.format but it makes sure that any arrays are transformed to strings.- Parameters:
string
-parms
-
-
makePrintableArray
-
makePrintable
-
compareExcept
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 compareb
- the second string to comparepattern
- where first group should be ignored in the comparison- Returns:
- true if the strings are equal ignoring the first group's pattern matches
-
toString
-
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 withunescape(String, char)
using the same escape character.- Parameters:
string
- a string to be escapedillegalCharacters
- a pattern matching illegal characters, must include the escape characterescape
- an escape character, must be included in the illegalCharacters- Returns:
- a string that does not contain the illegalCharacters except the escape
-
unescape
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 nullescape
- the escape character- Returns:
- an Optional, present if the escaping was successful
-
removeQuotes
-