org.melati.poem.util
Class StringUtils

Package class diagram package StringUtils
java.lang.Object
  extended by org.melati.poem.util.StringUtils

public final class StringUtils
extends Object

An assortment of useful operations on Strings.


Constructor Summary
StringUtils()
           
 
Method Summary
static void appendEscaped(StringBuffer b, String s, char character)
           
static void appendEscaped(StringBuffer b, String s, char character, char escapeChar)
          Append a String to a StringBuffer, and escaping any occurances of the char in the String.
static void appendQuoted(StringBuffer b, String s, char q)
          Append a String to a StringBuffer, first quoting it with a quote character and escaping any occurrences of the quote char in the String.
static String capitalised(String name)
          Capitalise the first character of the input string.
static String concatenated(String sep, String[] xs)
          Concatenate an array of Strings with a separator.
static byte hexDecoding(char c)
          Decode a hex char to a byte.
static byte[] hexDecoding(String digits)
          Decode a hex String into a byte Array.
static String hexEncoding(byte[] bytes)
          Hex encode an Array of bytes.
static boolean isQuoted(String in)
          Determine whether a String is quoted, with either quoting character.
static String nulled(String s)
          Turn an empty String into a null.
static String quoted(String i, char q)
          Surround a string in quotes.
static String randomString(int length)
          Generate a random String.
static String[] split(String s, char c)
          As Perl, create an Array from a String by using a character as the Array delimiter.
static String tr(String s, char from, char to)
          Deprecated. now use string.replace(old,new)
static String tr(String s, String from, String to)
          As Perl tr; swap any occurrences of any characters in the from string in the input string with the corresponding character from the to string.
static String uncapitalised(String name)
          Uncaptialise the first character of the input string.
static String unNulled(String in)
          Turn a null into an empty String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

split

public static String[] split(String s,
                             char c)
As Perl, create an Array from a String by using a character as the Array delimiter.

Parameters:
s - the String to split
c - the Array delimiter
Returns:
an Array

appendEscaped

public static void appendEscaped(StringBuffer b,
                                 String s,
                                 char character)
Parameters:
b - the buffer to append to
s - the String to append
character - the character to escape

appendEscaped

public static void appendEscaped(StringBuffer b,
                                 String s,
                                 char character,
                                 char escapeChar)
Append a String to a StringBuffer, and escaping any occurances of the char in the String.

Parameters:
b - the buffer to append to
s - the String to append
character - the character to escape
escapeChar - the character to escape with

appendQuoted

public static void appendQuoted(StringBuffer b,
                                String s,
                                char q)
Append a String to a StringBuffer, first quoting it with a quote character and escaping any occurrences of the quote char in the String.

Parameters:
b - the buffer to append to
s - the String to append
q - the quote character

quoted

public static String quoted(String i,
                            char q)
Surround a string in quotes.

Parameters:
i - the string to quote
q - The quote character to use
Returns:
the quoted string

capitalised

public static String capitalised(String name)
Capitalise the first character of the input string.

Parameters:
name - String to capitalise
Returns:
the capitalised string

uncapitalised

public static String uncapitalised(String name)
Uncaptialise the first character of the input string.

Parameters:
name - String to uncapitalise
Returns:
the uncapitalised string

tr

public static String tr(String s,
                        String from,
                        String to)
As Perl tr; swap any occurrences of any characters in the from string in the input string with the corresponding character from the to string. tr("melati", "ait", "osn").equals("melons")

Parameters:
s - String to act upon
from - String containing characters to swap from
to - String containing characters to swap to
Returns:
the transformed input String

tr

public static String tr(String s,
                        char from,
                        char to)
Deprecated. now use string.replace(old,new)

As Perl tr; swap any occurances of the from character in the input string with the corresponding the to character. tr("melati", 'i', 'o').equals("melato")

Parameters:
s - String to act upon
from - character to swap from
to - character to swap to
Returns:
the transformed input String

concatenated

public static String concatenated(String sep,
                                  String[] xs)
Concatenate an array of Strings with a separator.

Parameters:
sep - The separator String to use, may be null.
xs - An array of Strings to concatenate.
Returns:
the concatenated String.

randomString

public static String randomString(int length)
Generate a random String.

Parameters:
length - the required length of the String returned
Returns:
a random String of upper and lowercase letters and digits

nulled

public static String nulled(String s)
Turn an empty String into a null.

Parameters:
s - input String, possibly of zero length or null
Returns:
null if input is empty, input otherwise

unNulled

public static String unNulled(String in)
Turn a null into an empty String.

Parameters:
in - input String, possibly null
Returns:
empty String if input is null, input otherwise

hexEncoding

public static String hexEncoding(byte[] bytes)
Hex encode an Array of bytes.

Parameters:
bytes - the byte Array
Returns:
the hex representation

hexDecoding

public static byte hexDecoding(char c)
Decode a hex char to a byte.

Parameters:
c - the char
Returns:
a byte

hexDecoding

public static byte[] hexDecoding(String digits)
Decode a hex String into a byte Array.

Parameters:
digits - the hex String
Returns:
a byte Array

isQuoted

public static boolean isQuoted(String in)
Determine whether a String is quoted, with either quoting character.

Parameters:
in - String to examine
Returns:
whether String is quoted


Copyright © 2000-2010 PanEris. All Rights Reserved.