com.funambol.util
Class StringUtil

java.lang.Object
  extended by com.funambol.util.StringUtil

public class StringUtil
extends java.lang.Object

Utility class useful when dealing with string objects. This class is a collection of static functions, and the usage is: StringUtil.method() it is not allowed to create instances of this class


Method Summary
static boolean endsWithIgnoreCase(java.lang.String str, java.lang.String suffix)
          This method check if a string ends with the specified suffix ignoring the case.
static boolean equalsIgnoreCase(java.lang.String string1, java.lang.String string2)
          This method is missing in CLDC 1.0 String implementation
static java.lang.String extractAddressFromUrl(java.lang.String url)
          This method extracts from address the resources
static java.lang.String extractAddressFromUrl(java.lang.String url, java.lang.String protocol)
          This method extracts from address the protocol port and resources
static int findEmptyLine(java.lang.String s)
          Find two consecutive newlines in a string.
static java.lang.String fold(java.lang.String recipients)
          Builds a list of the recipients email addresses each on a different line, starting just from the second line with an HT ("\t") separator at the head of the line.
static boolean getBooleanValue(java.lang.String string)
          Util method for retrieve a boolean primitive type from a String.
static java.lang.String getProtocolFromUrl(java.lang.String url)
          This method retrieves the protocol used in the given url.
static java.lang.String[] getStringArray(java.util.Vector stringVec)
          Returns the string array
static java.util.Vector getVectorFromArray(java.lang.Object[] array)
          create a vector filled with the elements of the given array
static boolean isNullOrEmpty(java.lang.String str)
          Returns true if the given string is null or empty.
static boolean isValidProtocol(java.lang.String url)
          This method check if the protocol used in the given url is valid.
static java.lang.String join(java.lang.String[] list, java.lang.String sep)
          Join the given strings into a single string using sep as separator for individual values.
static java.lang.String removeBackslashes(java.lang.String content)
          Removes unwanted backslashes characters
static java.lang.String removeBlanks(java.lang.String content)
          Removes unwanted blank characters
static java.lang.String removeChar(java.lang.String content, char ch)
          Removes unwanted characters
static java.lang.String removePortFromUrl(java.lang.String url, java.lang.String protocol)
           
static java.lang.String replaceAll(java.lang.String s, char c1, char c2)
          Replace all characters c1 with c2
static java.lang.String replaceAll(java.lang.String s, java.lang.String src, java.lang.String tgt)
          Replace any occurrence of one string with another one
static java.lang.String[] split(java.lang.String s, java.lang.String sep)
          Split the string into an array of strings using one of the separator in 'sep'.
static java.lang.String[] split(java.lang.String s, java.lang.String[] sepArray)
          Split the string into an array of strings using one of the separator in 'sep'.
static java.lang.String trim(java.lang.String s, char c)
          Removes characters 'c' from the beginning and the end of the string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String sep)
Split the string into an array of strings using one of the separator in 'sep'.

Parameters:
s - the string to tokenize
sep - a list of separator to use
Returns:
the array of tokens (an array of size 1 with the original string if no separator found)

split

public static java.lang.String[] split(java.lang.String s,
                                       java.lang.String[] sepArray)
Split the string into an array of strings using one of the separator in 'sep'.

Parameters:
s - the string to tokenize
sep - a list of separators (strings, not chars) to use
Returns:
the array of tokens (an array of size 1 with the original string if no separator found)

join

public static java.lang.String join(java.lang.String[] list,
                                    java.lang.String sep)
Join the given strings into a single string using sep as separator for individual values.

Parameters:
list - the string array to join
sep - the separator to use
Returns:
the joined string

getStringArray

public static java.lang.String[] getStringArray(java.util.Vector stringVec)
Returns the string array

Parameters:
stringVec - the Vecrot of tring to convert
Returns:
String []

getVectorFromArray

public static java.util.Vector getVectorFromArray(java.lang.Object[] array)
create a vector filled with the elements of the given array

Parameters:
array -
Returns:
a vector with the elements from the given array

findEmptyLine

public static int findEmptyLine(java.lang.String s)
Find two consecutive newlines in a string.

Parameters:
s - - The string to search
Returns:
int: the position of the empty line

removeBlanks

public static java.lang.String removeBlanks(java.lang.String content)
Removes unwanted blank characters

Parameters:
content -
Returns:
String

removeBackslashes

public static java.lang.String removeBackslashes(java.lang.String content)
Removes unwanted backslashes characters

Parameters:
content - The string containing the backslashes to be removed
Returns:
the content without backslashes

removeChar

public static java.lang.String removeChar(java.lang.String content,
                                          char ch)
Removes unwanted characters

Parameters:
content - The string containing the backslashes to be removed
ch - the character to be removed
Returns:
the content without backslashes

fold

public static java.lang.String fold(java.lang.String recipients)
Builds a list of the recipients email addresses each on a different line, starting just from the second line with an HT ("\t") separator at the head of the line. This is an implementation of the 'folding' concept from the RFC 2822 (par. 2.2.3)

Parameters:
recipients - A string containing all recipients comma-separated
Returns:
A string containing the email list of the recipients spread over more lines, ended by CRLF and beginning from the second with the WSP defined in the RFC 2822

equalsIgnoreCase

public static boolean equalsIgnoreCase(java.lang.String string1,
                                       java.lang.String string2)
This method is missing in CLDC 1.0 String implementation


getBooleanValue

public static boolean getBooleanValue(java.lang.String string)
Util method for retrieve a boolean primitive type from a String. Implemented because Boolean class doesn't provide parseBoolean() method. Returns true if the input string is equal to "true" (case insensitive) false otherwise


trim

public static java.lang.String trim(java.lang.String s,
                                    char c)
Removes characters 'c' from the beginning and the end of the string


isNullOrEmpty

public static boolean isNullOrEmpty(java.lang.String str)
Returns true if the given string is null or empty.


extractAddressFromUrl

public static java.lang.String extractAddressFromUrl(java.lang.String url,
                                                     java.lang.String protocol)
This method extracts from address the protocol port and resources

Parameters:
url - eg. http://127.0.0.1:8080/sync
protocol - http
Returns:
127.0.0.1

extractAddressFromUrl

public static java.lang.String extractAddressFromUrl(java.lang.String url)
This method extracts from address the resources

Parameters:
url - eg. http://127.0.0.1:8080/sync
Returns:
http://127.0.0.1:8080

removePortFromUrl

public static java.lang.String removePortFromUrl(java.lang.String url,
                                                 java.lang.String protocol)

getProtocolFromUrl

public static java.lang.String getProtocolFromUrl(java.lang.String url)
This method retrieves the protocol used in the given url.

Parameters:
url - eg. http://127.0.0.1:8080/sync
Returns:
the url protocol (e.g. http). Return null if the protocol is not found.

isValidProtocol

public static boolean isValidProtocol(java.lang.String url)
This method check if the protocol used in the given url is valid.

Parameters:
url - eg. http://127.0.0.1:8080/sync
Returns:
the url protocol (e.g. http). Return null if the protocol is not found.

endsWithIgnoreCase

public static boolean endsWithIgnoreCase(java.lang.String str,
                                         java.lang.String suffix)
This method check if a string ends with the specified suffix ignoring the case.

Parameters:
str - - string to check suffix - the suffix to find
Returns:
true if the character sequence represented by the argument is a suffix of the character sequence represented by this object; false otherwise.

replaceAll

public static java.lang.String replaceAll(java.lang.String s,
                                          char c1,
                                          char c2)
Replace all characters c1 with c2

Parameters:
s - the String to be manipulated
c1 - the char to be replaced
c2 - the char to put in place of c1
Returns:
the new string

replaceAll

public static java.lang.String replaceAll(java.lang.String s,
                                          java.lang.String src,
                                          java.lang.String tgt)
Replace any occurrence of one string with another one

Parameters:
s - the String to be manipulated
src - the string to be replaced
tgt - the replacement string
Returns:
the replaced string (newly allocated). If src is not found the method returns a string identical to the original one


Copyright © 2001-2009 Funambol.