info.aduna.text
Class StringUtil

java.lang.Object
  extended by info.aduna.text.StringUtil

public class StringUtil
extends java.lang.Object


Constructor Summary
StringUtil()
           
 
Method Summary
static void appendN(char c, int n, java.lang.StringBuilder sb)
          Appends the specified character n times to the supplied StringBuilder.
static java.lang.String concat(java.lang.String... strings)
          Concatenate a number of Strings.
static java.lang.String[] decodeArray(java.lang.String encodedArray)
          Decodes a String generated by encodeArray.
static java.lang.String deriveInitialText(java.lang.String text)
          Derives the initial text from the supplied text.
static java.lang.String encodeArray(java.lang.String[] array)
          Encodes an array of Strings into a single String than can be decoded to the original array using the corresponding decode method.
static java.lang.String getAllAfter(java.lang.String string, char separatorChar)
          Returns all text occurring after the specified separator character, or the entire string when the seperator char does not occur.
static java.lang.String getAllBefore(java.lang.String string, char separatorChar)
          Returns all text occurring before the specified separator character, or the entire string when the seperator char does not occur.
static java.lang.String gsub(java.lang.String olds, java.lang.String news, java.lang.String text)
          Substitute String "old" by String "new" in String "text" everywhere.
static boolean isGarbageText(java.lang.String text)
          Titles shorter than MIN_TITLE_LENGTH and long titles that don't contain a single space character are considered to be garbage.
static java.lang.String trimDoubleQuotes(java.lang.String text)
          Removes the double quote from the start and end of the supplied string if it starts and ends with this character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtil

public StringUtil()
Method Detail

gsub

public static java.lang.String gsub(java.lang.String olds,
                                    java.lang.String news,
                                    java.lang.String text)
Substitute String "old" by String "new" in String "text" everywhere. This is static util function that I could not place anywhere more appropriate. The name of this function is from the good-old awk time.

Parameters:
olds - The String to be substituted.
news - The String is the new content.
text - The String in which the substitution is done.
Returns:
The result String containing the substitutions; if no substitutions were made, the result is 'text'.

getAllAfter

public static java.lang.String getAllAfter(java.lang.String string,
                                           char separatorChar)
Returns all text occurring after the specified separator character, or the entire string when the seperator char does not occur.

Parameters:
string - The string of which the substring needs to be determined.
separatorChar - The character to look for.
Returns:
All text occurring after the separator character, or the entire string when the character does not occur.

getAllBefore

public static java.lang.String getAllBefore(java.lang.String string,
                                            char separatorChar)
Returns all text occurring before the specified separator character, or the entire string when the seperator char does not occur.

Parameters:
string - The string of which the substring needs to be determined.
separatorChar - The character to look for.
Returns:
All text occurring before the separator character, or the entire string when the character does not occur.

encodeArray

public static java.lang.String encodeArray(java.lang.String[] array)
Encodes an array of Strings into a single String than can be decoded to the original array using the corresponding decode method. Useful for e.g. storing an array of Strings as a single entry in a Preferences node.


decodeArray

public static java.lang.String[] decodeArray(java.lang.String encodedArray)
Decodes a String generated by encodeArray.


deriveInitialText

public static java.lang.String deriveInitialText(java.lang.String text)
Derives the initial text from the supplied text. The returned text excludes whitespace and other special characters and is useful for display purposes (e.g. previews).


isGarbageText

public static boolean isGarbageText(java.lang.String text)
Titles shorter than MIN_TITLE_LENGTH and long titles that don't contain a single space character are considered to be garbage.


appendN

public static void appendN(char c,
                           int n,
                           java.lang.StringBuilder sb)
Appends the specified character n times to the supplied StringBuilder.

Parameters:
c - The character to append.
n - The number of times the character should be appended.
sb - The StringBuilder to append the character(s) to.

trimDoubleQuotes

public static java.lang.String trimDoubleQuotes(java.lang.String text)
Removes the double quote from the start and end of the supplied string if it starts and ends with this character. This method does not create a new string if text doesn't start and end with double quotes, the text object itself is returned in that case.

Parameters:
text - The string to remove the double quotes from.
Returns:
The trimmed string, or a reference to text if it did not start and end with double quotes.

concat

public static java.lang.String concat(java.lang.String... strings)
Concatenate a number of Strings. This implementation uses a StringBuilder.

Parameters:
strings - the String to concatenate
Returns:
a String that is the results of concatenating the input strings.


Copyright © 2010 Aduna. All Rights Reserved.