|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.util.StringUtilities
public final class StringUtilities
Utility methods for manipulating Strings.
Method Summary | ||
---|---|---|
static StringBuffer |
append(StringBuffer strBuf,
byte[] buffer,
int offset,
int length)
Append a subsection of a byte array to a StringBuffer . |
|
static StringBuffer |
append(StringBuffer strBuf,
String str,
int offset,
int length)
Appends a subsection of a String to a StringBuffer . |
|
static StringBuffer |
append(StringBuffer strBuf,
StringBuffer other)
Append a StringBuffer to another StringBuffer . |
|
static StringBuffer |
append(StringBuffer strBuf,
StringBuffer other,
int offset,
int length)
Append a subsection of a StringBuffer to another StringBuffer . |
|
static String |
cStr2String(byte[] b,
int start,
int len)
Converts C/C++ string into a Java String. |
|
static int |
compareObjectToStringIgnoreCase(Object o1,
Object o2)
Compares the string form of two objects, ignoring case. |
|
static int |
compareToHandleSpecialChars(String s1,
String s2)
Compare two strings, ignoring case and handling special characters differently than strict ASCII order. |
|
static int |
compareToIgnoreCase(String s1,
String s2)
Compare two strings, ignoring case. |
|
static int |
compareToIgnoreCase(String s1,
String s2,
int locale)
Compare two strings, ignoring case, taking into account the specified locale. |
|
static int |
computeHashCode(StringBuffer stringBuffer)
Retrieves hashcode of provided string buffer. |
|
static int |
computeReverseLookupHashCodeBytes(byte[] bytes,
int start,
int length)
Retrieves restricted hashcode for section of a byte array. |
|
static int |
computeReverseLookupHashCodeBytes(byte[] bytes,
int start,
int length,
boolean allChars)
Retrieves restricted hashcode for section of a byte array. |
|
static int |
computeReverseLookupHashCodeString(String string)
Retrieves restricted hashcode for string (for use in reverse lookups). |
|
static int |
computeReverseLookupHashCodeString(String string,
boolean allChars)
Retrieves restricted hashcode for string (for use in reverse lookups). |
|
static void |
convertToOriginal(StringBuffer stringBuffer,
int start,
int length)
Converts the string buffer content (characters) to the first characters in a decomposition. |
|
static String[] |
copy(String[] array)
Retrieves a duplicate copy of a String array. |
|
static int |
hashCode(String str,
int fromIndex,
int toIndex,
boolean ignoreCase)
Retrieves hashcode of provided string between the offsets provided. |
|
static int |
hashCodeIgnoreCase(String str)
Retrieves case-insensitive hashcode of provided string. |
|
static int |
indexOf(String string,
char ch,
int fromIndex,
int toIndex)
Retrieves first occurrence of character in section of provided string. |
|
static int |
indexOf(String string,
int ch,
int fromIndex,
int toIndex)
Retrieves first occurrence of character in section of provided string. |
|
static String |
removeChars(String src,
String remove)
Removes specified characters from a string. |
|
static boolean |
startsWithIgnoreCase(String string,
String prefix)
Determines if target string begins with provided prefix. |
|
static boolean |
startsWithIgnoreCaseAndAccents(String string,
String prefix)
Determines if target string begins with a provided prefix, igoring the case and accents of the characters in the string. |
|
static boolean |
strEqual(String s1,
String s2)
Compares two (possibly null) strings for equality. |
|
static boolean |
strEqualIgnoreCase(String s1,
String s2)
Compares two (possibly null) strings for equality, ignoring their case. |
|
static long |
stringHashToLong(String key)
Returns the first 8 bytes of a SHA1 digest as a long. |
|
static String[] |
stringToKeywords(String string)
Extracts keyword tokens from provided string. |
|
static int |
stringToKeywords(String stringContainingKeywords,
int[] startOffsets,
int resultOffset)
Parses string into keywords. |
|
static int |
stringToKeywords(String string,
String[] wordArray,
int index)
Extracts keyword tokens from provided string, placing them into provided array. |
|
static String[] |
stringToWords(String string)
Extracts word tokens from provided string. |
|
static int |
stringToWords(String stringContainingWords,
int[] indexResults,
int resultOffset)
Parses string into words. |
|
static int |
stringToWords(String string,
String[] wordArray,
int index)
Extracts word tokens from provided string, placing them into provided array. |
|
static int |
stringToWordsOrKeywords(String stringContainingKeywords,
int[] startOffsets,
int[] endOffsets,
int resultOffset,
boolean keywords)
Native method that parses string to words or keywords |
|
static String |
toLowerCase(String str,
int locale)
Convert string to lower case , using the specified locale. |
|
static void |
toLowerCase(StringBuffer stringBuffer,
int start,
int length,
int locale)
Converts the string buffer content (characters) to lower case, using the specified locale. |
|
static String |
toUpperCase(String str,
int locale)
Convert string to upper case , using the specified locale. |
|
static int |
writeUTF(String str,
DataOutput out)
Writes a string to the specified DataOutput using UTF-8 encoding in a machine-independent manner. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void convertToOriginal(StringBuffer stringBuffer, int start, int length)
Examples: character U+00E9 will be replaced with U+0065; character U+1EDA will be replaced with U+004F.
stringBuffer
- string buffer containing characters to use as source.start
- The starting offset. If this value is less than 0 IllegalArgumentException is thrown.length
- Number of characters to include in the conversion. If this value is less than 0, or
(start + length) > length of the received string buffer IllegalArgumentException is thrown.
NullPointerException
- if any argument is null
.CharacterUtilities.getOriginal(char)
public static void toLowerCase(StringBuffer stringBuffer, int start, int length, int locale)
stringBuffer
- string buffer containing characters to convertstart
- The starting offset.length
- Number of characters to include in the conversion.locale
- locale code to use for the conversion
NullPointerException
- if stringBuffer is null
.
IllegalArgumentException
- if length or start is less than 0, or (start + length) > length of the received string buffer.public static int compareToIgnoreCase(String s1, String s2)
This function converts each character of s1 to upper case and each character of s2 to upper case, in the context of the specified locale, and compares the converted characters one by one. It is assumed that conversion of 1 charcater to the upper case will result in 1 upper case(if exists) character.
s1
- First string to compare.s2
- Second string to compare.
NullPointerException
- if any argument is null
.public static int compareToHandleSpecialChars(String s1, String s2)
This function converts each character of s1 to upper case and each character of s2 to upper case, in the context of the specified locale, and compares the converted characters one by one. It is assumed that conversion of 1 charcater to the upper case will result in 1 upper case(if exists) character. The following special characters are sorted before any others, in the order they appear below:
SPACE ! " # $ % & ( * , . / : ; @ [ ] ^ _ { | } ~ + < = > ' -
s1
- First string to compare.s2
- Second string to compare.
NullPointerException
- if any argument is null
.public static int compareToIgnoreCase(String s1, String s2, int locale)
This function converts each character of s1 to upper case and each character of s2 to upper case, in the context of the specified locale, and compares the converted characters one by one. It is assumed that conversion of 1 charcater to the upper case will result in 1 upper case(if exists) character.
s1
- First string to compare.s2
- Second string to compare.locale
- The locale code to use for the conversion.
NullPointerException
- if any argument is null
.public static String toLowerCase(String str, int locale)
str
- String to convertlocale
- locale code to use for the conversion
NullPointerException
- if the argument is null
.public static String toUpperCase(String str, int locale)
str
- String to convertlocale
- locale code to use for the conversion
NullPointerException
- if the argument is null
.public static int computeHashCode(StringBuffer stringBuffer)
An identical hashcode would be produced for a String instance containing the same data.
stringBuffer
- String buffer for which to retrieve a hashcode.
NullPointerException
- if the argument is null
.public static int hashCodeIgnoreCase(String str)
An hashcode identical to str.toLowerCase().hashCode() without the extra object creation.
str
- String for which to retrieve a case-insensitive hashcode.
NullPointerException
- if the argument is null
.public static int hashCode(String str, int fromIndex, int toIndex, boolean ignoreCase)
An hashcode identical to str.substring(fromIndex, toIndex).hashCode() without the extra object creation.
str
- String for which to retrieve a hashcode.fromIndex
- First element in string to look at. If this value is
less than 0, or if the value is greater than the toIndex parameter an
IllegalArgumentException is thrown.toIndex
- Last element in string to look at. If this value is
greater than the length of the string, this method assumes it has the
same value as the length of the string.ignoreCase
- Whether or not to compute a case-insensitive hashcode.
NullPointerException
- if any argument is null
.public static int computeReverseLookupHashCodeString(String string)
The hash only considers alphas, numbers, *
, #
,
and the @
sign, with all characters being lower case.
string
- String for which to retrieve the hashcode.
NullPointerException
- if the argument is null
.public static int computeReverseLookupHashCodeString(String string, boolean allChars)
The hash only considers alphas, numbers, *
, #
,
and the @
sign, with all characters being lower case.
string
- String for which to retrieve the hashcode.allChars
- true if all characters should be hashed, false if just the subset above.
NullPointerException
- if any argument is null
.public static int computeReverseLookupHashCodeBytes(byte[] bytes, int start, int length)
The hash only considers alphas, numbers, *
, #
,
and the @
sign, with all characters being lower case.
bytes
- Byte array containing section for which to retrieve the
hashcode.start
- First element to include in the compuatation.length
- Number of bytes to include in the computation.
NullPointerException
- if any argument is null
.public static int computeReverseLookupHashCodeBytes(byte[] bytes, int start, int length, boolean allChars)
The hash only considers alphas, numbers, *
, #
,
and the @
sign, with all characters being lower case.
bytes
- Byte array containing section for which to retrieve the
hashcode.start
- First element to include in the compuatation.length
- Number of bytes to include in the computation.allChars
- true if all characters should be hashed, false if just the subset above.
NullPointerException
- if any argument is null
.public static boolean startsWithIgnoreCase(String string, String prefix)
string
- Target string to check.prefix
- Prefix to look for.
NullPointerException
- if any argument is null
.public static boolean startsWithIgnoreCaseAndAccents(String string, String prefix)
string
- The Target string to check.prefix
- The prefix to look for.
public static String[] stringToWords(String string)
A word is a contiguous block of upper case and lower case characters, with the adjacent characters at either end, if they exist, not being upper or lower case.
string
- String to tokenize.
public static String[] stringToKeywords(String string)
A keyword is the same as a word except it may contain additional characters that are necessary for keywords.
string
- String to tokenize.
StringUtilities.stringToWords(java.lang.String)
public static int stringToWords(String stringContainingWords, int[] indexResults, int resultOffset) throws ArrayIndexOutOfBoundsException
This method computes the positions of words in a target string. A word is defined as a contiguous block of upper and lower case characters, with the adjacent characters at either end (if they exist) not upper or lower case.
If the resulting array is not large enough to hold the computed
indexes, an ArrayIndexOutOfBoundsException
is thrown.
stringContainingWords
- Target string to parse.indexResults
- Array of word positions in the target string.resultOffset
- First element of the results array to contain the
first word position for the target string.
ArrayIndexOutOfBoundsException
- If the results array is not large
enough to contain the positions of all the words found in the target string.public static int stringToKeywords(String stringContainingKeywords, int[] startOffsets, int resultOffset) throws ArrayIndexOutOfBoundsException
This method computes the positons of keywords in a target string. A keyword is the same as a word except it may contain additional characters that are necessary for keywords.
If the resulting array is not large enough to hold the computed
indexes, an ArrayIndexOutOfBoundsException
is thrown.
stringContainingKeywords
- Target string to parse.indexResults
- Array of keyword positions in the target string.resultOffset
- First element of the results array to contain the
first keyword position for the target string.
ArrayIndexOutOfBoundsException
- If the results array is not large
enough to contain the positions of all the keywords found in the target
string.StringUtilities.stringToWords(String, int[], int)
public static int stringToWordsOrKeywords(String stringContainingKeywords, int[] startOffsets, int[] endOffsets, int resultOffset, boolean keywords) throws ArrayIndexOutOfBoundsException
stringContainingKeywords
- Target string to parse.startOffsets[]
- Array of offsets for words' start positions.endOffsets[]
- Array of offsets for words' end positions.resultOffset
- First element of the offsets arrays.keywords
- Boolean that says whether string should be parsed for words or keywords.
ArrayIndexOutOfBoundsException
- If the offsets arrays are not large
enough to contain the positions of all the keywords found in the target
string.public static int stringToWords(String string, String[] wordArray, int index)
A word is a contiguous block of upper case and lower case characters, with the adjacent characters at either end, if they exist, not being alphanumeric.
string
- String to tokenize.wordArray
- Array to contain the word tokens found in provided
string.index
- Position in the word array at which to start adding words
found in provided string.
public static int stringToKeywords(String string, String[] wordArray, int index)
A keyword is the same as a word except it may contain additional characters that are necessary for keywords.
string
- String to tokenize.wordArray
- Array to contain the keyword tokens found in the
provided string.index
- Position in wordArray at which to start adding keywords
found in the provided string.
public static boolean strEqualIgnoreCase(String s1, String s2)
No attempt is currently made to pay attention to ASCII ordering. Two null strings are considered equal.
s1
- First string to compare.s2
- Second string to compare.
public static boolean strEqual(String s1, String s2)
Two null strings are considered equal.
s1
- First string to compare.s2
- Second string to compare.
public static final String cStr2String(byte[] b, int start, int len)
This method strips off the trailing nulls. Use this instead of
String.trim()
if you don't want to end up creating two string
objects.
b
- Byte array containing C/C++ string data.start
- First byte in the C/C++ string.len
- Length of the C/C++ string (this may include nulls that this
method will strip.
NullPointerException
- if the argument is null
.public static int compareObjectToStringIgnoreCase(Object o1, Object o2)
This method invokes Object.toString()
on both provided objects, and
then compares the two return values for equality. No attempt is
currently made to pay attention to ASCII ordering. A null object sorts
before a non-null object.
o1
- First object to compare.o2
- Second object to compare.
public static int indexOf(String string, char ch, int fromIndex, int toIndex)
string
- String containing section search.ch
- Character to look for.fromIndex
- First element in string to look at. If this value is
less than 0, this method assumes it has the value 0. If this value is
greater than the toIndex parameter, this method assumes it has the same
value as the toIndex parameter.toIndex
- Last element in string to look at. If this value is
greater than the length of the string, this method assumes it has the
same value as the length of the string.
public static int indexOf(String string, int ch, int fromIndex, int toIndex)
string
- String containing section search.ch
- Character to look for.fromIndex
- First element in string to look at. If this value is
less than 0, this method assumes it has the value 0. If this value is
greater than the toIndex parameter, this method assumes it has the same
value as the toIndex parameter.toIndex
- Last element in string to look at. If this value is
greater than the length of the string, this method assumes it has the
same value as the length of the string.
NullPointerException
- if any argument is null
.public static String removeChars(String src, String remove)
src
- Source string; may not be null.remove
- String containing characters to remove from source string;
may not be null.
NullPointerException
- if any argument is null
.public static long stringHashToLong(String key)
key
- The string to convert to a long.
NullPointerException
- if the argument is null
.public static StringBuffer append(StringBuffer strBuf, String str, int offset, int length)
StringBuffer
.
Note this has the same affect as:
for(int i = 0; i < length; i++) strBuf.append( str.charAt(offset+i) );
strBuf
- The string buffer to append the string to.str
- The string to append onto the string buffer.offset
- The offset (starting position) into the string of the subsection to append.length
- The number of characters to append.
strBuf
.
StringIndexOutOfBoundsException
- if one or both of offset
or length
is less
than zero or if offset+length
is greater than str.length()
.
NullPointerException
- if any argument is null
.public static StringBuffer append(StringBuffer strBuf, byte[] buffer, int offset, int length)
StringBuffer
.
Note this has the same affect as:
for(int i = 0; i < length; i++) strBuf.append( buffer[offset+i] );
strBuf
- The string buffer to append the byte array data to.buffer
- The byte array to append onto the string buffer.offset
- The offset into buffer
of the subsection to append.length
- The number of bytes to append.
strBuf
.
ArrayIndexOutOfBoundsException
- if one or both of offset
or length
is less
than zero or if offset+length
is greater than buffer.length
.
NullPointerException
- if any argument is null
.public static StringBuffer append(StringBuffer strBuf, StringBuffer other)
StringBuffer
to another StringBuffer
.
strBuf
- The string buffer to append to.other
- The string buffer that will be appended to strBuf
.
strBuf
.
NullPointerException
- if any argument is null
.public static StringBuffer append(StringBuffer strBuf, StringBuffer other, int offset, int length)
StringBuffer
to another StringBuffer
.
strBuf
- The string buffer to append to.other
- The string buffer whose subsection will be appended to strBuf
.offset
- The offset into other
of the subsection to append.length
- The number of characters to append.
strBuf
.
NullPointerException
- if any argument is null
.
ArrayIndexOutOfBoundsException
- if one or both of offset
or length
is less
than zero or if offset+length
is greater than other.length()
.public static int writeUTF(String str, DataOutput out) throws IOException
First, two bytes are written to out as if by the writeShort
method giving the number of bytes to follow. This value is the number of
bytes actually written out, not the length of the string. Following the
length, each character of the string is output, in sequence, using the
UTF-8 encoding for the character. If no exception is thrown, the
counter written
is incremented by the total number of
bytes written to the output stream. This will be at least two
plus the length of str
, and at most two plus
thrice the length of str
.
str
- a string to be written.out
- destination to write to
IOException
- if an I/O error occurs.
NullPointerException
- if any argument is null
.public static String[] copy(String[] array)
array
- Array to copy.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.