Package org.restlet.engine.util
Class StringUtils
- java.lang.Object
-
- org.restlet.engine.util.StringUtils
-
public class StringUtils extends java.lang.ObjectString manipulation utilities.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classStringUtils.CharacterEntityRepresents an XML or HTML character entity reference.private static classStringUtils.CharacterEntitySolverStores a list en entities and is able to return one given its numeric value or name.
-
Field Summary
Fields Modifier and Type Field Description private static StringUtils.CharacterEntitySolverhtml40EntitiesEntities defined for HTML 4.0.private static java.util.List<StringUtils.CharacterEntity>htmlLat1Entities defined in http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent.private static java.util.List<StringUtils.CharacterEntity>htmlSpecialEntities defined in http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent.private static java.util.List<StringUtils.CharacterEntity>htmlSymbolEntities defined in http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent.private static java.util.List<StringUtils.CharacterEntity>xml10Basic entities.
-
Constructor Summary
Constructors Modifier Constructor Description privateStringUtils()Private constructor to ensure that the class acts as a true utility class i.e.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringfirstLower(java.lang.String string)Returns the string with the first character capitalized.static java.lang.StringfirstUpper(java.lang.String string)Returns the string with the first character capitalized.static byte[]getAsciiBytes(java.lang.String string)Encodes the given String into a sequence of bytes using the Ascii character set.static byte[]getLatin1Bytes(java.lang.String string)Encodes the given String into a sequence of bytes using the Latin1 character set.static java.lang.StringhtmlEscape(java.lang.String str)Returns the givenStringaccording to the HTML 4.0 encoding rules.static java.lang.StringhtmlUnescape(java.lang.String str)Returns the givenStringdecoded according to the HTML 4.0 decoding rules.static booleanisNullOrEmpty(java.lang.String string)Returnstrueif the given string is null or is the empty string.static java.lang.StringnullToEmpty(java.lang.String string)Returns the given string if it is non-null; the empty string otherwise.static java.util.List<java.lang.String>splitAndTrim(java.lang.String stringToSplit)Returns an list of trimmed token splitted with the split character ",".static java.util.List<java.lang.String>splitAndTrim(java.lang.String stringToSplit, java.lang.String splitCharacter)Returns an list of trimmed token splitted with the split character.static java.lang.Stringstrip(java.lang.String source, char delimiter)Strips a delimiter character from both ends of the source string.static java.lang.Stringstrip(java.lang.String source, char delimiter, boolean start, boolean end)Strips a delimiter character from a source string.
-
-
-
Field Detail
-
html40Entities
private static StringUtils.CharacterEntitySolver html40Entities
Entities defined for HTML 4.0.
-
htmlLat1
private static java.util.List<StringUtils.CharacterEntity> htmlLat1
Entities defined in http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent.
-
htmlSpecial
private static java.util.List<StringUtils.CharacterEntity> htmlSpecial
Entities defined in http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent.
-
htmlSymbol
private static java.util.List<StringUtils.CharacterEntity> htmlSymbol
Entities defined in http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent.
-
xml10
private static java.util.List<StringUtils.CharacterEntity> xml10
Basic entities.
-
-
Method Detail
-
firstLower
public static java.lang.String firstLower(java.lang.String string)
Returns the string with the first character capitalized.- Parameters:
string- a string reference to check- Returns:
- the string with the first character capitalized.
-
firstUpper
public static java.lang.String firstUpper(java.lang.String string)
Returns the string with the first character capitalized.- Parameters:
string- a string reference to check- Returns:
- the string with the first character capitalized.
-
getAsciiBytes
public static byte[] getAsciiBytes(java.lang.String string)
Encodes the given String into a sequence of bytes using the Ascii character set.- Parameters:
string- The string to encode.- Returns:
- The String encoded with the Ascii character set as an array of bytes.
-
getLatin1Bytes
public static byte[] getLatin1Bytes(java.lang.String string)
Encodes the given String into a sequence of bytes using the Latin1 character set.- Parameters:
string- The string to encode.- Returns:
- The String encoded with the Latin1 character set as an array of bytes.
-
htmlEscape
public static java.lang.String htmlEscape(java.lang.String str)
Returns the givenStringaccording to the HTML 4.0 encoding rules.- Parameters:
str- TheStringto encode.- Returns:
- The converted
Stringaccording to the HTML 4.0 encoding rules.
-
htmlUnescape
public static java.lang.String htmlUnescape(java.lang.String str)
Returns the givenStringdecoded according to the HTML 4.0 decoding rules.- Parameters:
str- TheStringto decode.- Returns:
- The given
Stringdecoded according to the HTML 4.0 decoding rules.
-
isNullOrEmpty
public static boolean isNullOrEmpty(java.lang.String string)
Returnstrueif the given string is null or is the empty string. Consider normalizing your string references withnullToEmpty(java.lang.String). If you do, you can useString.isEmpty()instead of this method, and you won't need special null-safe forms of methods likeString.toUpperCase(java.util.Locale)either.- Parameters:
string- a string reference to check- Returns:
trueif the string is null or is the empty string
-
nullToEmpty
public static java.lang.String nullToEmpty(java.lang.String string)
Returns the given string if it is non-null; the empty string otherwise.- Parameters:
string- the string to test and possibly return- Returns:
stringitself if it is non-null;""if it is null
-
splitAndTrim
public static java.util.List<java.lang.String> splitAndTrim(java.lang.String stringToSplit)
Returns an list of trimmed token splitted with the split character ",".- Parameters:
stringToSplit- The String to split.- Returns:
- List of tokens.
-
splitAndTrim
public static java.util.List<java.lang.String> splitAndTrim(java.lang.String stringToSplit, java.lang.String splitCharacter)Returns an list of trimmed token splitted with the split character.- Parameters:
stringToSplit- The String to split.splitCharacter- The split Character.- Returns:
- List of tokens.
-
strip
public static java.lang.String strip(java.lang.String source, char delimiter)Strips a delimiter character from both ends of the source string.- Parameters:
source- The source string to strip.delimiter- The character to remove.- Returns:
- The stripped string.
-
strip
public static java.lang.String strip(java.lang.String source, char delimiter, boolean start, boolean end)Strips a delimiter character from a source string.- Parameters:
source- The source string to strip.delimiter- The character to remove.start- Indicates if start of source should be stripped.end- Indicates if end of source should be stripped.- Returns:
- The stripped source string.
-
-