|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfreemarker.template.utility.StringUtil
public class StringUtil
Some text related utilities.
Constructor Summary | |
---|---|
StringUtil()
|
Method Summary | |
---|---|
static java.lang.String |
capitalize(java.lang.String s)
|
static java.lang.String |
chomp(java.lang.String s)
Removes the line-break from the end of the string. |
static java.util.Locale |
deduceLocale(java.lang.String input)
|
static java.lang.String |
FTLStringLiteralDec(java.lang.String s)
FTL string literal decoding. \\, \", \', \n, \t, \r, \b and \f will be replaced according to Java rules. |
static java.lang.String |
FTLStringLiteralEnc(java.lang.String s)
|
static boolean |
getYesNo(java.lang.String s)
|
static java.lang.String |
HTMLEnc(java.lang.String s)
HTML encoding (does not convert line breaks). |
static boolean |
isXMLID(java.lang.String name)
|
static java.lang.String |
javaScriptStringEnc(java.lang.String s)
Escapes a String according the JavaScript string literal
escaping rules. |
static java.lang.String |
javaStringEnc(java.lang.String s)
Escapes the String with the escaping rules of Java language
string literals, so it is safe to insert the value into a string literal. |
static java.lang.String |
jQuote(java.lang.String s)
Quotes string as Java Language string literal. |
static java.lang.String |
leftPad(java.lang.String s,
int minLength)
Pads the string at the left with spaces until it reaches the desired length. |
static java.lang.String |
leftPad(java.lang.String s,
int minLength,
char filling)
Pads the string at the left with the specified character until it reaches the desired length. |
static java.lang.String |
leftPad(java.lang.String s,
int minLength,
java.lang.String filling)
Pads the string at the left with a filling pattern until it reaches the desired length. |
static boolean |
matchesName(java.lang.String qname,
java.lang.String nodeName,
java.lang.String nsURI,
Environment env)
|
static java.util.Map |
parseNameValuePairList(java.lang.String s,
java.lang.String defaultValue)
Parses a name-value pair list, where the pairs are separated with comma, and the name and value is separated with colon. |
static java.lang.String |
replace(java.lang.String text,
java.lang.String oldsub,
java.lang.String newsub,
boolean caseInsensitive,
boolean firstOnly)
Replaces all occurrences of a sub-string in a string. |
static java.lang.String |
rightPad(java.lang.String s,
int minLength)
Pads the string at the right with spaces until it reaches the desired length. |
static java.lang.String |
rightPad(java.lang.String s,
int minLength,
char filling)
Pads the string at the right with the specified character until it reaches the desired length. |
static java.lang.String |
rightPad(java.lang.String s,
int minLength,
java.lang.String filling)
Pads the string at the right with a filling pattern until it reaches the desired length. |
static java.lang.String |
RTFEnc(java.lang.String s)
Rich Text Format encoding (does not replace line breaks). |
static java.lang.String[] |
split(java.lang.String s,
char c)
Splits a string at the specified character. |
static java.lang.String[] |
split(java.lang.String s,
java.lang.String sep,
boolean caseInsensitive)
Splits a string at the specified string. |
static java.lang.String |
URLEnc(java.lang.String s,
java.lang.String charset)
URL encoding (like%20this). |
static java.lang.String |
XHTMLEnc(java.lang.String s)
XHTML Encoding. |
static java.lang.String |
XMLEnc(java.lang.String s)
XML Encoding. |
static java.lang.String |
XMLEncNA(java.lang.String s)
XML encoding without replacing apostrophes. |
static java.lang.String |
XMLEncNQG(java.lang.String s)
XML encoding without replacing apostrophes and quotation marks and greater-than signs. |
static java.lang.String |
XMLEncQAttr(java.lang.String s)
XML encoding for attributes valies quoted with " (not with '!). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StringUtil()
Method Detail |
---|
public static java.lang.String HTMLEnc(java.lang.String s)
public static java.lang.String XMLEnc(java.lang.String s)
public static java.lang.String XHTMLEnc(java.lang.String s)
public static java.lang.String XMLEncNA(java.lang.String s)
XMLEnc(String)
public static java.lang.String XMLEncQAttr(java.lang.String s)
XMLEnc(String)
public static java.lang.String XMLEncNQG(java.lang.String s)
XMLEnc(String)
public static java.lang.String RTFEnc(java.lang.String s)
public static java.lang.String URLEnc(java.lang.String s, java.lang.String charset) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static java.lang.String FTLStringLiteralEnc(java.lang.String s)
public static java.lang.String FTLStringLiteralDec(java.lang.String s) throws ParseException
s
- String literal without the surrounding quotation marks
ParseException
- if there string contains illegal escapespublic static java.util.Locale deduceLocale(java.lang.String input)
public static java.lang.String capitalize(java.lang.String s)
public static boolean getYesNo(java.lang.String s)
public static java.lang.String[] split(java.lang.String s, char c)
public static java.lang.String[] split(java.lang.String s, java.lang.String sep, boolean caseInsensitive)
public static java.lang.String replace(java.lang.String text, java.lang.String oldsub, java.lang.String newsub, boolean caseInsensitive, boolean firstOnly)
text
- The string where it will replace oldsub
with
newsub
.
public static java.lang.String chomp(java.lang.String s)
public static java.lang.String jQuote(java.lang.String s)
"null"
if s
is null
.
public static java.lang.String javaStringEnc(java.lang.String s)
String
with the escaping rules of Java language
string literals, so it is safe to insert the value into a string literal.
The resulting string will not be quoted.
In additional, all characters under UCS code point 0x20, that has no dedicated escape sequence in Java language, will be replaced with UNICODE escape (\uXXXX).
jQuote(String)
public static java.lang.String javaScriptStringEnc(java.lang.String s)
String
according the JavaScript string literal
escaping rules. The resulting string will not be quoted.
It escapes both ' and ". In additional it escapes > as \> (to avoid </script>). Furthermore, all characters under UCS code point 0x20, that has no dedicated escape sequence in JavaScript language, will be replaced with hexadecimal escape (\xXX).
public static java.util.Map parseNameValuePairList(java.lang.String s, java.lang.String defaultValue) throws java.text.ParseException
defaultValue
is not null. When a
value is omitted, then the colon after the key must be omitted as well.
The same key can't be used for multiple times.
s
- the string to parse.
For example: "strong:100, soft:900"
.defaultValue
- the value used when the value is omitted in a
key-value pair.
java.text.ParseException
- if the string is not a valid name-value
pair list.public static boolean isXMLID(java.lang.String name)
public static boolean matchesName(java.lang.String qname, java.lang.String nodeName, java.lang.String nsURI, Environment env)
public static java.lang.String leftPad(java.lang.String s, int minLength)
s
- the string that will be padded.minLength
- the length to reach.public static java.lang.String leftPad(java.lang.String s, int minLength, char filling)
s
- the string that will be padded.minLength
- the length to reach.filling
- the filling pattern.public static java.lang.String leftPad(java.lang.String s, int minLength, java.lang.String filling)
leftPad('ABC', 9, '1234')
returns "123412ABC"
.
s
- the string that will be padded.minLength
- the length to reach.filling
- the filling pattern. Must be at least 1 characters long.
Can't be null
.public static java.lang.String rightPad(java.lang.String s, int minLength)
s
- the string that will be padded.minLength
- the length to reach.public static java.lang.String rightPad(java.lang.String s, int minLength, char filling)
s
- the string that will be padded.minLength
- the length to reach.filling
- the filling pattern.public static java.lang.String rightPad(java.lang.String s, int minLength, java.lang.String filling)
rightPad('ABC', 9, '1234')
returns "ABC412341"
. Note that the filling pattern is
started as if you overlay "123412341"
with the left-aligned
"ABC"
, so it starts with "4"
.
s
- the string that will be padded.minLength
- the length to reach.filling
- the filling pattern. Must be at least 1 characters long.
Can't be null
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |