public class StringUtil
extends java.lang.Object
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
array(T... elements) |
static java.lang.String |
combine(java.lang.String sep,
java.lang.String... s) |
static java.lang.String |
d2s(java.lang.Double d) |
static java.lang.String |
join(java.lang.String... s) |
static <T> java.lang.String |
ltos(java.util.Collection<T> l,
java.lang.Character c)
Converts a collection to a string, separating the elements by ","
|
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
parseQuery(java.lang.String s)
Taken from HttpUtils.java and modified
Parses a query string passed from the client to the
server and builds a
HashTable object
with key-value pairs. |
static java.lang.String |
quote(java.lang.String s) |
static java.util.List<java.lang.String> |
stol(java.lang.String s)
Converts a string to a list
|
static java.lang.String |
trim(java.lang.String data)
Remove leading/trailing spaces and any newlines.
|
static java.lang.String |
unquote(java.lang.String s) |
static java.lang.String |
urldecode(java.lang.String encodedText,
java.lang.String contentType)
URL-decode a string, if needed
|
static java.lang.String |
urlencode(java.lang.String text) |
static java.lang.String |
wrap(java.lang.String s,
char c,
int lineLength,
int leps,
int reps)
Wrap a long string in multiple lines
|
static java.lang.String |
wrap(java.lang.String s,
int lineLength)
Wrap a long string in multiple lines
|
public static java.lang.String trim(java.lang.String data)
data
- String to be trimmedpublic static java.lang.String wrap(java.lang.String s, int lineLength)
s
- the stringlineLength
- the preferred line lengthpublic static java.lang.String wrap(java.lang.String s, char c, int lineLength, int leps, int reps)
s
- the stringc
- the preferred char on which to split the string (usually ' ')lineLength
- the preferred line lengthleps
- tolerance to the left of lineLength
reps
- tolerance to the right of lineLength
public static java.lang.String quote(java.lang.String s)
public static java.lang.String unquote(java.lang.String s)
public static java.lang.String combine(java.lang.String sep, java.lang.String... s)
public static java.lang.String join(java.lang.String... s)
public static <T> java.lang.String ltos(java.util.Collection<T> l, java.lang.Character c)
l
- The StringListc
- The delimiterpublic static java.util.List<java.lang.String> stol(java.lang.String s)
s
- The StringListpublic static <T> T[] array(T... elements)
public static java.lang.String d2s(java.lang.Double d)
public static java.lang.String urldecode(java.lang.String encodedText, java.lang.String contentType)
public static java.lang.String urlencode(java.lang.String text)
public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> parseQuery(java.lang.String s)
HashTable
object
with key-value pairs.
The query string should be in the form of a string
packaged by the GET or POST method, that is, it
should have key-value pairs in the form key=value,
with each pair separated from the next by a & character.
A key can appear more than once in the query string with different values. However, the key appears only once in the hashtable, with its value being an array of strings containing the multiple values sent by the query string.
The keys and values in the hashtable are stored in their decoded form, so any + characters are converted to spaces, and characters sent in hexadecimal notation (like %xx) are converted to ASCII characters.
s
- a string containing the query to be parsedHashTable
object built
from the parsed key-value pairsjava.lang.IllegalArgumentException
- if the query string
is invalid