railo.commons.lang
Class StringUtil

java.lang.Object
  extended by railo.commons.lang.StringUtil

public final class StringUtil
extends Object

Util to do some additional String Operations


Constructor Summary
StringUtil()
           
 
Method Summary
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 String changeCharset(String str, String charset)
          change charset of string from system default to givenstr
static String changeCharset(String str, String charset, String defaultValue)
          change charset of string from system default to givenstr
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 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)
          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 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(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 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 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 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 toUpperCase(String str)
           
static String toVariableName(String str)
          translate a string to a valid variable string
static String toVariableName(String str, boolean addIdentityNumber)
           
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
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

ucFirst

public static String ucFirst(String str)
do first Letter Upper case

Parameters:
str - String to operate
Returns:
uppercase string

capitalize

public static String capitalize(String input,
                                char[] delims)

lcFirst

public static String lcFirst(String str)
do first Letter Upper case

Parameters:
str - String to operate
Returns:
lower case String

unescapeHTML

public static String unescapeHTML(String html)
Unescapes HTML Tags

Parameters:
html - html code to escape
Returns:
escaped html code

escapeHTML

public static String escapeHTML(String html)
Escapes XML Tags

Parameters:
html - html code to unescape
Returns:
unescaped html code

escapeJS

public static String escapeJS(String str)
escapes JS sensitive characters

Parameters:
str - String to escape
Returns:
escapes String

repeatString

public static String repeatString(String str,
                                  int count)
reapeats a string

Parameters:
str - string to repeat
count - how many time string will be reapeted
Returns:
reapted string

toStringEmptyIfNull

public 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 ("").

Parameters:
o - Object to convert
Returns:
converted String

emptyIfNull

public static String emptyIfNull(String str)

emptyIfNull

public static String emptyIfNull(Collection.Key key)

reqExpEscape

public static String reqExpEscape(String str)
escape all special characters of the regular expresson language

Parameters:
str - String to escape
Returns:
escaped String

toIdentityVariableName

public static String toIdentityVariableName(String varName)
translate a string to a valid identity variable name

Parameters:
varName - variable name template to translate
Returns:
translated variable name

toClassName

public static String toClassName(String str)
translate a string to a valid classname string

Parameters:
str - string to translate
Returns:
translated String

toVariableName

public static String toVariableName(String str)
translate a string to a valid variable string

Parameters:
str - string to translate
Returns:
translated String

toVariableName

public static String toVariableName(String str,
                                    boolean addIdentityNumber)

ltrim

public static String ltrim(String str,
                           String defaultValue)
This function returns a string with whitespace stripped from the beginning of str

Parameters:
str - String to clean
Returns:
cleaned String

rtrim

public static String rtrim(String str,
                           String defaultValue)
This function returns a string with whitespace stripped from the end of str

Parameters:
str - String to clean
Returns:
cleaned String

hasLineFeed

public static boolean hasLineFeed(String str)
return if in a string are line feeds or not

Parameters:
str - string to check
Returns:
translated string

suppressWhiteSpace

public static String suppressWhiteSpace(String str)
remove all white spaces followd by whitespaces

Parameters:
str - strring to translate
Returns:
translated string

toString

public static String toString(String value,
                              String defaultValue)
returns string, if given string is null or lengt 0 return default value

Parameters:
value -
defaultValue -
Returns:
value or default value

toString

public static String toString(Object value,
                              String defaultValue)
returns string, if given string is null or lengt 0 return default value

Parameters:
value -
defaultValue -
Returns:
value or default value

max

public static String max(String content,
                         int max)
cut string to max size if the string is greater, otherweise to nothing

Parameters:
content -
max -
Returns:
cutted string

max

public static String max(String content,
                         int max,
                         String dotDotDot)

replace

public static String replace(String input,
                             String find,
                             String repl,
                             boolean firstOnly,
                             boolean ignoreCase)
performs a replace operation on a string

Parameters:
input - - the string input to work on
find - - the substring to find
repl - - the substring to replace the matches with
firstOnly - - if true then only the first occurrence of find will be replaced
ignoreCase - - if true then matches will not be case sensitive
Returns:

replace

public 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).

Parameters:
input - - the string input to work on
find - - the substring to find
repl - - the substring to replace the matches with
firstOnly - - if true then only the first occurrence of find will be replaced
Returns:
- calls replace( input, find, repl, firstOnly, false )

replace

public static String replace(String input,
                             String find,
                             String repl)
performs a CaSe sensitive replace all

Parameters:
input - - the string input to work on
find - - the substring to find
repl - - the substring to replace the matches with
Returns:
- calls replace( input, find, repl, false, false )

addZeros

public static String addZeros(int i,
                              int size)
adds zeros add the begin of a int example: addZeros(2,3) return "002"

Parameters:
i - number to add nulls
size -
Returns:
min len of return value;

addZeros

public static String addZeros(long i,
                              int size)
adds zeros add the begin of a int example: addZeros(2,3) return "002"

Parameters:
i - number to add nulls
size -
Returns:
min len of return value;

indexOf

public static int indexOf(String haystack,
                          String needle)

indexOfIgnoreCase

public static int indexOfIgnoreCase(String haystack,
                                    String needle)

startsWith

public static boolean startsWith(String str,
                                 char prefix)
Tests if this string starts with the specified prefix.

Parameters:
str - string to check first char
prefix - the prefix.
Returns:
is first of given type

endsWith

public static boolean endsWith(String str,
                               char suffix)
Tests if this string ends with the specified suffix.

Parameters:
str - string to check first char
suffix - the suffix.
Returns:
is last of given type

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(String base,
                                           String start)
Helper functions to query a strings start portion. The comparison is case insensitive.

Parameters:
base - the base string.
start - the starting text.
Returns:
true, if the string starts with the given starting text.

endsWithIgnoreCase

public static boolean endsWithIgnoreCase(String base,
                                         String end)
Helper functions to query a strings end portion. The comparison is case insensitive.

Parameters:
base - the base string.
end - the ending text.
Returns:
true, if the string ends with the given ending text.

isBOM

public static boolean isBOM(byte[] barr)
returns if byte arr is a BOM character Stream (UTF-8,UTF-16)

Parameters:
barr -
Returns:
is BOM or not

valueOf

public static String valueOf(String str)
return "" if value is null otherwise return same string

Parameters:
str -
Returns:
string (not null)

toLowerCase

public 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

Parameters:
str -
Returns:
lower case value

toUpperCase

public static String toUpperCase(String str)

soundex

public static String soundex(String str)
soundex function

Parameters:
str -
Returns:
soundex from given string

lastChar

public static char lastChar(String str)
return the last character of a string, if string ist empty return 0;

Parameters:
str - string to get last character
Returns:
last character

isEmpty

public static boolean isEmpty(String str)
Parameters:
str -
Returns:
return if a String is "Empty", that means NULL or String with length 0 (whitespaces will not counted)

isEmpty

public static boolean isEmpty(String str,
                              boolean trim)
Parameters:
str -
Returns:
return if a String is "Empty", that means NULL or String with length 0 (whitespaces will not counted)

firstChar

public static char firstChar(String str)
return the first character of a string, if string ist empty return 0;

Parameters:
str - string to get first character
Returns:
first character

changeCharset

public static String changeCharset(String str,
                                   String charset)
                            throws UnsupportedEncodingException
change charset of string from system default to givenstr

Parameters:
str -
charset -
Returns:
Throws:
UnsupportedEncodingException

changeCharset

public static String changeCharset(String str,
                                   String charset,
                                   String defaultValue)
change charset of string from system default to givenstr

Parameters:
str -
charset -
Returns:
Throws:
UnsupportedEncodingException

isWhiteSpace

public static boolean isWhiteSpace(char c)

removeWhiteSpace

public static String removeWhiteSpace(String str)

replaceLast

public static String replaceLast(String str,
                                 char from,
                                 char to)

replaceLast

public static String replaceLast(String str,
                                 String from,
                                 String to)

removeQuotes

public static String removeQuotes(String string,
                                  boolean trim)
removes quotes(",') that wraps the string

Parameters:
string -
Returns:

isEmpty

public static boolean isEmpty(Object obj,
                              boolean trim)

isEmpty

public static boolean isEmpty(Object obj)

isEmpty

public static boolean isEmpty(StringBuffer sb,
                              boolean trim)

isEmpty

public static boolean isEmpty(StringBuilder sb,
                              boolean trim)

isEmpty

public static boolean isEmpty(StringBuffer sb)

isEmpty

public static boolean isEmpty(StringBuilder sb)

removeStarting

public static String removeStarting(String str,
                                    String sub)

removeStartingIgnoreCase

public static String removeStartingIgnoreCase(String str,
                                              String sub)

merge

public static String[] merge(String str,
                             String[] arr)

length

public static int length(String str)

hasUpperCase

public static boolean hasUpperCase(String str)

trim

public static String trim(String str,
                          String defaultValue)
trim given value, return defaultvalue when input is null

Parameters:
str -
defaultValue -
Returns:
trimmed string or defaultValue

contains

public static boolean contains(String str,
                               String substr)

containsIgnoreCase

public static boolean containsIgnoreCase(String str,
                                         String substr)

substringEL

public static String substringEL(String str,
                                 int index,
                                 String defaultValue)

camelToHypenNotation

public static String camelToHypenNotation(String str)
translate a string in camel notation to a string in hypen notation example: helloWorld -> hello-world

Parameters:
str -
Returns:

hypenToCamelNotation

public static String hypenToCamelNotation(String str)
translate a string in hypen notation to a string in camel notation example: hello-world -> helloWorld

Parameters:
str -
Returns:

isAscii

public static boolean isAscii(String str)

isWhiteSpace

public static boolean isWhiteSpace(String str)

substring

public 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

Parameters:
str -
off -
len -
Returns:

replaceMap

public static String replaceMap(String input,
                                Map map,
                                boolean ignoreCase)
                         throws PageException
this is the public entry point for the replaceMap() method

Parameters:
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 key
ignoreCase - - if true then matches will not be case sensitive
Returns:
Throws:
PageException


Copyright © 2012 Railo