cdx.scorebot.util
Class StringOps

java.lang.Object
  extended by cdx.scorebot.util.StringOps

public abstract class StringOps
extends java.lang.Object

Defines some methods for matching and replacement on special conditions for Strings.

Author:
David Underhill

Constructor Summary
StringOps()
           
 
Method Summary
static java.lang.String checkName(java.lang.String name)
          Checks to see if name contains anything other than alphanumeric characters, underscores, or spaces.
static java.lang.String endWithSlash(java.lang.String s)
          make sure the last character in the specified String is a slash unless s is of length 0 in which case the empty string passed in is returned
static java.lang.String getFileAsString(java.lang.String fn)
          Gets the contents of a file as a String
static java.lang.String getFileTitle(java.lang.String s)
          Gets the text following the last slash (\ or /) in a string (the "file title")
static java.lang.String getPath(java.lang.String fn)
          determine the path in the string (all text before and included the last slash mark, or the empty string if there are no slashes)
static int indexOf(java.lang.String s, java.lang.String searchTerm)
          finds the searchTerm in String s from startIndex which doesn't have a letter, digit, or underscore on either side of it
static int indexOf(java.lang.String s, java.lang.String searchTerm, int startIndex)
          finds the searchTerm in String s from startIndex which doesn't have a letter, digit, or underscore on either side of it
static java.lang.String replace(java.lang.String s, java.lang.String searchTerm, java.lang.String replaceTerm)
          replaces all occurs of searchTerm in s which don't have a letter, digit, or underscore on either side
static java.lang.String replaceBetweenStrings(java.lang.String str, java.lang.String s1, java.lang.String s2, java.lang.String repl)
          Replaces the text between two strings (and removes the specified strings themselves too)
static java.lang.String selectBetweenStrings(java.lang.String str, java.lang.String s1, java.lang.String s2)
          Selects the text between two strings
static java.lang.String splitIntoLines(java.lang.String s)
          inserts a newline after every 80 characters
static java.lang.String splitIntoLines(java.lang.String s, int maxLineLen)
          inserts a newline after every maxLineLen characters
static java.lang.String splitIntoLines(java.lang.String s, int firstLineMaxLen, int maxLineLen, java.lang.String newlineIdentifier, boolean trim)
          inserts a newline string specified by the user after every maxLineLen characters
static java.lang.String splitIntoLines(java.lang.String s, int maxLineLen, java.lang.String newlineIdentifier, boolean trim)
          inserts a newline string specified by the user after every maxLineLen characters
static java.lang.String stripExtensions(java.lang.String s, int numExtToStrip)
          Removes a specified number of extensions from s
static void writeStringToFile(java.lang.String fn, java.lang.String str)
          Writes a string to a file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringOps

public StringOps()
Method Detail

checkName

public static java.lang.String checkName(java.lang.String name)
                                  throws IllegalArgValException
Checks to see if name contains anything other than alphanumeric characters, underscores, or spaces.

Returns:
name if it is valid.
Throws:
IllegalArgValException - occurs if the name is invalid.

endWithSlash

public static java.lang.String endWithSlash(java.lang.String s)
make sure the last character in the specified String is a slash unless s is of length 0 in which case the empty string passed in is returned


getPath

public static java.lang.String getPath(java.lang.String fn)
determine the path in the string (all text before and included the last slash mark, or the empty string if there are no slashes)

Parameters:
fn - the filename to find the path in
Returns:
the path to the file specified in fn included the trailing slash as appropriate

getFileAsString

public static java.lang.String getFileAsString(java.lang.String fn)
                                        throws java.io.IOException
Gets the contents of a file as a String

Throws:
java.io.Exception - occurs if the file is invalid or unable to be properly read
java.io.IOException

getFileTitle

public static java.lang.String getFileTitle(java.lang.String s)
Gets the text following the last slash (\ or /) in a string (the "file title")

Parameters:
s - the string to work with
Returns:
all text is s following the last slash, or s if there were no slashes, or s if s is length 1.

stripExtensions

public static java.lang.String stripExtensions(java.lang.String s,
                                               int numExtToStrip)
Removes a specified number of extensions from s

Parameters:
s - the string to remove extensions from (.ext)
numExtToStrip - the number of extensions to remove
Returns:
s without the specified number of extensions (if s has fewer extensions that numExtToStrip then all extensions are stripped from s). The return may be of zero length.

replace

public static java.lang.String replace(java.lang.String s,
                                       java.lang.String searchTerm,
                                       java.lang.String replaceTerm)
replaces all occurs of searchTerm in s which don't have a letter, digit, or underscore on either side

Parameters:
s - the string being searched
searchTerm - what is being searched for
replaceTerm - what searchTerm is being replaced with

replaceBetweenStrings

public static java.lang.String replaceBetweenStrings(java.lang.String str,
                                                     java.lang.String s1,
                                                     java.lang.String s2,
                                                     java.lang.String repl)
Replaces the text between two strings (and removes the specified strings themselves too)

Parameters:
str - the string to search
s1 - the first string to find
s2 - the second string to find
repl - the string to use to replace the range from the beginning s1 to the end s2 inclusive
Returns:
the resulting string, or the string str which was passed in if s1 or s2 are not found

selectBetweenStrings

public static java.lang.String selectBetweenStrings(java.lang.String str,
                                                    java.lang.String s1,
                                                    java.lang.String s2)
Selects the text between two strings

Parameters:
str - the string to search
s1 - the first string to find
s2 - the second string to find
Returns:
the text between s1 and s2 (trimmed) or an empty string if either string isn't found

writeStringToFile

public static void writeStringToFile(java.lang.String fn,
                                     java.lang.String str)
                              throws java.io.IOException
Writes a string to a file

Parameters:
fn - the file to write the string to
str - the string to write
Throws:
java.io.IOException

indexOf

public static int indexOf(java.lang.String s,
                          java.lang.String searchTerm)
finds the searchTerm in String s from startIndex which doesn't have a letter, digit, or underscore on either side of it

Parameters:
s - the string being searched
searchTerm - what is being searched for

indexOf

public static int indexOf(java.lang.String s,
                          java.lang.String searchTerm,
                          int startIndex)
finds the searchTerm in String s from startIndex which doesn't have a letter, digit, or underscore on either side of it

Parameters:
s - the string being searched
searchTerm - what is being searched for
startIndex - where to start looking

splitIntoLines

public static java.lang.String splitIntoLines(java.lang.String s)
inserts a newline after every 80 characters

Parameters:
s - the string to split
Returns:
the split up string

splitIntoLines

public static java.lang.String splitIntoLines(java.lang.String s,
                                              int maxLineLen)
inserts a newline after every maxLineLen characters

Parameters:
s - the string to split
maxLineLen - the max length (in characters) a line may be
Returns:
the split up string

splitIntoLines

public static java.lang.String splitIntoLines(java.lang.String s,
                                              int maxLineLen,
                                              java.lang.String newlineIdentifier,
                                              boolean trim)
inserts a newline string specified by the user after every maxLineLen characters

Parameters:
s - the string to split
maxLineLen - the max length (in characters) a line may be
newlineIdentifier - the string to use to split lines up
trim - whether or not trim whitespace of each line's ends
Returns:
the split up string

splitIntoLines

public static java.lang.String splitIntoLines(java.lang.String s,
                                              int firstLineMaxLen,
                                              int maxLineLen,
                                              java.lang.String newlineIdentifier,
                                              boolean trim)
inserts a newline string specified by the user after every maxLineLen characters

Parameters:
s - the string to split
firstLineMaxLen - the max length (in characters) the first line may be
maxLineLen - the max length (in characters) a line may be
newlineIdentifier - the string to use to split lines up
trim - whether or not trim whitespace of each line's ends
Returns:
the split up string