Methods Summary |
---|
public java.lang.String[] | allParts(java.lang.String text, java.lang.String delimiters)Returns an array of substrings of the given text.
The separators between the substrings are the given delimiters.
Each character in the delimiter string is treated as a separator.
For each delimiter that is followed immediately by another delimiter an
empty string will be added to the result. There are no empty strings added
to the result for a delimiter at the very beginning of at the very end.
Examples:
allParts( "/A/B//", "/" ) --> { "A", "B", "" }
allParts( "/A,B/C;D", ",;/" ) --> { "A", "B", "C", "D" }
allParts( "A/B,C/D", "," ) --> { "A/B", "C/D" }
return this.parts( text, delimiters, true ) ;
|
public java.lang.String[] | allSubstrings(java.lang.String text, java.lang.String separator)Returns the given text split up into an array of strings, at
the occurrances of the separator string.
In contrary to method allParts() the separator is a one or many
character sequence delimiter. That is, only the exact sequence
of the characters in separator identifies the end of a substring.
Subsequent occurences of separator are not skipped. They are added
as empty strings to the result.
return this.substrings( text, separator, true ) ;
|
public java.lang.String[] | append(java.lang.String[] strings, java.lang.String string)Returns the given string array extended by one element
that hold the specified string.
String[] appStr = { string } ;
return this.append( strings, appStr ) ;
|
public java.lang.String[] | append(java.lang.String[] strings, java.lang.String[] appendStrings)Returns an array of strings that contains all strings given
by the first and second string array. The strings from the
second array will be added at the end of the first array.
String[] newStrings = null ;
if ( strings == null )
return appendStrings ;
if ( appendStrings == null )
return strings ;
newStrings = new String[strings.length + appendStrings.length] ;
System.arraycopy( strings, 0, newStrings, 0, strings.length ) ;
System.arraycopy( appendStrings, 0, newStrings, strings.length, appendStrings.length ) ;
return newStrings ;
|
public java.lang.String[] | appendIfNotThere(java.lang.String[] strings, java.lang.String appendString)Returns an array of strings that contains all strings given
in the first plus the specified string to append, if it is not
already in the given array.
if ( this.contains( strings, appendString ) )
return strings ;
else
return this.append( strings, appendString ) ;
|
public java.lang.String[] | appendIfNotThere(java.lang.String[] strings, java.lang.String[] appendStrings)Returns an array of strings that contains all strings given
in the first plus all strings of the second array that are not
already in the first array.
String[] newStrings = strings ;
if ( appendStrings == null )
return newStrings ;
for ( int i = 0 ; i < appendStrings.length ; i++ )
{
newStrings = this.appendIfNotThere( newStrings, appendStrings[i] ) ;
}
return newStrings ;
|
public java.util.Map | asMap(java.lang.String str)Returns a new map object that contains all key-value pairs of the
specified string.
The separator between the elements is assumed to be ","
and "=" between key and value.
Example:
"main=Fred,support1=John,support2=Stella,manager=Oscar"
Be aware that all leading and trailing whitespaces of keys and values
will be removed!
return this.toMap( str, null, null, null ) ;
|
public java.util.Map | asMap(java.lang.String str, java.lang.String elementSeparator)Returns a new map object that contains all key-value pairs of the
specified string.
The separator between the keys and values is assumed to be "=".
Be aware that all leading and trailing whitespaces of keys and values
will be removed!
return this.toMap( str, elementSeparator, null, null ) ;
|
public java.util.Map | asMap(java.lang.String str, java.lang.String elementSeparator, java.lang.String keyValueSeparator)Returns a new map object that contains all key-value pairs of the
specified string.
Be aware that all leading and trailing whitespaces of keys and values
will be removed!
return this.toMap( str, elementSeparator, keyValueSeparator, null ) ;
|
public java.util.Properties | asProperties(java.lang.String str)Adds all key-value pairs of the given string to a new properties object.
The separator between the elements is assumed to be ","
and "=" between key and value.
Be aware that all leading and trailing whitespaces of keys and values
will be removed!
return this.toProperties( str, null ) ;
|
public java.lang.String | asString(java.lang.String[] strings, java.lang.String separator)Returns a string that contains all given strings concatenated
and separated by the specified separator.
StringBuffer buffer = null ;
buffer = new StringBuffer( strings.length * 20 ) ;
if ( strings.length > 0 )
{
buffer.append( strings[0].toString() ) ;
for ( int i = 1 ; i < strings.length ; i++ )
{
buffer.append( separator ) ;
if ( strings[i] != null )
buffer.append( strings[i] ) ;
}
}
return buffer.toString() ;
|
public java.lang.String | asString(java.lang.String[] strings)Returns a string that contains all given strings concatenated
and separated by comma.
return this.asString( strings, "," ) ;
|
public java.lang.String | center(java.lang.String str, int len)Returns the given string filled (on the right and right)
up to the specified length with spaces.
Example: center( "Mike", 10 ) --> " Mike "
return this.centerCh( str, len, CH_SPACE ) ;
|
public java.lang.String | centerCh(java.lang.String str, int len, char ch)Returns the given string filled equally left and right
up to the specified length with the given character.
Example: centerCh( "A", 5, '_' ) --> "__A__"
Example: centerCh( "XX", 7, '+' ) --> "++XX+++"
String buffer = null ;
int missing = len - str.length() ;
int half = 0 ;
if ( missing <= 0 )
return str ;
half = missing / 2 ;
buffer = this.rightPadCh( str, len-half, ch ) ;
return this.leftPadCh( buffer, len, ch ) ;
|
protected void | collectParts(java.util.List list, java.util.StringTokenizer tokenizer)
while( tokenizer.hasMoreTokens() )
{
list.add( tokenizer.nextToken() ) ;
}
|
protected void | collectParts(java.util.List list, java.util.StringTokenizer tokenizer, java.lang.String delimiter)
String token ;
boolean lastWasDelimiter = false ;
while( tokenizer.hasMoreTokens() )
{
token = tokenizer.nextToken() ;
if ( delimiter.indexOf( token ) >= 0 )
{
if ( lastWasDelimiter )
list.add( "" ) ;
lastWasDelimiter = true ;
}
else
{
list.add( token ) ;
lastWasDelimiter = false ;
}
}
|
public boolean | contains(java.lang.String[] strArray, java.lang.String searchStr, boolean ignoreCase)Returns whether or not the specified string can be found
in the given string array.
if ( ignoreCase )
return this.containsIgnoreCase( strArray, searchStr ) ;
else
return this.contains( strArray, searchStr ) ;
|
public boolean | contains(java.lang.String[] strArray, StringPattern pattern)Returns whether or not a string can be found in the given string array
that matches the specified string pattern.
return ( this.indexOf( strArray, pattern ) >= 0 ) ;
|
public boolean | contains(java.lang.String[] strArray, java.lang.String searchStr)Returns whether or not the specified string can be found
in the given string array.
The comparison of the strings is case-sensitive!
return ( this.indexOf( strArray, searchStr ) >= 0 ) ;
|
public boolean | containsIgnoreCase(java.lang.String[] strArray, java.lang.String searchStr)Returns whether or not the specified string can be found
in the given string array.
The comparison of the strings is case-insensitive!
return ( this.indexOfIgnoreCase( strArray, searchStr ) >= 0 ) ;
|
public java.lang.String[] | copyFrom(java.lang.String[] from, int start)Returns all elements of string array from in a new array
from index start up to the end.
If start index is larger than the array's length, an empty array will be
returned.
if ( from == null )
return null ;
return this.copyFrom( from, start, from.length - 1 ) ;
|
public java.lang.String[] | copyFrom(java.lang.String[] from, int start, int end)Returns all elements of string array from in a new array
from index start up to index end (inclusive).
If end is larger than the last valid index, it will be reduced
to the last index.
If end index is less than start index, an empty array will be
returned.
String[] result ;
int count ;
int stop = end ;
if ( from == null )
return null ;
if ( stop > ( from.length - 1 ) )
stop = from.length - 1 ;
count = stop - start + 1 ;
if ( count < 1 )
return new String[0] ;
result = new String[count] ;
System.arraycopy( from, start, result, 0, count ) ;
return result ;
|
public static org.pf.text.StringUtil | current()Returns the one and only instance of this class.
if ( getSingleton() == null )
setSingleton( new StringUtil() ) ;
return getSingleton() ;
|
public java.lang.String | cutHead(java.lang.String text, java.lang.String separator)Returns the portion of the given string that stands after the last
occurance of the specified separator.
If the separator could not be found in the given string, then the
string is returned unchanged.
Examples:
cutHead( "A/B/C", "/" ) ; // returns "C"
cutHead( "A/B/C", "," ) ; // returns "A/B/C"
int index ;
if ( ( text == null ) || ( separator == null ) )
return text ;
index = text.lastIndexOf( separator ) ;
if ( index < 0 )
return text ;
return text.substring( index + 1 ) ;
|
public java.lang.String | cutTail(java.lang.String text, java.lang.String separator)Returns the portion of the given string that comes before the last
occurance of the specified separator.
If the separator could not be found in the given string, then the
string is returned unchanged.
Examples:
cutTail( "A/B/C", "/" ) ; // returns "A/B"
cutTail( "A/B/C", "," ) ; // returns "A/B/C"
int index ;
if ( ( text == null ) || ( separator == null ) )
return text ;
index = text.lastIndexOf( separator ) ;
if ( index < 0 )
return text ;
return text.substring( 0, index ) ;
|
public java.lang.String | getDelimitedSubstring(java.lang.String text, java.lang.String startDelimiter, java.lang.String endDelimiter)Returns the first substring that is enclosed by the specified delimiters.
The delimiters are not included in the return string.
Example:
getDelimitedSubstring( "This {placeholder} belongs to me", "{", "}" )
--> returns "placeholder"
int start ;
int stop ;
String subStr = "" ;
if ( ( text != null ) && ( startDelimiter != null )
&& ( endDelimiter != null ) )
{
start = text.indexOf( startDelimiter ) ;
if ( start >= 0 )
{
stop = text.indexOf( endDelimiter, start + 1 ) ;
if ( stop > start )
subStr = text.substring( start + 1, stop ) ;
}
}
return subStr ;
|
public java.lang.String | getDelimitedSubstring(java.lang.String text, java.lang.String delimiter)Returns the first substring that is enclosed by the specified delimiter.
The delimiters are not included in the return string.
Example:
getDelimitedSubstring( "File 'text.txt' not found.", "'", "'" )
--> returns "text.txt"
return this.getDelimitedSubstring( text, delimiter, delimiter ) ;
|
private static org.pf.text.StringUtil | getSingleton()
return singleton ;
|
public int | indexOf(java.lang.String[] strArray, StringPattern pattern)Returns the index of the first string in the given string array that
matches the specified string pattern.
If no string is found in the array the result is -1.
if ( ( strArray == null ) || ( strArray.length == 0 ) )
return -1 ;
boolean found = false ;
for ( int i = 0 ; i < strArray.length ; i++ )
{
if ( strArray[i] == null )
{
if ( pattern == null )
found = true ;
}
else
{
if ( pattern != null )
found = pattern.matches( strArray[i] ) ;
}
if ( found )
return i ;
}
return -1 ;
|
public int | indexOf(java.lang.String[] strArray, java.lang.String searchStr)Returns the index of the specified string in the given string array.
It returns the index of the first occurrence of the string.
If the string is not found in the array the result is -1.
The comparison of the strings is case-sensitive!
return this.indexOfString( strArray, searchStr, false ) ;
|
public int | indexOfIgnoreCase(java.lang.String[] strArray, java.lang.String searchStr)Returns the index of the specified string in the given string array.
It returns the index of the first occurrence of the string.
If the string is not found in the array the result is -1.
The comparison of the strings is case-insensitive!
return this.indexOfString( strArray, searchStr, true ) ;
|
protected int | indexOfString(java.lang.String[] strArray, java.lang.String searchStr, boolean ignoreCase)
if ( ( strArray == null ) || ( strArray.length == 0 ) )
return -1 ;
boolean found = false ;
for ( int i = 0 ; i < strArray.length ; i++ )
{
if ( strArray[i] == null )
{
if ( searchStr == null )
found = true ;
}
else
{
if ( ignoreCase )
found = strArray[i].equalsIgnoreCase( searchStr ) ;
else
found = strArray[i].equals( searchStr ) ;
}
if ( found )
return i ;
}
return -1 ;
|
public java.lang.String | leftPad(java.lang.String str, int len)Returns the given string filled (on the left) up to the specified
length with spaces.
Example: leftPad( "XX", 4 ) --> " XX"
return this.leftPadCh( str, len, CH_SPACE ) ;
|
public java.lang.String | leftPad(int value, int len)Returns the given integer as string filled (on the left) up to the
specified length with zeroes.
Example: leftPad( 12, 4 ) --> "0012"
return this.leftPadCh( value, len, '0" ) ;
|
public java.lang.String | leftPadCh(java.lang.String str, int len, char ch)Returns the given string filled (on the left) up to the specified
length with the given character.
Example: leftPadCh( "12", 6, '0' ) --> "000012"
return this.padCh( str, len, ch, true ) ;
|
public java.lang.String | leftPadCh(int value, int len, char fillChar)Returns the given integer as string filled (on the left) up to the
specified length with the given fill character.
Example: leftPad( 24, 5, '*' ) --> "***24"
return this.leftPadCh( Integer.toString(value), len, fillChar ) ;
|
protected java.lang.String | padCh(java.lang.String str, int len, char ch, boolean left)
StringBuffer buffer = null ;
int missing = len - str.length() ;
if ( missing <= 0 )
return str ;
buffer = new StringBuffer( len ) ;
if ( ! left )
buffer.append( str ) ;
for ( int i = 1 ; i <= missing ; i++ )
buffer.append( ch ) ;
if ( left )
buffer.append( str ) ;
return buffer.toString() ;
|
protected java.lang.String[] | parts(java.lang.String text, java.lang.String delimiters, boolean all)Returns an array of substrings of the given text.
The separators between the substrings are the given delimiters.
Each character in the delimiter string is treated as a separator.
ArrayList result = null ;
StringTokenizer tokenizer = null ;
if ( text == null )
return null ;
if ( ( delimiters == null ) || ( delimiters.length() == 0 ) )
{
String[] resultArray = { text } ;
return resultArray ;
}
if ( text.length() == 0 )
{
return new String[0] ;
}
else
{
result = new ArrayList() ;
tokenizer = new StringTokenizer( text, delimiters, all ) ;
if ( all )
this.collectParts( result, tokenizer, delimiters ) ;
else
this.collectParts( result, tokenizer ) ;
}
return (String[])result.toArray( new String[0] ) ;
|
public java.lang.String[] | parts(java.lang.String text, java.lang.String delimiters)Returns an array of substrings of the given text.
The separators between the substrings are the given delimiters.
Each character in the delimiter string is treated as a separator.
All consecutive delimiters are treated as one delimiter, that is there
will be no empty strings in the result.
return this.parts( text, delimiters, false ) ;
|
public java.lang.String | prefix(java.lang.String str, java.lang.String separator)Returns the substring of the given string that comes before the
first occurance of the specified separator.
If the string starts with a separator, the result will be an empty string.
If the string doesn't contain the separator the method returns null.
Examples:
prefix( "A/B/C", "/" ) ; // returns "A"
prefix( "A/B/C", "," ) ; // returns null
return this.prefix( str, separator, true ) ;
|
protected java.lang.String | prefix(java.lang.String str, java.lang.String separator, boolean returnNull)Returns the substring of the given string that comes before the
first occurance of the specified separator.
If the string starts with a separator, the result will be an empty string.
If the string doesn't contain the separator the method returns null or
the whole string, depending on the returnNull flag.
if ( str == null )
return null ;
if ( separator == null )
return ( returnNull ? null : str ) ;
int index = str.indexOf( separator ) ;
if ( index >= 0 )
return str.substring( 0, index ) ;
else
return ( returnNull ? null : str ) ;
|
public java.lang.String[] | remove(java.lang.String[] strings, java.lang.String[] removeStrings)Removes all string of the second array from the first array.
Returns a new array of string that contains all remaining strings of the
original strings array.
if ( ( strings == null ) || ( removeStrings == null )
|| ( strings.length == 0 ) || ( removeStrings.length == 0 ) )
{
return strings ;
}
return this.removeFromStringArray( strings, removeStrings ) ;
|
public java.lang.String[] | remove(java.lang.String[] strings, java.lang.String removeString)Removes the given string from the specified string array.
Returns a new array of string that contains all remaining strings of the
original strings array.
String[] removeStrings = { removeString } ;
return this.remove( strings, removeStrings ) ;
|
protected java.lang.String[] | removeFromStringArray(java.lang.String[] strings, java.lang.String[] removeStrings)Removes the given strings from the array.
If removeStrings is null it means that all null values are removed from
the first array.
List list ;
boolean remains ;
list = new ArrayList( strings.length ) ;
for (int i = 0; i < strings.length; i++)
{
if ( removeStrings == null )
{
remains = strings[i] != null ;
}
else
{
remains = ! this.contains( removeStrings, strings[i] ) ;
}
if ( remains )
{
list.add( strings[i] ) ;
}
}
return (String[])list.toArray( new String[list.size()] ) ;
|
public java.lang.String[] | removeNull(java.lang.String[] strings)Removes all null values from the given string array.
Returns a new string array that contains all none null values of the
input array.
if ( strings == null )
return strings ;
return this.removeFromStringArray( strings, null ) ;
|
public java.lang.String | repeat(char ch, int count)Returns a string with size of count and all characters initialized with ch.
StringBuffer buffer = null ;
buffer = new StringBuffer( count ) ;
for ( int i = 1 ; i <= count ; i++ )
{
buffer.append( ch ) ;
}
return ( buffer.toString() ) ;
|
public java.lang.String | replaceAll(java.lang.String sourceStr, java.lang.String oldSubStr, java.lang.String newSubStr)Returns the given string with all found oldSubStr replaced by newSubStr.
Example: StringUtil.current().replaceAll( "Seven of ten", "even", "ix" ) ;
results in: "Six of ten"
String part = null ;
String result = "" ;
int index = -1 ;
int subLen = 0 ;
subLen = oldSubStr.length() ;
part = sourceStr ;
while ( ( part.length() > 0 ) && ( subLen > 0 ) )
{
index = part.indexOf( oldSubStr ) ;
if ( index >= 0 )
{
result = result + part.substring( 0, index ) + newSubStr ;
part = part.substring( index + subLen ) ;
}
else
{
result = result + part ;
part = "" ;
}
} // while
return result ;
|
public java.lang.String | reverse(java.lang.String str)Returns a string that contains all characters of the given string in
reverse order.
if ( str == null )
return null ;
char[] newStr = new char[str.length()] ;
StringCharacterIterator iterator = new StringCharacterIterator(str) ;
int i = 0 ;
for(char ch = iterator.last(); ch != CharacterIterator.DONE; ch = iterator.previous())
{
newStr[i] = ch ;
i++ ;
}
return new String( newStr ) ;
|
public java.lang.String | rightPad(java.lang.String str, int len)Returns the given string filled (on the right) up to the specified
length with spaces.
Example: rightPad( "88", 6 ) --> "88 "
return this.rightPadCh( str, len, CH_SPACE ) ;
|
public java.lang.String | rightPad(int value, int len)Returns the given integer as string filled (on the right) up to the
specified length with spaces.
Example: rightPad( "17", 5 ) --> "17 "
return this.rightPadCh( value, len, CH_SPACE ) ;
|
public java.lang.String | rightPadCh(java.lang.String str, int len, char ch)Returns the given string filled (on the right) up to the specified
length with the given character.
Example: rightPadCh( "34", 5, 'X' ) --> "34XXX"
return this.padCh( str, len, ch, false ) ;
|
public java.lang.String | rightPadCh(int value, int len, char fillChar)Returns the given integer as string filled (on the right) up to the
specified length with the given character.
Example: rightPad( "32", 4, '#' ) --> "32##"
return this.rightPadCh( Integer.toString(value), len, fillChar ) ;
|
private static void | setSingleton(org.pf.text.StringUtil inst) singleton = inst ;
|
public java.lang.String[] | splitNameValue(java.lang.String str, java.lang.String separator)Returns a string array with two elements where the first is the attribute
name and the second is the attribute value.
Splits the given string at the first occurance of separator and returns
the piece before the separator in element 0 and the piece after the
separator in the returned array.
If the separator is not found, the first element contains the full
string and the second an empty string.
String[] result = { "", "" } ;
int index ;
if ( str != null )
{
index = str.indexOf( separator ) ;
if ( index > 0 )
{
result[0] = str.substring( 0, index ) ;
result[1] = str.substring( index + separator.length() ) ;
}
else
{
result[0] = str ;
}
}
return result ;
|
public java.lang.String | stackTrace(java.lang.Throwable throwable)Prints the stack trace of the specified throwable to a
string and returns it.
StringWriter sw = new StringWriter() ;
PrintWriter pw = new PrintWriter( sw ) ;
throwable.printStackTrace( pw ) ;
pw.close() ;
return sw.toString() ;
|
public java.lang.String | startingFrom(java.lang.String str, java.lang.String separator)Returns the substring of the given string that comes after the
first occurance of the specified separator.
If the string doesn't contain the separator the method returns the
whole string unchanged.
Examples:
startingFrom( "A/B/C", "/" ) ; // returns "B/C"
startingFrom( "A/B/C", "," ) ; // returns "A/B/C"
return this.suffix( str, separator, false ) ;
|
protected java.lang.String[] | substrings(java.lang.String text, java.lang.String separator, boolean all)Returns the given text split up into an array of strings, at
the occurrances of the separator string.
In contrary to method parts() the separator is a one or many
character sequence delimiter. That is, only the exact sequence
of the characters in separator identifies the end of a substring.
Parameter all defines whether empty strings between consecutive
separators are added to the result or not.
int index = 0 ;
int start = 0 ;
int sepLen = 0 ;
int strLen = 0 ;
String str = text ;
ArrayList strings = new ArrayList() ;
if ( text == null )
return new String[0] ;
if ( ( separator == null ) || ( separator.length() == 0 ) )
{
if ( text.length() == 0 )
return new String[0] ;
String[] resultArray = { text } ;
return resultArray ;
}
if ( ! all )
str = this.trimSeparator( text, separator ) ;
strLen = str.length() ;
if ( strLen > 0 )
{
sepLen = separator.length() ;
index = str.indexOf( separator, start ) ;
while ( index >= 0 )
{
if ( all )
{
if ( index > 0 )
{
strings.add( str.substring( start, index ) ) ;
}
}
else
{
if ( index > ( start + sepLen ) )
strings.add( str.substring( start, index ) ) ;
}
start = index + sepLen ;
index = str.indexOf( separator, start ) ;
}
if ( start < strLen )
strings.add( str.substring( start ) ) ;
}
return (String[])strings.toArray( new String[0] ) ;
|
public java.lang.String[] | substrings(java.lang.String text, java.lang.String separator)Returns the given text split up into an array of strings, at
the occurrances of the separator string.
In contrary to method parts() the separator is a one or many
character sequence delimiter. That is, only the exact sequence
of the characters in separator identifies the end of a substring.
Subsequent occurences of separator will be skipped. Therefore
no empty strings ("") will be in the result array.
return this.substrings( text, separator, false ) ;
|
public java.lang.String | suffix(java.lang.String str, java.lang.String separator)Returns the substring of the given string that comes after the
first occurance of the specified separator.
If the string ends with a separator, the result will be an empty string.
If the string doesn't contain the separator the method returns null.
Examples:
suffix( "A/B/C", "/" ) ; // returns "B/C"
suffix( "A/B/C", "," ) ; // returns null
return this.suffix( str, separator, true ) ;
|
protected java.lang.String | suffix(java.lang.String str, java.lang.String separator, boolean returnNull)Returns the substring of the given string that comes after the
first occurance of the specified separator.
If the string ends with a separator, the result will be an empty string.
If the string doesn't contain the separator the method returns null or
the whole string, depending on the returnNull flag.
if ( str == null )
return null ;
if ( separator == null )
return ( returnNull ? null : str ) ;
int index = str.indexOf( separator ) ;
if ( index >= 0 )
return str.substring( index + separator.length() ) ;
else
return ( returnNull ? null : str ) ;
|
public java.util.Map | toMap(java.lang.String str, java.lang.String elementSeparator, java.lang.String keyValueSeparator, java.util.Map map)Returns the given map with new entries from the specified String.
If the specified map is null a new empty java.util.Hashtable will be
created.
The string is split up into elements separated by the elementSeparator
parameter. If this parameter is null the default separator "," is used.
After that each part is split up to a key-value pair separated by the
keyValueSeparator parameter. If this parameter is null the default "=" is
used.
Then the key-value pairs are added to the map and the map is returned.
Be aware that all leading and trailing whitespaces of keys and values
will be removed!
Map result ;
String elemSep ;
String kvSep ;
String[] assignments ;
String[] nameValue ;
if ( str == null )
return map ;
result = ( map == null ? new Hashtable() : map ) ;
elemSep = ( elementSeparator == null ) ? "," : elementSeparator ;
kvSep = ( keyValueSeparator == null ) ? "=" : keyValueSeparator ;
assignments = this.parts( str, elemSep ) ;
for ( int i = 0 ; i < assignments.length ; i++ )
{
nameValue = this.splitNameValue( assignments[i], kvSep ) ;
nameValue[0] = nameValue[0].trim() ;
nameValue[1] = nameValue[1].trim() ;
if ( nameValue[0].length() > 0 )
result.put( nameValue[0], nameValue[1] ) ;
}
return result ;
|
public java.util.Map | toMap(java.lang.String str, java.lang.String elementSeparator, java.util.Map map)Returns the given map object with all key-value pairs of the
specified string added to it.
The separator between the keys and values is assumed to be "=".
Be aware that all leading and trailing whitespaces of keys and values
will be removed!
return this.toMap( str, elementSeparator, null, map ) ;
|
public java.util.Map | toMap(java.lang.String str, java.util.Map map)Adds all key-value pairs of the given string to the specified map.
The separator between the elements is assumed to be ","
and "=" between key and value.
Be aware that all leading and trailing whitespaces of keys and values
will be removed!
return this.toMap( str, null, null, map ) ;
|
public java.util.Properties | toProperties(java.lang.String str, java.util.Properties properties)Adds all key-value pairs of the given string to the specified properties.
The separator between the elements is assumed to be ","
and "=" between key and value.
Be aware that all leading and trailing whitespaces of keys and values
will be removed!
Properties props = ( properties == null ) ? new Properties() : properties ;
return (Properties)this.toMap( str, null, null, props ) ;
|
protected java.lang.String | trimSeparator(java.lang.String text, java.lang.String separator)Cuts off all leading and trailing occurences of separator in text.
int sepLen = separator.length() ;
while ( text.startsWith( separator ) )
text = text.substring( separator.length() ) ;
while ( text.endsWith( separator ) )
text = text.substring( 0, text.length() - sepLen ) ;
return text ;
|
public java.lang.String | upTo(java.lang.String str, java.lang.String separator)Returns the substring of the given string that comes before the
first occurance of the specified separator.
If the string starts with a separator, the result will be an empty string.
If the string doesn't contain the separator the method returns the
whole string unchanged.
Examples:
upTo( "A/B/C", "/" ) ; // returns "A"
upTo( "A/B/C", "," ) ; // returns "A/B/C"
upTo( "/A/B/C", "/" ) ; // returns ""
return this.prefix( str, separator, false ) ;
|
public java.lang.String[] | words(java.lang.String text)Returns an array of substrings of the given text.
The delimiters between the substrings are the whitespace characters
SPACE, NEWLINE, CR and TAB.
return this.parts( text, WORD_DELIM ) ;
|