Difference between revisions of "TextUtils"
Line 5: | Line 5: | ||
<syntaxhighlight lang="java5"> | <syntaxhighlight lang="java5"> | ||
/** | /** | ||
− | * | + | * Compile pattern as a regular expression then check if exists a match in text. |
− | |||
* | * | ||
* @param pattern | * @param pattern | ||
* @param text | * @param text | ||
− | * @return | + | * @return true if the pattern match the text |
*/ | */ | ||
public static boolean matches(String pattern, String text) | public static boolean matches(String pattern, String text) | ||
Line 30: | Line 29: | ||
/** | /** | ||
+ | * Replaces placeholders value in the input string. | ||
+ | * | ||
* @param input | * @param input | ||
+ | * the input text | ||
* @param phPrefix | * @param phPrefix | ||
+ | * the placeholder prefix | ||
* @param phSuffix | * @param phSuffix | ||
+ | * the placeholder suffix | ||
* @param phValues | * @param phValues | ||
+ | * the placeholder values | ||
* @return the string with placeholders replaced | * @return the string with placeholders replaced | ||
* | * | ||
*/ | */ | ||
− | public static String replacePlaceholder(String input, String phPrefix, String phSuffix,Hashtable<String, String> phValues) | + | public static String replacePlaceholder(String input, String phPrefix, String phSuffix, Hashtable<String, String> phValues) |
+ | |||
/** | /** | ||
* This method tokenizes a given string using another given string as | * This method tokenizes a given string using another given string as | ||
Line 43: | Line 49: | ||
* returned List is NEVER null (it may have zero elements, anyway). | * returned List is NEVER null (it may have zero elements, anyway). | ||
* | * | ||
− | * @param theString the | + | * @param theString |
− | * @param separatorString the | + | * the string to be tokenized. |
+ | * @param separatorString | ||
+ | * the string separator between tokens. | ||
* @return a List containing found tokens. | * @return a List containing found tokens. | ||
*/ | */ | ||
public static List<String> splitByStringSeparator(String theString, String separatorString) | public static List<String> splitByStringSeparator(String theString, String separatorString) | ||
+ | |||
/** | /** | ||
− | * Replaces | + | * Replaces JavaScript invalid chars within input String with the |
* corresponding entities. | * corresponding entities. | ||
* | * | ||
* @param input the input String. | * @param input the input String. | ||
− | * @return the input string, with | + | * @return the input string, with JS invalid chars replaced by the |
* corresponding entities. | * corresponding entities. | ||
*/ | */ |
Revision as of 10:56, 28 February 2012
Class FQN: it.greenvulcano.util.txt
Following the TextUtils public static methods
- Parsing
/**
* Compile pattern as a regular expression then check if exists a match in text.
*
* @param pattern
* @param text
* @return true if the pattern match the text
*/
public static boolean matches(String pattern, String text)
/**
* Replaces within input string all the occurrences of the
* substring toBeReplaced with occurrences of the substring replacement.
*
* @param input
* the input String.
* @param toBeReplaced
* the substring to be replaced within input string.
* @param replacement
* the string used to replace substring toBeReplaced within input string.
* @return the input string, with all occurrences of the substring
* toBeReplaced replaced by occurrences of the substring replacement.
*/
public static String replaceSubstring(String input, String toBeReplaced, String replacement);
/**
* Replaces placeholders value in the input string.
*
* @param input
* the input text
* @param phPrefix
* the placeholder prefix
* @param phSuffix
* the placeholder suffix
* @param phValues
* the placeholder values
* @return the string with placeholders replaced
*
*/
public static String replacePlaceholder(String input, String phPrefix, String phSuffix, Hashtable<String, String> phValues)
/**
* This method tokenizes a given string using another given string as
* separator and returns a List containing found tokens. The
* returned List is NEVER null (it may have zero elements, anyway).
*
* @param theString
* the string to be tokenized.
* @param separatorString
* the string separator between tokens.
* @return a List containing found tokens.
*/
public static List<String> splitByStringSeparator(String theString, String separatorString)
/**
* Replaces JavaScript invalid chars within input String with the
* corresponding entities.
*
* @param input the input String.
* @return the input string, with JS invalid chars replaced by the
* corresponding entities.
*/
public static String replaceJSInvalidChars(String input)
/**
* Generate random chars string of given <code>length</code>.
*
* @param length
* @return a random string of given length.
*/
public static String generateRandomString(int length)