org.epseelon.mobimap.util
Class TextUtil

java.lang.Object
  extended by org.epseelon.mobimap.util.TextUtil

public final class TextUtil
extends java.lang.Object

Provides some usefull String methods.

Copyright Enough Software 2004 - 2008

 history
        20-Apr-2004 - rob creation
 

Author:
Robert Virkus, robert@enough.de

Constructor Summary
TextUtil()
           
 
Method Summary
static java.lang.String encodeUrl(java.lang.String url)
          Encodes a URL string.
static boolean equalsIgnoreCase(java.lang.String str1, java.lang.String str2)
          Compares two strings in a case-insensitive way.
static int lastIndexOf(java.lang.String text, java.lang.String match)
          Retrieves the last index of the given match in the specified text.
static java.lang.String replace(java.lang.String input, java.lang.String search, java.lang.String replacement)
          Replaces the all matches within a String.
static java.lang.String replaceFirst(java.lang.String input, java.lang.String search, java.lang.String replacement)
          Replaces the first match in a String.
static java.lang.String replaceLast(java.lang.String input, java.lang.String search, java.lang.String replacement)
          Replaces the last match in a String.
static java.lang.String reverseForRtlLanguage(java.lang.String input)
          Reverses the given text while keeping English texts and numbers in the normal position.
static java.lang.String[] split(java.lang.String value, char delimiter)
          Splits the given String around the matches defined by the given delimiter into an array.
static java.lang.String[] split(java.lang.String value, char delimiter, int numberOfChunks)
          Splits the given String around the matches defined by the given delimiter into an array.
static java.lang.String[] splitAndTrim(java.lang.String value, char delimiter)
          Splits the given String around the matches defined by the given delimiter into an array.
static java.lang.String[] wrap(java.lang.String value, javax.microedition.lcdui.Font font, int firstLineWidth, int lineWidth)
          Wraps the given string so it fits on the specified lines.
static void wrap(java.lang.String value, javax.microedition.lcdui.Font font, int completeWidth, int firstLineWidth, int lineWidth, java.util.Vector list)
          Wraps the given string so that the substrings fit into the the given line-widths.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextUtil

public TextUtil()
Method Detail

split

public static java.lang.String[] split(java.lang.String value,
                                       char delimiter)
Splits the given String around the matches defined by the given delimiter into an array. Example: TextUtil.split("one;two;three", ';') results into the array {"one", "two", "three"}.

Parameters:
value - the String which should be split into an array
delimiter - the delimiter which marks the boundaries of the array
Returns:
an array, when the delimiter was not found, the array will only have a single element.

splitAndTrim

public static java.lang.String[] splitAndTrim(java.lang.String value,
                                              char delimiter)
Splits the given String around the matches defined by the given delimiter into an array. Example: TextUtil.splitAndTrim(" one; two; three", ';') results into the array {"one", "two", "three"}.

Parameters:
value - the String which should be split into an array
delimiter - the delimiter which marks the boundaries of the array
Returns:
an array, when the delimiter was not found, the array will only have a single element.

split

public static java.lang.String[] split(java.lang.String value,
                                       char delimiter,
                                       int numberOfChunks)
Splits the given String around the matches defined by the given delimiter into an array. Example: TextUtil.split("one;two;three", ';', 3) results into the array {"one", "two", "three"}.
TextUtil.split("one;two;three", ';', 4) results into the array {"one", "two", "three", null}.
TextUtil.split("one;two;three", ';', 2) results into the array {"one", "two"}.
This method is less resource intensive compared to the other split method, since no temporary list needs to be created

Parameters:
value - the String which should be split into an array
delimiter - the delimiter which marks the boundaries of the array
numberOfChunks - the number of expected matches
Returns:
an array with the length of numberOfChunks, when not enough elements are found, the array will contain null elements

wrap

public static java.lang.String[] wrap(java.lang.String value,
                                      javax.microedition.lcdui.Font font,
                                      int firstLineWidth,
                                      int lineWidth)
Wraps the given string so it fits on the specified lines. First of al it is splitted at the line-breaks ('\n'), subsequently the substrings are splitted when they do not fit on a single line.

Parameters:
value - the string which should be splitted
font - the font which is used to display the font
firstLineWidth - the allowed width for the first line
lineWidth - the allowed width for all other lines, lineWidth >= firstLineWidth
Returns:
the array containing the substrings

wrap

public static void wrap(java.lang.String value,
                        javax.microedition.lcdui.Font font,
                        int completeWidth,
                        int firstLineWidth,
                        int lineWidth,
                        java.util.Vector list)
Wraps the given string so that the substrings fit into the the given line-widths. It is expected that the specified lineWidth >= firstLineWidth. The resulting substrings will be added to the given ArrayList. When the complete string fits into the first line, it will be added to the list. When the string needs to be splited to fit on the lines, it is tried to split the string at a gab between words. When this is not possible, the given string will be splitted in the middle of the corresponding word.

Parameters:
value - the string which should be splitted
font - the font which is used to display the font
completeWidth - the complete width of the given string for the specified font.
firstLineWidth - the allowed width for the first line
lineWidth - the allowed width for all other lines, lineWidth >= firstLineWidth
list - the list to which the substrings will be added.

encodeUrl

public static java.lang.String encodeUrl(java.lang.String url)
Encodes a URL string. This method assumes UTF-8 usage.

Parameters:
url - URL to encode
Returns:
the encoded URL

replace

public static java.lang.String replace(java.lang.String input,
                                       java.lang.String search,
                                       java.lang.String replacement)
Replaces the all matches within a String.

Parameters:
input - the input string
search - the string that should be replaced
replacement - the replacement
Returns:
the input string where the search string has been replaced
Throws:
java.lang.NullPointerException - when one of the specified strings is null

replaceFirst

public static java.lang.String replaceFirst(java.lang.String input,
                                            java.lang.String search,
                                            java.lang.String replacement)
Replaces the first match in a String.

Parameters:
input - the input string
search - the string that should be replaced
replacement - the replacement
Returns:
the input string where the first match of the search string has been replaced
Throws:
java.lang.NullPointerException - when one of the specified strings is null

replaceLast

public static java.lang.String replaceLast(java.lang.String input,
                                           java.lang.String search,
                                           java.lang.String replacement)
Replaces the last match in a String.

Parameters:
input - the input string
search - the string that should be replaced
replacement - the replacement
Returns:
the input string where the last match of the search string has been replaced
Throws:
java.lang.NullPointerException - when one of the specified strings is null

lastIndexOf

public static int lastIndexOf(java.lang.String text,
                              java.lang.String match)
Retrieves the last index of the given match in the specified text.

Parameters:
text - the text in which the match is given
match - the match within the text
Returns:
the last index of the match or -1 when the match is not found in the given text
Throws:
java.lang.NullPointerException - when text or match is null

equalsIgnoreCase

public static boolean equalsIgnoreCase(java.lang.String str1,
                                       java.lang.String str2)
Compares two strings in a case-insensitive way. Both strings are lower cased and then compared. If both are equal this method returns true, false otherwise.

Parameters:
str1 - the string to compare
str2 - the string to compare to
Returns:
true if both strings are equals except case, false
Throws:
java.lang.NullPointerException - if str1 is null
See Also:
String.equals(Object), String.equalsIgnoreCase(String)

reverseForRtlLanguage

public static java.lang.String reverseForRtlLanguage(java.lang.String input)
Reverses the given text while keeping English texts and numbers in the normal position.

Parameters:
input - the text
Returns:
the reveresed text


Copyright © 2008 Epseelon. All Rights Reserved.