Package com.yahoo.text
Class StringUtilities
- java.lang.Object
-
- com.yahoo.text.StringUtilities
-
public class StringUtilities extends Object
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 Constructor Description StringUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
escape(String source)
static String
escape(String source, char delimiter)
Escapes strings into a format with only printable ASCII characters.static String
implode(String[] array, String sepString)
Returns the given array flattened to string, with the given separator stringstatic String
implodeMultiline(List<String> lines)
Returns the given list flattened to one with newline betweenstatic String
quote(Object object)
Adds single quotes around object.toString Example: '12'static Set<String>
split(String s)
Splits a string on both space and commastatic String
stripSuffix(String string, String suffix)
static String
truncateSequencesIfNecessary(String text, int maxConsecutiveLength)
This will truncate sequences in a string of the same character that exceed the maximum allowed length.static String
unescape(String source)
-
-
-
Method Detail
-
escape
public static String escape(String source, char delimiter)
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
-
implode
public static String implode(String[] array, String sepString)
Returns the given array flattened to string, with the given separator string- Parameters:
array
- the arraysepString
- or null- Returns:
- imploded array
-
implodeMultiline
public static String implodeMultiline(List<String> lines)
Returns the given list flattened to one with newline between- Returns:
- flattened string
-
truncateSequencesIfNecessary
public static String truncateSequencesIfNecessary(String text, int maxConsecutiveLength)
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.
-
quote
public static String quote(Object object)
Adds single quotes around object.toString Example: '12'
-
-