|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectariba.util.core.StringUtil
public final class StringUtil
String Utilities. These are utilities for working with strings.
Nested Class Summary | |
---|---|
static class |
StringUtil.SearchResult
Small struct class that captures the result of search for a string within some other unidentified string or stream. |
Method Summary | |
---|---|
static java.lang.String |
bit(int pint)
Create the appropriate bit string for use in a LIKE clause for a string bit mask. |
static java.lang.String |
bitClear(java.lang.String value,
int pos)
Bit Clear - clear the bit with the given position in the given string Passing pos = 0 and value = "101" would yield "100". |
static java.lang.String |
bitSet(java.lang.String value,
int pos)
Bit Set - sets the bit with the given position in the given string Passing pos = 0 and value = "100" would yield "101". |
static boolean |
bitTest(java.lang.String value,
int pos)
Bit Test - test the bit for the given position in the given string Passing pos = 0 and value = "100" would yield false Passing pos = 1 and value = "100" would yield false Passing pos = 2 and value = "100" would yield true |
static int |
calcTruncateSize(java.lang.String label,
int maxSize,
int numLines)
Returns the ideal size to truncate based on the max number characters to display by trying to fit the most words / characters before truncation. |
static java.lang.String |
capitalizeFirstChar(java.lang.String string)
Returns string with the first character upper-cased. |
static boolean |
charsEqualString(char[] chars,
java.lang.String s)
Compare a character array to a string without allocating a temporary string. |
static java.lang.String |
compressSpaces(java.lang.String s)
Replace all repeating instances of a space in a String with a single space. |
static boolean |
contains(java.lang.String string,
java.lang.String phrase)
Case insensitive string search for a substring. |
static long |
convertFromBase26(java.lang.String numberInBase26)
Convenience method that converts a number in base 26 (as might have been constructed by convertToBase26(long) ) back into an integer. |
static java.lang.String |
convertToBase26(long value)
Returns the Base26 representation of the provided integer; where 0 = a, 25 = z, 26 = ba, etc. |
static java.lang.String[] |
delimitedStringToArray(java.lang.String str,
char delimiter)
Tokenize a String with a specified separator character and return an array. |
static boolean |
endsWith(java.lang.CharSequence s,
java.lang.CharSequence sub)
Evaluates if the first CharSequence ends with the second. |
static boolean |
endsWithAny(java.lang.CharSequence s,
java.lang.CharSequence... subs)
Evaluate if hte first CharSequence ends with any of the following CharSequences. |
static boolean |
equalsIgnoreCase(java.lang.String one,
java.lang.String two)
Compares if two strings are equal or not. |
static java.lang.String |
escapeRegEx(java.lang.String regex)
Escapes metacharacters in a regex into literals. |
static java.lang.String |
fastJoin(java.util.Collection collection,
java.lang.String joinString)
Joins collection of elements with a string between each pair of elements. |
static java.lang.String |
fastJoin(java.util.List vector,
java.lang.String joinString)
Joins vector of elements with a string between each pair of elements. |
static byte[] |
getBytesUTF8(java.lang.String string)
|
static java.lang.String |
getStringUTF8(byte[] bytes)
|
static int |
indexOf(java.lang.String string,
java.lang.String[] substrings)
Search for any of an array of substrings inside of the specified string. |
static java.lang.String |
intern(java.lang.String source)
|
static boolean |
is7bitAscii(char c)
Specifies whether the given character is a 7-ascii character |
static boolean |
isAllDigits(java.lang.String string)
Check if a String is composed entirely of digits using Character.isDigit |
static boolean |
isJavaIdentifier(java.lang.String identifier)
Check if a string is a legal java identifier. |
static boolean |
isValidEmailLocalPart(java.lang.String string)
Validate the local part of an email address per RFC-822 |
static boolean |
isValidURIPart(java.lang.String string,
boolean allowForExtendedMarks)
Specifies whether the given String is a valid URI part. |
static java.lang.String |
join(java.util.List vector,
java.lang.String joinString)
Joins vector of elements with a string between each pair of elements. |
static java.lang.String |
join(java.lang.Object[] objects,
java.lang.String joinString)
Joins array of elements with a string between each pair of elements. |
static java.lang.String |
join(java.lang.Object[] objects,
java.lang.String joinString,
int index,
int length)
Joins a sub-array of the given objects array elements
with a string between each pair of elements. |
static boolean |
nullOrEmptyOrBlankString(java.lang.String string)
Determine if a string is null or empty or entirely spaces. |
static boolean |
nullOrEmptyString(java.lang.String string)
Determine if a String is null or empty. |
static int |
occurs(java.lang.String[] array,
java.lang.String string)
Count the number of occurrences of a string in an array of Strings. |
static int |
occurs(java.lang.String str,
char ch)
Count the number of occurrences of a character in a string. |
static int |
occurs(java.lang.String str,
java.lang.String substr)
Count the number of occurrences of a substring in a string. |
static java.lang.String[] |
parseMatchingParentheses(java.lang.String str)
Parse the input String into two components separated by
matching left and right parentheses. |
static java.lang.String |
printSecret(java.lang.String value)
|
static java.lang.String |
removeCarriageReturns(java.lang.String string)
Removes the newlines and carriage returns from string
and returns the resultant string. |
static java.lang.String[] |
removeDuplicates(java.lang.String[] s)
To remove duplicate elements from a String array s |
static java.lang.String[] |
removeDuplicates(java.lang.String[] s,
StringArray duplicateArray)
To remove duplicate elements from a String array s |
static java.lang.String |
removeLeadingSlashIfAny(java.lang.String path)
Removes the leading slash from the given String. |
static java.lang.String |
removeTrailingSlashIfAny(java.lang.String path)
Removes the trailing slash from the given String. |
static java.lang.String |
replaceCharByChar(java.lang.String string,
char marker,
char replace)
Replace all occurrences of a character in a String with another character. |
static java.lang.String |
replaceCharByString(java.lang.String string,
char marker,
java.lang.String replace)
Replace all occurrences of a character in a String with a String. |
static StringUtil.SearchResult |
search(java.lang.String toSearch,
int fromIdx,
java.util.Collection toFind)
Searches for the first one of any of the supplied strings |
static java.lang.String |
separateAtCapitalization(java.lang.String string)
|
static java.lang.String |
separateAtCapitalization(java.lang.String string,
char separationChar)
|
static java.util.List |
splitWithQuotes(java.lang.String str,
boolean keepQuotes)
Splits a string up into chunks using a whitespace delimiter. |
static boolean |
startsWithIgnoreCase(java.lang.String string,
java.lang.String other)
Check if a string starts with a specific substring in a case insensitive manner. |
static java.lang.String |
strcat(java.lang.String[] elems)
|
static java.lang.String |
strcat(java.lang.String s1,
java.lang.String s2)
|
static java.lang.String |
strcat(java.lang.String s1,
java.lang.String s2,
java.lang.String s3)
|
static java.lang.String |
strcat(java.lang.String s1,
java.lang.String s2,
java.lang.String s3,
java.lang.String s4)
|
static java.lang.String |
strcat(java.lang.String s1,
java.lang.String s2,
java.lang.String s3,
java.lang.String s4,
java.lang.String s5)
|
static java.lang.String |
strcat(java.lang.String s1,
java.lang.String s2,
java.lang.String s3,
java.lang.String s4,
java.lang.String s5,
java.lang.String s6)
|
static java.lang.String |
strcat(java.lang.String s1,
java.lang.String s2,
java.lang.String s3,
java.lang.String s4,
java.lang.String s5,
java.lang.String s6,
java.lang.String s7)
|
static java.lang.String |
strcat(java.lang.String s1,
java.lang.String s2,
java.lang.String s3,
java.lang.String s4,
java.lang.String s5,
java.lang.String s6,
java.lang.String s7,
java.lang.String s8)
|
static java.lang.String |
strcat(java.lang.String s1,
java.lang.String s2,
java.lang.String s3,
java.lang.String s4,
java.lang.String s5,
java.lang.String s6,
java.lang.String s7,
java.lang.String s8,
java.lang.String s9)
|
static int |
stringArrayIndex(java.lang.String[] keys,
java.lang.String key)
Performs a binary search on a sorted string array. |
static boolean |
stringMatchesPattern(java.lang.String str,
java.lang.String pattern)
Checks if a string matches a perl 5 pattern. |
static java.util.List |
stringToStringsListUsingBreakChars(java.lang.String s,
java.lang.String breakChars)
Tokenize a string separated by any separator characters into a List. |
static java.lang.String |
substring(java.lang.String string,
int beginIndex,
int endIndex)
Returns the substring of string from
beginIndex (inclusive) to endIndex ,
exclusive. |
static java.lang.String |
trailing(java.lang.String string,
int length)
Returns the trailing part of string up to a max of
length characters. |
static java.lang.String |
truncate(java.lang.String string,
int length)
Returns this string truncated to a max of length
characters. |
static int |
unorderedStringArrayIndex(java.lang.String[] keys,
java.lang.String key)
Search an unsorted array of strings. |
static int |
unorderedStringArrayIndexIdentical(java.lang.String[] keys,
java.lang.String key)
Search an unsorted array of strings. |
static java.lang.String |
wrap(java.lang.String string,
java.lang.String lineSeparator,
int wrapLength)
Return the string argument with the lineSeparator inserted every wrapLength- characters. |
static java.lang.String |
wrapHTML(java.lang.String string,
int wrapLength)
Return the string argument with " " tag inserted every wrapLength- characters. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean nullOrEmptyString(java.lang.String string)
string
- a String object to check
public static boolean nullOrEmptyOrBlankString(java.lang.String string)
string
- a String object to check
public static java.lang.String capitalizeFirstChar(java.lang.String string)
string
with the first character upper-cased.
If string
is already uppercased or if it is null
or less than one in length, the passed-in value is returned.
string
with the first character upper-casedpublic static java.lang.String separateAtCapitalization(java.lang.String string)
public static java.lang.String separateAtCapitalization(java.lang.String string, char separationChar)
public static final int stringArrayIndex(java.lang.String[] keys, java.lang.String key)
keys
- a sorted array of string keys to searchkey
- a key to search for
public static java.lang.String intern(java.lang.String source)
public static boolean stringMatchesPattern(java.lang.String str, java.lang.String pattern)
public static final int unorderedStringArrayIndexIdentical(java.lang.String[] keys, java.lang.String key)
keys
- an array of string keys to searchkey
- a key to search for using the == operator
public static final int unorderedStringArrayIndex(java.lang.String[] keys, java.lang.String key)
keys
- an array of string keys to searchkey
- a key to search for using the equals() method
public static java.lang.String[] delimitedStringToArray(java.lang.String str, char delimiter)
Takes a string in the form "Description.Price.Amount" with a delimiter of '.' and turns it into an array of strings:
path[0] = "Description" path[1] = "Price" path[2] = "Amount"
str
- a string to tokenizedelimiter
- the delimiter to use when tokenizing
ListUtil.delimitedStringToList(java.lang.String, char)
public static int occurs(java.lang.String str, char ch)
str
- the String to count inch
- the character to count the occurrences of
public static int occurs(java.lang.String str, java.lang.String substr)
str
- the String to count insubstr
- the substring to count the occurrences of
public static int occurs(java.lang.String[] array, java.lang.String string)
array
- an array of Strings to search in. There may not
be null elements in the array.string
- the String to match against
public static boolean contains(java.lang.String string, java.lang.String phrase)
string
- the String to search inphrase
- the String to search for
public static int indexOf(java.lang.String string, java.lang.String[] substrings)
string
- the String to search insubstrings
- the strings to search for
-1
if the string is not found.public static java.lang.String replaceCharByChar(java.lang.String string, char marker, char replace)
string
- the string to do do the replacing on. If
null
or empty string, the string is simply
returned.marker
- the character to removereplace
- the character to replace the removed character
marker with
public static java.lang.String replaceCharByString(java.lang.String string, char marker, java.lang.String replace)
string
- the string to do do the replacing on. If
null
or empty string, the string is simply
returned.marker
- the character to removereplace
- the String that will replace the removed
marker. If an empty string or null
is
passed, any occurrences of the marker are removed from
the initial string.
public static java.lang.String compressSpaces(java.lang.String s)
s
- the string to be compressed
public static boolean charsEqualString(char[] chars, java.lang.String s)
chars
- the characters to check against the Strings
- the string to compare to the characters
public static boolean endsWith(java.lang.CharSequence s, java.lang.CharSequence sub)
s
- The search space.sub
- The substring to evaluate.
public static boolean endsWithAny(java.lang.CharSequence s, java.lang.CharSequence... subs)
s
- The search space.subs
- The substrings to evaluate.
public static java.util.List stringToStringsListUsingBreakChars(java.lang.String s, java.lang.String breakChars)
s
- the String to tokenizebreakChars
- a string containing all characters to use as
separator characters for the tokenize
public static java.lang.String substring(java.lang.String string, int beginIndex, int endIndex)
string
from
beginIndex
(inclusive) to endIndex
,
exclusive.
This function is "safe" in the sense that it will bound
beginIndex
and endIndex
appropriately so
that no exceptions will be thrown. E.g. if beginIndex
is
less than zero, the zero index will be used for the substring instead.
string
- the string to substringbeginIndex
- the beginning index, inclusiveendIndex
- the end index, exclusive
null
if
string
is null
public static java.lang.String truncate(java.lang.String string, int length)
length
characters.
string
- the string to truncatelength
- the length of the truncated string
null
if
string
is null
public static java.lang.String trailing(java.lang.String string, int length)
string
up to a max of
length
characters.
string
- the string to get the trailing part oflength
- the length of the truncated string
null
if
string
is null
public static java.lang.String join(java.lang.Object[] objects, java.lang.String joinString)
objects
- an array of Objects each which will be toStringed.joinString
- a string to separate each pair of elements, if
null
the empty string is assumed
public static java.lang.String join(java.lang.Object[] objects, java.lang.String joinString, int index, int length) throws java.lang.IndexOutOfBoundsException
objects
array elements
with a string between each pair of elements. The sub-array is
specified by the index
offset and the
length
.Range checking is delegated to the native access provided when accessing array elements.
objects
- an array of Objects each which will be toStringed.joinString
- a string to separate each pair of elements, if
null
the empty string is assumedindex
- the index within the array at which to begin the join of
the elements; should be >= 0
and
<= objects.length
. (Note that if
index == objects.length
, length
must equal
0 in order that an exception will not be thrown.)length
- the number of elements within the array to join
together; should satisfy
index + length <= objects.length
java.lang.IndexOutOfBoundsException
- if bounds specified lead to access
outside the bounds of the objects
arraypublic static java.lang.String fastJoin(java.util.List vector, java.lang.String joinString)
vector
- a vector of Objects each which will be toStringed.joinString
- a string to separate each pair of elements.
public static java.lang.String fastJoin(java.util.Collection collection, java.lang.String joinString)
collection
- a collection of Objects each which will be toStringed.joinString
- a string to separate each pair of elements.
public static java.lang.String join(java.util.List vector, java.lang.String joinString)
vector
- a vector of Objects each which will be formatted
using the formatters.joinString
- a string to separate each pair of elements.
public static boolean isJavaIdentifier(java.lang.String identifier)
identifier
- The string to check
public static boolean startsWithIgnoreCase(java.lang.String string, java.lang.String other)
string
- the string to search inother
- the string to check for
String.startsWith(java.lang.String, int)
,
String.regionMatches(boolean, int, String, int, int)
public static boolean isAllDigits(java.lang.String string)
string
- the String to check
Character.isDigit(char)
public static final java.lang.String bitSet(java.lang.String value, int pos)
public static final java.lang.String bitClear(java.lang.String value, int pos)
public static final boolean bitTest(java.lang.String value, int pos)
public static final java.lang.String bit(int pint)
public static java.lang.String strcat(java.lang.String s1, java.lang.String s2)
public static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3)
public static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4)
public static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5)
public static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5, java.lang.String s6)
public static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5, java.lang.String s6, java.lang.String s7)
public static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5, java.lang.String s6, java.lang.String s7, java.lang.String s8)
public static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5, java.lang.String s6, java.lang.String s7, java.lang.String s8, java.lang.String s9)
public static java.lang.String strcat(java.lang.String[] elems)
public static java.lang.String[] removeDuplicates(java.lang.String[] s)
s
- a String array to unique
public static java.lang.String removeCarriageReturns(java.lang.String string)
string
and returns the resultant string.
string
- the string to remove the carriage returns from
public static java.lang.String[] removeDuplicates(java.lang.String[] s, StringArray duplicateArray)
s
- a String array to uniqueduplicateArray
- a list of duplicate array elements found
in String array s
public static java.lang.String removeTrailingSlashIfAny(java.lang.String path)
path
- the given path String, must not be null.
public static java.lang.String removeLeadingSlashIfAny(java.lang.String path)
path
- the given path String, must not be null.
public static java.lang.String printSecret(java.lang.String value)
public static boolean is7bitAscii(char c)
c
- the character to test
true
if the character c
is a 7-ascii
characterpublic static boolean isValidURIPart(java.lang.String string, boolean allowForExtendedMarks)
true
if all the characters part of the String follow the RFC
speficication.
However because some of these marks can be troublesome, this method will return false
if they are part of the String and allowForExtendedMarks
is false
.
string
- the String to verify.allowForExtendedMarks
- if false
the marks '!', '~', '*', ''', '(' and ')'
will not be considered valid characters (although the RFC 2396 allows them.
true when the String complies with RFC 2396
isValidEmailLocalPart
public static boolean isValidEmailLocalPart(java.lang.String string)
- Validate the local part of an email address per RFC-822
- Parameters:
string
-
- Returns:
- boolean
splitWithQuotes
public static java.util.List splitWithQuotes(java.lang.String str,
boolean keepQuotes)
- Splits a string up into chunks using a whitespace delimiter.
Quoted items are treated as a single chunk.
- Parameters:
str
- the string to splitkeepQuotes
- if true keep the quotes that encapsulate an element
- Returns:
- a List of String containing each seperated element
equalsIgnoreCase
public static boolean equalsIgnoreCase(java.lang.String one,
java.lang.String two)
- Compares if two strings are equal or not. It is different from
equalsIgnoreCase method of java.lang.String in the sense that
it makes a null check of each of the Strings to be compared.
- Parameters:
one
- the String to be comparedtwo
- the String to be compared
- Returns:
- true if both are null or equalsIgnoreCase of
java.lang.String returns true. False if one of them are null
or equalsIgnoreCase of java.lang.String returns false.
wrapHTML
public static java.lang.String wrapHTML(java.lang.String string,
int wrapLength)
- Return the string argument with "
" tag inserted every wrapLength- characters.
Doesn't break a word, correctly handles punctuation and hyphenated words.
- Parameters:
string
- wrapLength
-
- Returns:
- wrapped string
wrap
public static java.lang.String wrap(java.lang.String string,
java.lang.String lineSeparator,
int wrapLength)
- Return the string argument with the lineSeparator inserted every wrapLength- characters.
Doesn't break a word, correctly handles punctuation and hyphenated words.
StringUtil.wrap("Hello World!, null, 9) = Hello
World!
StringUtil.wrap("1234512345", "
", 5) = 1234512345
StringUtil.wrap("12345", 10) = 12345
- Parameters:
string
- The StringlineSeparator
- Line break, "
" by defaultwrapLength
- The position to create a line break
- Returns:
- String
getBytesUTF8
public static byte[] getBytesUTF8(java.lang.String string)
getStringUTF8
public static java.lang.String getStringUTF8(byte[] bytes)
escapeRegEx
public static java.lang.String escapeRegEx(java.lang.String regex)
- Escapes metacharacters in a regex into literals.
search
public static StringUtil.SearchResult search(java.lang.String toSearch,
int fromIdx,
java.util.Collection toFind)
- Searches for the first one of any of the supplied strings
- Parameters:
toSearch
- the string to searchfromIdx
- the index at which to begin the search
- Returns:
- the result of the search
parseMatchingParentheses
public static java.lang.String[] parseMatchingParentheses(java.lang.String str)
- Parse the input
String
into two components separated by
matching left and right parentheses. Only one pair is supported.
- Returns:
- an array containing two elements, the first one is the
first component before the left parenthesis and the second one is
the component wrapped between the left and right perentheses
calcTruncateSize
public static int calcTruncateSize(java.lang.String label,
int maxSize,
int numLines)
- Returns the ideal size to truncate based on the max number characters to display
by trying to fit the most words / characters before truncation.
This method tries to truncate CJK characters as best as it can comparing to latin
characters. Also it specifically truncates long words, such as in German, so that
they can be displayed on the browser inside a fixed with div without causing layout
problems.
- Parameters:
label
- maxSize
- max ideal length before truncationnumLines
- number of lines to display the label in - only used when it's > 0
- Returns:
- number of characters to truncate
convertToBase26
public static java.lang.String convertToBase26(long value)
- Returns the Base26 representation of the provided integer; where 0 = a,
25 = z, 26 = ba, etc.
Right now, we don't support negative values. The reason for this is that
we anticipate that if someone ever wants to use this, they would use it for
generating a unique alphabetical-only string based on some incrementing
number. It's not designed to fully support base 26 as a convenience for
everyone (if you want this just use Integer.toString(i, 26).)
To get upper case letters, just toUpper() the result.
- Parameters:
positive
- integer
- Returns:
- String
convertFromBase26
public static long convertFromBase26(java.lang.String numberInBase26)
- Convenience method that converts a number in base 26 (as might have been
constructed by
convertToBase26(long)
) back into an integer.
- Parameters:
numberInBase26
-
- Returns:
Overview
Package
Class
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.