public class StringUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
StringUtil.ParseException
Formal (syntactical) problem with the text.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LINE_BREAK
The default line-break string used by the methods in this class.
|
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
capitalizeFirst(java.lang.String s) |
static java.lang.String |
chomp(java.lang.String s)
Removes the line-break from the end of the string.
|
static void |
chomp(java.lang.StringBuffer sb)
Removes the line-break from the end of the
StringBuffer . |
static java.lang.String |
createSourceCodeErrorMessage(java.lang.String message,
java.lang.String srcCode,
int position,
java.lang.String fileName,
int maxQuotLength) |
static java.lang.String |
expandTabs(java.lang.String text,
int tabWidth)
Same as
expandTabs(text, tabWidth, 0) . |
static java.lang.String |
expandTabs(java.lang.String text,
int tabWidth,
int startCol)
Replaces all occurances of character tab with spaces.
|
static java.lang.String |
ftlStringLiteralDec(java.lang.String s)
FTL string literal decoding.
|
static java.lang.String |
htmlEnc(java.lang.String s)
HTML encoding (does not convert line breaks).
|
static java.lang.String |
jQuote(char c)
Quotes string as Java language character.
|
static java.lang.String |
jQuote(java.lang.String s)
Quotes string as Java language string literal.
|
static java.lang.String |
jQuoteOrName(char c)
Quotes character as Java language character, except quote characters,
which are referred with name.
|
static java.lang.String |
normalizeLinebreaks(java.lang.String s)
Converts all line-breaks to UN*X linebreaks (
"\n" ). |
static java.lang.String |
repeat(java.lang.String s,
int n) |
static java.lang.String |
replace(java.lang.String text,
java.lang.String oldsub,
java.lang.String newsub)
Replaces all occurances of a sub-string in a string.
|
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)
Same as
split(s, c, false) . |
static java.lang.String[] |
split(java.lang.String s,
char c,
boolean trim)
Splits a string at the specified character, and optionally trims the
items.
|
static java.lang.String[] |
split(java.lang.String s,
java.lang.String sep)
Splits a string at the specified string.
|
static java.lang.String[] |
splitAtWS(java.lang.String text)
Splits a string at white-spaces.
|
static java.math.BigDecimal |
stringToBigDecimal(java.lang.String s)
Converts a string to
BigDecimal . |
static boolean |
stringToBoolean(java.lang.String s) |
static freemarker.template.TemplateDateModel |
stringToDate(java.lang.String s,
java.util.TimeZone tz)
Parses a date of format
"yyyy-MM-dd"
or "yyyy-MM-dd z" and returns it as
TemplateDateModel . |
static freemarker.template.TemplateDateModel |
stringToDateTime(java.lang.String s,
java.util.TimeZone tz)
Parses a date-time of format
"yyyy-MM-dd H:mm:ss"
or "yyyy-MM-dd h:mm:ss a" or
"yyyy-MM-dd H:mm:ss z"
or "yyyy-MM-dd h:mm:ss a z" and returns it as
TemplateDateModel . |
static java.lang.String |
stringToPerl5Regex(java.lang.String text)
Convers string to Perl 5 regular expression.
|
static freemarker.template.TemplateDateModel |
stringToTime(java.lang.String s,
java.util.TimeZone tz)
Parses a time of format
"H:mm:ss"
or "h:mm:ss a" or "H:mm:ss z"
or "h:mm:ss a z" and returns it as
TemplateDateModel . |
static java.lang.String |
urlEnc(java.lang.String s,
java.lang.String enc)
URL encoding (like%20this).
|
static java.lang.String |
urlPathEnc(java.lang.String s,
java.lang.String enc)
URL encoding without escaping slashes.
|
static java.lang.StringBuffer |
wrap(java.lang.StringBuffer text,
int screenWidth,
int firstIndent,
int indent)
Hard-wraps flow-text.
|
static java.lang.StringBuffer |
wrap(java.lang.StringBuffer text,
int screenWidth,
int firstIndent,
int indent,
java.lang.String lineBreak,
boolean traceMode)
Hard-wraps flow-text.
|
static java.lang.String |
wrap(java.lang.String text,
int screenWidth)
Hard-wraps flow-text.
|
static java.lang.String |
wrap(java.lang.String text,
int screenWidth,
int indent)
Hard-wraps flow-text.
|
static java.lang.String |
wrap(java.lang.String text,
int screenWidth,
int firstIndent,
int indent)
Hard-wraps flow-text.
|
static java.lang.String |
wrap(java.lang.String text,
int screenWidth,
int firstIndent,
int indent,
java.lang.String lineBreak)
Hard-wraps flow-text.
|
static java.lang.String |
wrap(java.lang.String text,
int screenWidth,
int firstIndent,
int indent,
java.lang.String lineBreak,
boolean traceMode)
Hard-wraps flow-text.
|
static java.lang.String |
wrap(java.lang.String text,
int screenWidth,
int indent,
java.lang.String lineBreak)
Hard-wraps flow-text.
|
static java.lang.String |
wrap(java.lang.String text,
int screenWidth,
java.lang.String lineBreak)
Hard-wraps flow-text.
|
static java.lang.String |
wrapTrace(java.lang.String text,
int screenWidth)
Hard-wraps flow-text.
|
static java.lang.String |
xmlEnc(java.lang.String s)
XML Encoding.
|
static java.lang.String |
xmlEncNQ(java.lang.String s)
XML encoding without replacing apostrophes and quotation marks.
|
public static final java.lang.String LINE_BREAK
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 xmlEncNQ(java.lang.String s)
xmlEnc(String)
public static java.lang.String rtfEnc(java.lang.String s)
public static java.lang.String jQuoteOrName(char c)
public static java.lang.String jQuote(char c)
public static java.lang.String jQuote(java.lang.String s)
public static java.lang.String ftlStringLiteralDec(java.lang.String s) throws StringUtil.ParseException
StringUtil.ParseException
.s
- String literal without the surrounding quotation marksStringUtil.ParseException
- if there string contains illegal escapespublic static java.lang.String stringToPerl5Regex(java.lang.String text)
public static java.lang.String[] split(java.lang.String s, char c)
split(s, c, false)
.public static java.lang.String[] split(java.lang.String s, char c, boolean trim)
public static java.lang.String[] split(java.lang.String s, java.lang.String sep)
public static java.lang.String[] splitAtWS(java.lang.String text)
public static java.lang.String replace(java.lang.String text, java.lang.String oldsub, java.lang.String newsub)
text
- The string where it will replace oldsub
with
newsub
.public static java.lang.String expandTabs(java.lang.String text, int tabWidth)
expandTabs(text, tabWidth, 0)
.expandTabs(String, int, int)
public static java.lang.String expandTabs(java.lang.String text, int tabWidth, int startCol)
tabWidth
- the distance of tab stops.startCol
- the index of the column in which the first character of
the string is from the left edge of the page. The index of the first
column is 0.public static java.lang.String chomp(java.lang.String s)
public static void chomp(java.lang.StringBuffer sb)
StringBuffer
.public static java.lang.String urlEnc(java.lang.String s, java.lang.String enc) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static java.lang.String urlPathEnc(java.lang.String s, java.lang.String enc) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static java.lang.String wrap(java.lang.String text, int screenWidth)
wrap(text, screenWidth, 0, 0, LINE_BREAK, false)
.public static java.lang.String wrapTrace(java.lang.String text, int screenWidth)
wrap(text, screenWidth, 0, 0, LINE_BREAK, true)
.public static java.lang.String wrap(java.lang.String text, int screenWidth, java.lang.String lineBreak)
wrap(text, screenWidth, 0, 0, lineBreak, false)
.public static java.lang.String wrap(java.lang.String text, int screenWidth, int indent)
wrap(text, screenWidth, indent, indent, LINE_BREAK, false)
.public static java.lang.String wrap(java.lang.String text, int screenWidth, int firstIndent, int indent)
wrap(text, screenWidth, firstIndent, indent, LINE_BREAK,
false)
.public static java.lang.String wrap(java.lang.String text, int screenWidth, int indent, java.lang.String lineBreak)
wrap(text, screenWidth, indent, indent, lineBreak, false)
.public static java.lang.String wrap(java.lang.String text, int screenWidth, int firstIndent, int indent, java.lang.String lineBreak)
wrap(text, screenWidth, firstIndent, indent, lineBreak,
false)
.public static java.lang.StringBuffer wrap(java.lang.StringBuffer text, int screenWidth, int firstIndent, int indent)
wrap(text, screenWidth, firstIndent, indent, LINE_BREAK)
.public static java.lang.String wrap(java.lang.String text, int screenWidth, int firstIndent, int indent, java.lang.String lineBreak, boolean traceMode)
text
- The flow-text to wrap. The explicit line-breaks of the
source text will be kept. All types of line-breaks (UN*X, Mac, DOS/Win)
are understood.screenWidth
- The (minimum) width of the screen. It does not
utilize the screenWidth
-th column of the screen to store
characters, except line-breaks (because some terminals/editors
do an automatic line-break when you write visible character there,
and some doesn't... so it is unpredictable if an explicit line-break
is needed or not.).firstIndent
- The indentation of the first lineindent
- The indentation of all lines but the first linelineBreak
- The String used for line-breakstraceMode
- Set this true if the input text is a Java stack
trace. In this mode, all lines starting with
optional indentation + 'at'
+ space are treated as location
lines, and will be indented and wrapped in a slightly special way.java.lang.IllegalArgumentException
- if the number of columns remaining for
the text is less than 2.public static java.lang.StringBuffer wrap(java.lang.StringBuffer text, int screenWidth, int firstIndent, int indent, java.lang.String lineBreak, boolean traceMode)
wrap
variations, so if you are working with StringBuffers anyway, it gives
better performance.public static java.lang.String createSourceCodeErrorMessage(java.lang.String message, java.lang.String srcCode, int position, java.lang.String fileName, int maxQuotLength)
public static java.math.BigDecimal stringToBigDecimal(java.lang.String s) throws StringUtil.ParseException
BigDecimal
.StringUtil.ParseException
public static boolean stringToBoolean(java.lang.String s) throws StringUtil.ParseException
StringUtil.ParseException
public static freemarker.template.TemplateDateModel stringToDate(java.lang.String s, java.util.TimeZone tz) throws StringUtil.ParseException
"yyyy-MM-dd"
or "yyyy-MM-dd z"
and returns it as
TemplateDateModel
.StringUtil.ParseException
public static freemarker.template.TemplateDateModel stringToTime(java.lang.String s, java.util.TimeZone tz) throws StringUtil.ParseException
"H:mm:ss"
or "h:mm:ss a"
or "H:mm:ss z"
or "h:mm:ss a z"
and returns it as
TemplateDateModel
.StringUtil.ParseException
public static freemarker.template.TemplateDateModel stringToDateTime(java.lang.String s, java.util.TimeZone tz) throws StringUtil.ParseException
"yyyy-MM-dd H:mm:ss"
or "yyyy-MM-dd h:mm:ss a"
or
"yyyy-MM-dd H:mm:ss z"
or "yyyy-MM-dd h:mm:ss a z"
and returns it as
TemplateDateModel
.StringUtil.ParseException
public static java.lang.String normalizeLinebreaks(java.lang.String s)
"\n"
). The
input text can contain UN*X, DOS (Windows) and Mac linebreaks mixed.public static java.lang.String repeat(java.lang.String s, int n)
public static java.lang.String capitalizeFirst(java.lang.String s)