public class StringUtils extends Object
Common String
manipulation routines.
Originally from Turbine and the GenerationJavaCore library.
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
escapeBytesToPrintable(byte[] out,
int outoff,
byte[] input,
int off,
int len)
Escapes the bytes in the array
str to contain only 'printable' bytes. |
static void |
escapeToPrintable(StringBuilder target,
CharSequence str)
Escape the specified string to a representation that only consists of nicely printable characters, without any
newlines and without a comma.
|
static boolean |
isBlank(String str)
Checks if a (trimmed) String is
null or blank. |
static String[] |
split(String text,
String separator) |
static int |
unescapeBytes(byte[] out,
String str)
Reverses the effect of
escapeBytesToPrintable(byte[], int, byte[], int, int) . |
static void |
unescapeString(StringBuilder target,
CharSequence str)
Reverses the effect of
escapeToPrintable(StringBuilder, CharSequence) . |
public static boolean isBlank(String str)
Checks if a (trimmed) String is null
or blank.
str
- the String to checktrue
if the String is null
, or length zero once trimmedpublic static void escapeToPrintable(StringBuilder target, CharSequence str)
The reverse-method is unescapeString(StringBuilder, CharSequence)
.
target
- target string buffer. The required space will be up to str.getBytes().length * 5
chars.str
- String to escape values in, may be null
.public static void unescapeString(StringBuilder target, CharSequence str)
escapeToPrintable(StringBuilder, CharSequence)
.target
- target string bufferstr
- the String to un-escape, as created by escapeToPrintable(StringBuilder, CharSequence)
public static int escapeBytesToPrintable(byte[] out, int outoff, byte[] input, int off, int len)
str
to contain only 'printable' bytes.
Escaping is done by encoding the non-nicely printable bytes to '\' + upperCaseHexBytes(byte)
.
A save length of out
is len * 3 + outoff
.
The reverse-method is unescapeBytes(byte[], String)
.
out
- output bufferoutoff
- offset in the output bufferinput
- input bufferoff
- offset in the input bufferlen
- number of bytes to copy from the input bufferout
public static int unescapeBytes(byte[] out, String str)
escapeBytesToPrintable(byte[], int, byte[], int, int)
.
A save length of out
is str.length()
out
- the target byte arraystr
- the input Stringout
Copyright © 2004–2014 The Apache Software Foundation. All rights reserved.