org.brains2b.util
Class StringHelper

java.lang.Object
  extended byorg.brains2b.util.StringHelper

public final class StringHelper
extends java.lang.Object

Some static functions that help with Stringmanipulation.

Version:
0.21.2 [30-06-2007]
Author:
dennis@brains2b.nl

Constructor Summary
protected StringHelper()
          Creates new StringHelper, protected as all functions are static
 
Method Summary
static java.lang.String baseOnly(java.lang.String str)
          Returns only the base capitilazid characters [A-Z][0-9] All other characters are removed from the String
static java.lang.String breakLine(java.lang.String str, int maxLen)
          Breaks a String after a maximun number of characters on the first space or punctuation before that maximum.
static int getNonBaseCharacter(java.lang.String value)
           
static int getNonBaseCharacter(java.lang.String value, int start)
           
static java.lang.String initCaps(java.lang.String str, char c)
          Capitalize the first Letter in a String and all letters following the char.
static boolean isEmpty(java.lang.String s)
          check if a String is empty, meaning a String of length zero or null
static boolean isQuoteCharacter(char a)
          check is a character is a quote: "e; or &
static java.lang.String leftPad(java.lang.String str, java.lang.String filler, int len)
          Pads a String to the left with th filler String until len is reached If the String is longer then the length the string will be truncated on the left to not return more then lenght characters
static int matchBracket(char left, java.lang.String line)
          Finds the matching bracket for the first character given by left in String line.
static int matchBracket(int pos, java.lang.String line)
          Finds the matching bracket for the bracket character at pos in line.
static java.lang.String rightPad(java.lang.String str, java.lang.String filler, int len)
          Pads a String to the right with the filler String until len is reached If the String is longer then the length the string will be truncated on the right to not return more then lenght characters
static java.lang.String stripper(java.lang.String str, char c)
          Strips a character from a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringHelper

protected StringHelper()
Creates new StringHelper, protected as all functions are static

Method Detail

initCaps

public static java.lang.String initCaps(java.lang.String str,
                                        char c)
Capitalize the first Letter in a String and all letters following the char.

Parameters:
str - String, the String that needs to be InitCapped.
c - char, The character after which letters should be capitalized
Returns:
String, the InitCapped String, returns null if str is null

stripper

public static java.lang.String stripper(java.lang.String str,
                                        char c)
Strips a character from a String. The String will become shortend for every occurance of the char.

Parameters:
str - String, from which the character should be removed
c - char, the Character that needs to be removd
Returns:
String, the String minus the characters that where removed, returns null when str is null

getNonBaseCharacter

public static int getNonBaseCharacter(java.lang.String value)

getNonBaseCharacter

public static int getNonBaseCharacter(java.lang.String value,
                                      int start)

baseOnly

public static java.lang.String baseOnly(java.lang.String str)
Returns only the base capitilazid characters [A-Z][0-9] All other characters are removed from the String

Parameters:
str - String, the value to be 'based'
Returns:
String, the 'based' value

breakLine

public static final java.lang.String breakLine(java.lang.String str,
                                               int maxLen)
Breaks a String after a maximun number of characters on the first space or punctuation before that maximum. Uses the default lineseparator from the running System

Returns:
String, the String including linebreaks, returns null when str is null

leftPad

public static java.lang.String leftPad(java.lang.String str,
                                       java.lang.String filler,
                                       int len)
Pads a String to the left with th filler String until len is reached If the String is longer then the length the string will be truncated on the left to not return more then lenght characters

Parameters:
str - String, if str is null, it will be threated as a zero length string
filler - String, the String that fills the original String on the left until length.
len - int, the length of the output string
Returns:
String the leftpadded String
Throws:
java.lang.NullPointerException - thrown if filler is null

rightPad

public static java.lang.String rightPad(java.lang.String str,
                                        java.lang.String filler,
                                        int len)
Pads a String to the right with the filler String until len is reached If the String is longer then the length the string will be truncated on the right to not return more then lenght characters

Parameters:
str - String, if str is null, it will be threated as a zero length string
filler - String, the String that fills the original String on the left until length
len - int, the length of the output string
Returns:
String the leftpadded String
Throws:
java.lang.NullPointerException - thrown if filler is null

matchBracket

public static int matchBracket(char left,
                               java.lang.String line)
Finds the matching bracket for the first character given by left in String line.

Parameters:
left - char, the bracket character ",',{,[,( one is looking for
line - String, the line to find the matching bracket in
Returns:
int, the position where the bracket ends in line x, returns -1 if no at pos no bracket could be found or if the matching bracket could not be found
See Also:
matchBracket(int, String)

matchBracket

public static int matchBracket(int pos,
                               java.lang.String line)
Finds the matching bracket for the bracket character at pos in line.

Parameters:
pos - int, The position of the matching bracket, valid brackets are ",',{,[,(
line - String, the line to find the matching bracket in
Returns:
int, the position where the bracket ends in line x, returns -1 if no at pos no bracket could be found or if the matching bracket could not be found

isQuoteCharacter

public static boolean isQuoteCharacter(char a)
check is a character is a quote: "e; or &

Parameters:
a - char, the char to test
Returns:
boolean true if quote, false otherwise

isEmpty

public static boolean isEmpty(java.lang.String s)
check if a String is empty, meaning a String of length zero or null

Parameters:
s - String, to test for empty
Returns:
true if String is empty, false otherwise