Package com.yahoo.text
Class StringUtilities
java.lang.Object
com.yahoo.text.StringUtilities
Escapes strings into and out of a format where they only contain printable characters.
Need to duplicate escape / unescape of strings as we have in C++ for java version of system states.
- Author:
- Haakon Humberset
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringstatic StringEscapes strings into a format with only printable ASCII characters.static StringReturns the given array flattened to string, with the given separator stringstatic StringimplodeMultiline(List<String> lines) Returns the given list flattened to one with newline betweenstatic StringAdds single quotes around object.toString Example: '12'Splits a string on both space and commastatic StringstripSuffix(String string, String suffix) static StringtoHex(byte[] bytes) Returns a String where each byte b in `bytes` is replaced by "%02x".formatted(b).static StringtruncateSequencesIfNecessary(String text, int maxConsecutiveLength) This will truncate sequences in a string of the same character that exceed the maximum allowed length.static String
-
Constructor Details
-
StringUtilities
public StringUtilities()
-
-
Method Details
-
toHex
Returns a String where each byte b in `bytes` is replaced by "%02x".formatted(b). -
escape
-
escape
Escapes strings into a format with only printable ASCII characters.- Parameters:
source- The string to escapedelimiter- Escape this character too, even if it is printable.- Returns:
- The escaped string
-
unescape
-
implode
Returns the given array flattened to string, with the given separator string- Parameters:
array- the arraysepString- or null- Returns:
- imploded array
-
implodeMultiline
Returns the given list flattened to one with newline between- Returns:
- flattened string
-
truncateSequencesIfNecessary
This will truncate sequences in a string of the same character that exceed the maximum allowed length.- Returns:
- The same string or a new one if truncation is done.
-
stripSuffix
-
quote
Adds single quotes around object.toString Example: '12' -
split
Splits a string on both space and comma
-