|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.directory.shared.ldap.util.StringTools
Various string manipulation methods that are more efficient then chaining string operations: all is done in the same buffer without creating a bunch of string objects.
Field Summary | |
static boolean[] |
ALPHA
|
static boolean[] |
CHAR
|
static boolean[] |
DIGIT
'0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' |
static java.lang.String |
EMPTY
The empty String "" . |
static byte[] |
EMPTY_BYTES
The empty byte[] |
static byte[] |
HEX_VALUE
|
static int |
NOT_EQUAL
|
Constructor Summary | |
StringTools()
|
Method Summary | |
static int |
areEquals(byte[] byteArray,
int index,
byte[] byteArray2)
Check if a text is present at the current position in a buffer. |
static int |
areEquals(byte[] byteArray,
int index,
java.lang.String text)
Check if a text is present at the current position in a buffer. |
static int |
areEquals(char[] charArray,
int index,
char[] charArray2)
Check if a text is present at the current position in a buffer. |
static int |
areEquals(char[] charArray,
int index,
java.lang.String text)
Check if a text is present at the current position in a buffer. |
static char |
bytesToChar(byte[] bytes)
Return the Unicode char which is coded in the bytes at position 0. |
static char |
bytesToChar(byte[] bytes,
int pos)
Return the Unicode char which is coded in the bytes at the given position. |
static java.lang.String |
centerTrunc(java.lang.String a_str,
int a_head,
int a_tail)
Truncates large Strings showing a portion of the String's head and tail with the center cut out and replaced with '...'. |
static byte[] |
charToBytes(char car)
Return the Unicode char which is coded in the bytes at the given position. |
static int |
countBytes(char[] chars)
Count the number of bytes included in the given char[]. |
static int |
countBytesPerChar(byte[] bytes,
int pos)
Count the number of bytes needed to return an Unicode char. |
static int |
countChars(byte[] bytes)
Count the number of chars included in the given byte[]. |
static int |
countNbBytesPerChar(char car)
Return the number of bytes that hold an Unicode char. |
static java.lang.String |
deepTrim(java.lang.String string)
A deep trim of a string remove whitespace from the ends as well as excessive whitespace within the inside of the string between non-whitespace characters. |
static java.lang.String |
deepTrim(java.lang.String str,
boolean toLowerCase)
Put common code to deepTrim(String) and deepTrimToLower here. |
static java.lang.String |
deepTrimToLower(java.lang.String string)
This does the same thing as a trim but we also lowercase the string while performing the deep trim within the same buffer. |
static java.lang.String |
dumpByte(byte octet)
Helper function that dump a byte in hex form |
static java.lang.String |
dumpBytes(byte[] buffer)
Helper function that dump an array of bytes in hex form |
static char |
dumpHex(byte hex)
Helper function that returns a char from an hex |
static boolean |
equals(java.lang.String str1,
java.lang.String str2)
Compares two Strings, returning true if they are equal. |
static java.lang.String |
formatHtml(java.lang.String a_source,
boolean a_bReplaceNl,
boolean a_bReplaceTag,
boolean a_bReplaceQuote)
This method is used to insert HTML block dynamically |
static byte[] |
getBytesUtf8(java.lang.String string)
Return UTF-8 encoded byte[] representation of a String |
static java.util.List |
getPaths(java.lang.String a_paths,
java.io.FileFilter a_filter)
Splits apart a OS separator delimited set of paths in a string into multiple Strings. |
static java.util.regex.Pattern |
getRegex(java.lang.String ldapRegex)
Generates a regular expression from an LDAP substring match expression by parsing out the supplied string argument. |
static java.util.regex.Pattern |
getRegex(java.lang.String initialPattern,
java.lang.String[] anyPattern,
java.lang.String finalPattern)
Creates a regular expression from an LDAP substring assertion filter specification. |
static boolean |
isAlphaASCII(byte[] byteArray,
int index)
Test if the current character is an Alpha character : |
static boolean |
isAlphaASCII(char[] chars,
int index)
Test if the current character is an Alpha character : |
static boolean |
isAlphaDigitMinus(byte[] byteArray,
int index)
Check if the current character is an 7 bits ASCII CHAR (between 0 and 127). |
static boolean |
isAlphaDigitMinus(char[] chars,
int index)
Check if the current character is an 7 bits ASCII CHAR (between 0 and 127). |
static boolean |
isCharASCII(byte[] byteArray,
int index,
char car)
Test if the current character is equal to a specific character. |
static boolean |
isCharASCII(char[] chars,
int index,
char car)
Test if the current character is equal to a specific character. |
static boolean |
isDigit(byte[] byteArray)
Test if the current character is a digit |
static boolean |
isDigit(byte[] byteArray,
int index)
Test if the current character is a digit |
static boolean |
isDigit(char[] chars)
Test if the current character is a digit |
static boolean |
isDigit(char[] chars,
int index)
Test if the current character is a digit |
static boolean |
isEmpty(byte[] bytes)
Checks if a bytes array is empty or null. |
static boolean |
isEmpty(java.lang.String str)
Checks if a String is empty ("") or null. |
static boolean |
isHex(byte[] byteArray,
int index)
Check if the current character is an Hex Char |
static boolean |
isHex(char[] chars,
int index)
Check if the current character is an Hex Char |
static boolean |
isNotEmpty(java.lang.String str)
Checks if a String is not empty ("") and not null. |
static java.lang.String |
listToString(java.util.List list)
Utility method that return a String representation of a list |
static java.lang.String |
listToString(java.util.List list,
java.lang.String tabs)
Utility method that return a String representation of a list |
static java.lang.String |
lowerCase(java.lang.String str)
Converts a String to lower case as per String.toLowerCase() . |
static java.lang.String |
mapToString(java.util.Map map)
Utility method that return a String representation of a map. |
static java.lang.String |
mapToString(java.util.Map map,
java.lang.String tabs)
Utility method that return a String representation of a map. |
static byte[] |
toByteArray(java.lang.String a_hexString)
Get byte array from hex string |
static java.lang.String |
toHexString(byte[] a_res)
Gets a hex string from byte array. |
static byte[] |
trim(byte[] bytes)
Removes spaces (char <= 32) from both start and ends of this bytes array, handling null by returning null . |
static java.lang.String |
trim(java.lang.String str)
Removes spaces (char <= 32) from both start and ends of this String, handling null by returning null . |
static java.lang.String |
trimConsecutiveToOne(java.lang.String str,
char ch)
Trims several consecutive characters into one. |
static int |
trimLeft(byte[] bytes,
int pos)
Removes spaces (char <= 32) from start of this array, handling null by returning null . |
static int |
trimLeft(char[] chars,
int pos)
Removes spaces (char <= 32) from start of this array, handling null by returning null . |
static java.lang.String |
trimLeft(java.lang.String str)
Removes spaces (char <= 32) from start of this String, handling null by returning null . |
static int |
trimRight(byte[] bytes,
int pos)
Removes spaces (char <= 32) from end of this array, handling null by returning null . |
static int |
trimRight(char[] chars,
int pos)
Removes spaces (char <= 32) from end of this array, handling null by returning null . |
static java.lang.String |
trimRight(java.lang.String str)
Removes spaces (char <= 32) from end of this String, handling null by returning null . |
static java.lang.String |
upperCase(java.lang.String str)
Converts a String to upper case as per String.toUpperCase() . |
static java.lang.String |
utf8ToString(byte[] bytes)
Return an UTF-8 encoded String |
static java.lang.String |
utf8ToString(byte[] bytes,
int length)
Return an UTF-8 encoded String |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final boolean[] ALPHA
public static final boolean[] CHAR
public static final boolean[] DIGIT
public static final byte[] HEX_VALUE
public static final int NOT_EQUAL
public static final java.lang.String EMPTY
""
.
public static final byte[] EMPTY_BYTES
Constructor Detail |
public StringTools()
Method Detail |
public static java.lang.String trimConsecutiveToOne(java.lang.String str, char ch)
str
- the string to trim consecutive characters ofch
- the character to trim down
public static java.lang.String deepTrim(java.lang.String string)
string
- the string to deep trim.
public static java.lang.String deepTrimToLower(java.lang.String string)
deepTrim( String )
public static java.lang.String deepTrim(java.lang.String str, boolean toLowerCase)
str
- the string to deep trimtoLowerCase
- how to normalize for case: upper or lower
deepTrim( String )
public static java.lang.String centerTrunc(java.lang.String a_str, int a_head, int a_tail)
a_str
- the string to truncatea_head
- the amount of the head to displaya_tail
- the amount of the tail to display
public static java.lang.String toHexString(byte[] a_res)
a_res
- the byte array
public static byte[] toByteArray(java.lang.String a_hexString)
a_hexString
- the hex string to convert to a byte array
public static java.lang.String formatHtml(java.lang.String a_source, boolean a_bReplaceNl, boolean a_bReplaceTag, boolean a_bReplaceQuote)
a_source
- the HTML code to be processesa_bReplaceNl
- if true '\n' will be replaced by a_bReplaceTag
- if true '<' will be replaced by < and '>' will be replaced
by >a_bReplaceQuote
- if true '\"' will be replaced by "
public static java.util.regex.Pattern getRegex(java.lang.String initialPattern, java.lang.String[] anyPattern, java.lang.String finalPattern) throws java.util.regex.PatternSyntaxException
RESyntaxException
- if a syntactically correct regular expression cannot be
compiled
java.util.regex.PatternSyntaxException
public static java.util.regex.Pattern getRegex(java.lang.String ldapRegex) throws java.util.regex.PatternSyntaxException
RESyntaxException
- if a syntactically correct regular expression cannot be
compiled
java.util.regex.PatternSyntaxException
public static java.util.List getPaths(java.lang.String a_paths, java.io.FileFilter a_filter)
a_paths
- a set of paths delimited using the OS path separatora_filter
- a FileFilter used to filter the return set
public static java.lang.String dumpByte(byte octet)
octet
- The byte to dump
public static char dumpHex(byte hex)
public static java.lang.String dumpBytes(byte[] buffer)
buffer
- The bytes array to dump
public static char bytesToChar(byte[] bytes)
bytes
- The byte[] represntation of an Unicode string.
public static int countBytesPerChar(byte[] bytes, int pos)
bytes
- The bytes to readpos
- Position to start counting. It must be a valid start of a
encoded char !
public static int countNbBytesPerChar(char car)
car
- The character to be decoded
public static int countBytes(char[] chars)
chars
- The char array to decode
public static char bytesToChar(byte[] bytes, int pos)
bytes
- The byte[] represntation of an Unicode string.pos
- The current position to start decoding the char
public static byte[] charToBytes(char car)
public static int countChars(byte[] bytes)
bytes
- The byte array to decode
public static int areEquals(byte[] byteArray, int index, java.lang.String text)
byteArray
- The buffer which contains the dataindex
- Current position in the buffertext
- The text we want to check
true
if the buffer contains the text.public static int areEquals(char[] charArray, int index, java.lang.String text)
charArray
- The buffer which contains the dataindex
- Current position in the buffertext
- The text we want to check
true
if the buffer contains the text.public static int areEquals(char[] charArray, int index, char[] charArray2)
charArray
- The buffer which contains the dataindex
- Current position in the buffercharArray2
- The text we want to check
true
if the buffer contains the text.public static int areEquals(byte[] byteArray, int index, byte[] byteArray2)
byteArray
- The buffer which contains the dataindex
- Current position in the bufferbyteArray2
- The text we want to check
true
if the buffer contains the text.public static boolean isCharASCII(byte[] byteArray, int index, char car)
byteArray
- The buffer which contains the dataindex
- Current position in the buffercar
- The character we want to compare with the current buffer
position
true
if the current character equals the given
character.public static boolean isCharASCII(char[] chars, int index, char car)
chars
- The buffer which contains the dataindex
- Current position in the buffercar
- The character we want to compare with the current buffer
position
true
if the current character equals the given
character.public static boolean isHex(byte[] byteArray, int index)
byteArray
- The buffer which contains the dataindex
- Current position in the buffer
true
if the current character is a Hex Charpublic static boolean isHex(char[] chars, int index)
chars
- The buffer which contains the dataindex
- Current position in the buffer
true
if the current character is a Hex Charpublic static boolean isDigit(byte[] byteArray)
byteArray
- The buffer which contains the data
true
if the current character is a Digitpublic static boolean isAlphaASCII(byte[] byteArray, int index)
byteArray
- The buffer which contains the dataindex
- Current position in the buffer
true
if the current character is an Alpha
characterpublic static boolean isAlphaASCII(char[] chars, int index)
chars
- The buffer which contains the dataindex
- Current position in the buffer
true
if the current character is an Alpha
characterpublic static boolean isDigit(byte[] byteArray, int index)
byteArray
- The buffer which contains the dataindex
- Current position in the buffer
true
if the current character is a Digitpublic static boolean isDigit(char[] chars, int index)
chars
- The buffer which contains the dataindex
- Current position in the buffer
true
if the current character is a Digitpublic static boolean isDigit(char[] chars)
chars
- The buffer which contains the data
true
if the current character is a Digitpublic static boolean isAlphaDigitMinus(byte[] byteArray, int index)
byteArray
- The buffer which contains the dataindex
- Current position in the buffer
public static boolean isAlphaDigitMinus(char[] chars, int index)
chars
- The buffer which contains the dataindex
- Current position in the buffer
public static boolean isEmpty(java.lang.String str)
Checks if a String is empty ("") or null.
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("bob") = false StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
str
- the String to check, may be null
true
if the String is empty or nullpublic static boolean isEmpty(byte[] bytes)
bytes
- The bytes array to check, may be null
true
if the bytes array is empty or nullpublic static boolean isNotEmpty(java.lang.String str)
Checks if a String is not empty ("") and not null.
StringUtils.isNotEmpty(null) = false StringUtils.isNotEmpty("") = false StringUtils.isNotEmpty(" ") = true StringUtils.isNotEmpty("bob") = true StringUtils.isNotEmpty(" bob ") = true
str
- the String to check, may be null
true
if the String is not empty and not nullpublic static java.lang.String trim(java.lang.String str)
Removes spaces (char <= 32) from both start and ends of this String,
handling null
by returning null
.
StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"
str
- the String to be trimmed, may be null
null
if null String inputpublic static byte[] trim(byte[] bytes)
Removes spaces (char <= 32) from both start and ends of this bytes
array, handling null
by returning null
.
StringUtils.trim(null) = null StringUtils.trim("") = "" StringUtils.trim(" ") = "" StringUtils.trim("abc") = "abc" StringUtils.trim(" abc ") = "abc"
null
if null String inputpublic static java.lang.String trimLeft(java.lang.String str)
Removes spaces (char <= 32) from start of this String, handling
null
by returning null
.
StringUtils.trimLeft(null) = null StringUtils.trimLeft("") = "" StringUtils.trimLeft(" ") = "" StringUtils.trimLeft("abc") = "abc" StringUtils.trimLeft(" abc ") = "abc "
str
- the String to be trimmed, may be null
null
if null String inputpublic static int trimLeft(char[] chars, int pos)
Removes spaces (char <= 32) from start of this array, handling
null
by returning null
.
StringUtils.trimLeft(null) = null StringUtils.trimLeft("") = "" StringUtils.trimLeft(" ") = "" StringUtils.trimLeft("abc") = "abc" StringUtils.trimLeft(" abc ") = "abc "
chars
- the chars array to be trimmed, may be null
public static int trimLeft(byte[] bytes, int pos)
Removes spaces (char <= 32) from start of this array, handling
null
by returning null
.
StringUtils.trimLeft(null) = null StringUtils.trimLeft("") = "" StringUtils.trimLeft(" ") = "" StringUtils.trimLeft("abc") = "abc" StringUtils.trimLeft(" abc ") = "abc "
bytes
- the byte array to be trimmed, may be null
public static java.lang.String trimRight(java.lang.String str)
Removes spaces (char <= 32) from end of this String, handling
null
by returning null
.
StringUtils.trimRight(null) = null StringUtils.trimRight("") = "" StringUtils.trimRight(" ") = "" StringUtils.trimRight("abc") = "abc" StringUtils.trimRight(" abc ") = " abc"
str
- the String to be trimmed, may be null
null
if null String inputpublic static int trimRight(char[] chars, int pos)
Removes spaces (char <= 32) from end of this array, handling
null
by returning null
.
StringUtils.trimRight(null) = null StringUtils.trimRight("") = "" StringUtils.trimRight(" ") = "" StringUtils.trimRight("abc") = "abc" StringUtils.trimRight(" abc ") = " abc"
chars
- the chars array to be trimmed, may be null
public static int trimRight(byte[] bytes, int pos)
Removes spaces (char <= 32) from end of this array, handling
null
by returning null
.
StringUtils.trimRight(null) = null StringUtils.trimRight("") = "" StringUtils.trimRight(" ") = "" StringUtils.trimRight("abc") = "abc" StringUtils.trimRight(" abc ") = " abc"
bytes
- the chars array to be trimmed, may be null
public static java.lang.String upperCase(java.lang.String str)
Converts a String to upper case as per String.toUpperCase()
.
A null
input String returns null
.
StringUtils.upperCase(null) = null StringUtils.upperCase("") = "" StringUtils.upperCase("aBc") = "ABC"
str
- the String to upper case, may be null
null
if null String inputpublic static java.lang.String lowerCase(java.lang.String str)
Converts a String to lower case as per String.toLowerCase()
.
A null
input String returns null
.
StringUtils.lowerCase(null) = null StringUtils.lowerCase("") = "" StringUtils.lowerCase("aBc") = "abc"
str
- the String to lower case, may be null
null
if null String inputpublic static boolean equals(java.lang.String str1, java.lang.String str2)
Compares two Strings, returning true
if they are equal.
null
s are handled without exceptions. Two
null
references are considered to be equal. The comparison
is case sensitive.
StringUtils.equals(null, null) = true StringUtils.equals(null, "abc") = false StringUtils.equals("abc", null) = false StringUtils.equals("abc", "abc") = true StringUtils.equals("abc", "ABC") = false
str1
- the first String, may be nullstr2
- the second String, may be null
true
if the Strings are equal, case sensitive, or
both null
String.equals(Object)
public static java.lang.String utf8ToString(byte[] bytes)
bytes
- The byte array to be transformed to a String
public static java.lang.String utf8ToString(byte[] bytes, int length)
bytes
- The byte array to be transformed to a Stringlength
- The length of the byte array to be converted
public static byte[] getBytesUtf8(java.lang.String string)
string
- The string to be transformed to a byte array
public static java.lang.String listToString(java.util.List list)
list
- The list to transform to a string
public static java.lang.String listToString(java.util.List list, java.lang.String tabs)
list
- The list to transform to a string
public static java.lang.String mapToString(java.util.Map map)
map
- The map to transform to a string
public static java.lang.String mapToString(java.util.Map map, java.lang.String tabs)
map
- The map to transform to a string
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |