public final class StringUtil extends Object
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
addZeros(int i,
int size)
adds zeros add the begin of a int example: addZeros(2,3) return "002"
|
static String |
addZeros(long i,
int size)
adds zeros add the begin of a int example: addZeros(2,3) return "002"
|
static String |
camelToHypenNotation(String str)
translate a string in camel notation to a string in hypen notation
example:
helloWorld -> hello-world
|
static String |
capitalize(String input,
char[] delims) |
static boolean |
contains(String str,
String substr) |
static boolean |
containsIgnoreCase(String str,
String substr) |
static String |
emptyIfNull(Collection.Key key) |
static String |
emptyIfNull(String str) |
static boolean |
endsWith(String str,
char suffix)
Tests if this string ends with the specified suffix.
|
static boolean |
endsWith(String str,
char prefix1,
char prefix2) |
static boolean |
endsWithIgnoreCase(String base,
String end)
Helper functions to query a strings end portion.
|
static String |
escapeHTML(String html)
Escapes XML Tags
|
static String |
escapeJS(String str,
char quotesUsed)
escapes JS sensitive characters
|
static String |
escapeJS(String str,
char quotesUsed,
Charset charset) |
static String |
escapeJS(String str,
char quotesUsed,
CharsetEncoder enc)
escapes JS sensitive characters
|
static char |
firstChar(String str)
return the first character of a string, if string ist empty return 0;
|
static boolean |
hasLineFeed(String str)
return if in a string are line feeds or not
|
static boolean |
hasUpperCase(String str) |
static String |
hypenToCamelNotation(String str)
translate a string in hypen notation to a string in camel notation
example:
hello-world -> helloWorld
|
static int |
indexOf(String haystack,
String needle) |
static int |
indexOfIgnoreCase(String haystack,
String needle) |
static String |
insertAt(String str,
CharSequence substring,
int pos) |
static boolean |
isAllAlpha(String str)
returns true if all characters in the string are letters
|
static boolean |
isAllUpperCase(String str)
returns true if the input string has letters and they are all UPPERCASE
|
static boolean |
isAscii(String str) |
static boolean |
isBOM(byte[] barr)
returns if byte arr is a BOM character Stream (UTF-8,UTF-16)
|
static boolean |
isEmpty(Object obj) |
static boolean |
isEmpty(Object obj,
boolean trim) |
static boolean |
isEmpty(String str) |
static boolean |
isEmpty(String str,
boolean trim) |
static boolean |
isEmpty(StringBuffer sb) |
static boolean |
isEmpty(StringBuffer sb,
boolean trim) |
static boolean |
isEmpty(StringBuilder sb) |
static boolean |
isEmpty(StringBuilder sb,
boolean trim) |
static boolean |
isWhiteSpace(char c) |
static boolean |
isWhiteSpace(char c,
boolean checkSpecialWhiteSpace) |
static boolean |
isWhiteSpace(String str) |
static char |
lastChar(String str)
return the last character of a string, if string ist empty return 0;
|
static String |
lcFirst(String str)
do first Letter Upper case
|
static int |
length(String str) |
static int |
length(String str,
boolean trim) |
static String |
ltrim(String str,
String defaultValue)
This function returns a string with whitespace stripped from the beginning of str
|
static String |
max(String content,
int max)
cut string to max size if the string is greater, otherweise to nothing
|
static String |
max(String content,
int max,
String dotDotDot) |
static String[] |
merge(String str,
String[] arr) |
static String |
removeQuotes(String string,
boolean trim)
removes quotes(",') that wraps the string
|
static String |
removeStarting(String str,
String sub) |
static String |
removeStartingIgnoreCase(String str,
String sub) |
static String |
removeWhiteSpace(String str) |
static String |
repeatString(String str,
int count)
reapeats a string
|
static String |
replace(String input,
String find,
String repl)
performs a CaSe sensitive replace all
|
static String |
replace(String input,
String find,
String repl,
boolean firstOnly)
maintains the legacy signature of this method where matches are CaSe sensitive (sets the default of ignoreCase to false).
|
static String |
replace(String input,
String find,
String repl,
boolean firstOnly,
boolean ignoreCase)
performs a replace operation on a string
|
static String |
replaceLast(String str,
char from,
char to) |
static String |
replaceLast(String str,
String from,
String to) |
static String |
replaceMap(String input,
Map map,
boolean ignoreCase)
this is the public entry point for the replaceMap() method
|
static String |
reqExpEscape(String str)
escape all special characters of the regular expresson language
|
static String |
rtrim(String str,
String defaultValue)
This function returns a string with whitespace stripped from the end of str
|
static String |
soundex(String str)
soundex function
|
static boolean |
startsWith(String str,
char prefix)
Tests if this string starts with the specified prefix.
|
static boolean |
startsWith(String str,
char prefix1,
char prefix2) |
static boolean |
startsWithIgnoreCase(String base,
String start)
Helper functions to query a strings start portion.
|
static String |
substring(String str,
int off,
int len)
this method works different from the regular substring method, the regular substring method takes startIndex and endIndex as second and third argument,
this method takes offset and length
|
static String |
substringEL(String str,
int index,
String defaultValue) |
static String |
suppressWhiteSpace(String str)
remove all white spaces followd by whitespaces
|
static String |
toClassName(String str)
translate a string to a valid classname string
|
static String |
toIdentityVariableName(String varName)
translate a string to a valid identity variable name
|
static String |
toJavaClassName(String str) |
static String |
toLowerCase(String str)
cast a string a lower case String, is faster than the String.toLowerCase, if all Character are already Low Case
|
static String |
toString(Object value,
String defaultValue)
returns string, if given string is null or lengt 0 return default value
|
static String |
toString(String value,
String defaultValue)
returns string, if given string is null or lengt 0 return default value
|
static String |
toStringEmptyIfNull(Object o)
translate, like method toString, a object to a string, but when value is null value will be translated to a empty String ("").
|
static String |
toStringNative(Object obj,
String defaultValue) |
static String |
toUpperCase(String str) |
static String |
toVariableName(String str)
translate a string to a valid variable string
|
static String |
toVariableName(String str,
boolean addIdentityNumber,
boolean allowDot) |
static String |
trim(String str,
boolean removeBOM,
boolean removeSpecialWhiteSpace,
String defaultValue)
trim given value, return defaultvalue when input is null
this function no only removes the "classic" whitespaces,
it also removes Byte order masks forgotten to remove when reading a UTF file.
|
static String |
trim(String str,
String defaultValue)
trim given value, return defaultvalue when input is null
|
static String |
ucFirst(String str)
do first Letter Upper case
|
static String |
unescapeHTML(String html)
Unescapes HTML Tags
|
static String |
valueOf(String str)
return "" if value is null otherwise return same string
|
public StringUtil()
public static String ucFirst(String str)
str
- String to operatepublic static String capitalize(String input, char[] delims)
public static String lcFirst(String str)
str
- String to operatepublic static String unescapeHTML(String html)
html
- html code to escapepublic static String escapeHTML(String html)
html
- html code to unescapepublic static String escapeJS(String str, char quotesUsed)
str
- String to escapepublic static String escapeJS(String str, char quotesUsed, CharsetEncoder enc)
str
- String to escapecharset
- if not null, it checks if the given string is supported by the encoding, if not, lucee encodes the stringpublic static String repeatString(String str, int count)
str
- string to repeatcount
- how many time string will be reapetedpublic static String toStringEmptyIfNull(Object o)
o
- Object to convertpublic static String emptyIfNull(String str)
public static String emptyIfNull(Collection.Key key)
public static String reqExpEscape(String str)
str
- String to escapepublic static String toIdentityVariableName(String varName)
varName
- variable name template to translatepublic static String toClassName(String str)
str
- string to translatepublic static String toVariableName(String str)
str
- string to translatepublic static String toJavaClassName(String str)
public static String toVariableName(String str, boolean addIdentityNumber, boolean allowDot)
public static String ltrim(String str, String defaultValue)
str
- String to cleanpublic static String rtrim(String str, String defaultValue)
str
- String to cleanpublic static String trim(String str, String defaultValue)
str
- defaultValue
- public static boolean isWhiteSpace(char c, boolean checkSpecialWhiteSpace)
c
- character to checkcheckSpecialWhiteSpace
- if set to true, lucee checks also uncommon white spaces.public static boolean isWhiteSpace(char c)
public static String trim(String str, boolean removeBOM, boolean removeSpecialWhiteSpace, String defaultValue)
str
- removeBOM
- if set to true, Byte Order Mask that got forgotten get removed as wellremoveSpecialWhiteSpace
- if set to true, lucee removes also uncommon white spaces.defaultValue
- public static boolean hasLineFeed(String str)
str
- string to checkpublic static String suppressWhiteSpace(String str)
str
- strring to translatepublic static String toString(String value, String defaultValue)
value
- defaultValue
- public static String toString(Object value, String defaultValue)
value
- defaultValue
- public static String max(String content, int max)
content
- max
- public static String replace(String input, String find, String repl, boolean firstOnly, boolean ignoreCase)
input
- - the string input to work onfind
- - the substring to findrepl
- - the substring to replace the matches withfirstOnly
- - if true then only the first occurrence of find
will be replacedignoreCase
- - if true then matches will not be case sensitivepublic static String replace(String input, String find, String repl, boolean firstOnly)
input
- - the string input to work onfind
- - the substring to findrepl
- - the substring to replace the matches withfirstOnly
- - if true then only the first occurrence of find
will be replacedpublic static String replace(String input, String find, String repl)
input
- - the string input to work onfind
- - the substring to findrepl
- - the substring to replace the matches withpublic static String addZeros(int i, int size)
i
- number to add nullssize
- public static String addZeros(long i, int size)
i
- number to add nullssize
- public static int indexOfIgnoreCase(String haystack, String needle)
public static boolean startsWith(String str, char prefix)
str
- string to check first charprefix
- the prefix.public static boolean startsWith(String str, char prefix1, char prefix2)
public static boolean endsWith(String str, char suffix)
str
- string to check first charsuffix
- the suffix.public static boolean startsWithIgnoreCase(String base, String start)
base
- the base string.start
- the starting text.public static boolean endsWithIgnoreCase(String base, String end)
base
- the base string.end
- the ending text.public static boolean isBOM(byte[] barr)
barr
- public static String valueOf(String str)
str
- public static String toLowerCase(String str)
str
- public static String toUpperCase(String str)
public static String soundex(String str)
str
- public static char lastChar(String str)
str
- string to get last characterpublic static boolean isEmpty(String str)
str
- public static boolean isEmpty(String str, boolean trim)
str
- public static char firstChar(String str)
str
- string to get first characterpublic static String removeWhiteSpace(String str)
public static String replaceLast(String str, char from, char to)
public static String replaceLast(String str, String from, String to)
public static String removeQuotes(String string, boolean trim)
string
- public static boolean isEmpty(StringBuffer sb, boolean trim)
public static boolean isEmpty(StringBuilder sb, boolean trim)
public static boolean isEmpty(StringBuffer sb)
public static boolean isEmpty(StringBuilder sb)
public static String removeStarting(String str, String sub)
public static String removeStartingIgnoreCase(String str, String sub)
public static boolean hasUpperCase(String str)
public static boolean containsIgnoreCase(String str, String substr)
public static String substringEL(String str, int index, String defaultValue)
public static String camelToHypenNotation(String str)
str
- public static String hypenToCamelNotation(String str)
str
- public static boolean isAllAlpha(String str)
str
- public static boolean isAllUpperCase(String str)
str
- public static boolean isWhiteSpace(String str)
public static String substring(String str, int off, int len)
str
- off
- len
- public static String insertAt(String str, CharSequence substring, int pos)
public static String replaceMap(String input, Map map, boolean ignoreCase) throws PageException
input
- - the string on which the replacements should be performed.map
- - a java.util.Map with key/value pairs where the key is the substring to find and the value is the substring with which to replace the matched keyignoreCase
- - if true then matches will not be case sensitivePageException
public static String toStringNative(Object obj, String defaultValue)
Copyright © 2015 Lucee