com.planet_ink.coffee_mud.core
Class CMStrings

java.lang.Object
  extended by com.planet_ink.coffee_mud.core.CMStrings

public class CMStrings
extends java.lang.Object

A singleton of String utilities, string searchers, string builders, comparers, and alterers. Also includes my String comparison expression parser and evaluator. Also includes an adaptation of google's string differencer.


Nested Class Summary
static class CMStrings.Diff
          Class representing one diff operation.
static class CMStrings.DiffOperation
          The data structure representing a diff is a Linked list of Diff objects: {Diff(Operation.DELETE, "Hello"), Diff(Operation.INSERT, "Goodbye"), Diff(Operation.EQUAL, " world.")} which means: delete "Hello", add "Goodbye" and keep " world."
 
Field Summary
static java.lang.String[] emptyStringArray
          A string array with 0 entries
static java.lang.String SPACES
          1024 spaces
 
Method Summary
static java.lang.String bytesToStr(byte[] b)
          Converts the given byte array back into a string using the current threads CHARSETINPUT string encoding from the system properties.
static java.lang.String bytesToStr(java.lang.Object b)
          Converts the given object to a string by the following method: 1.
static java.lang.String capitalizeAllFirstLettersAndLower(java.lang.String name)
          Capitalizes the first letter in every word in the given string, and lowercases any other letters in each word.
static java.lang.String capitalizeAndLower(java.lang.String name)
          Capitalizes the first letter in the given string, and forcibly lowercases the remaining letters in the string.
static java.lang.String capitalizeFirstLetter(java.lang.String name)
          Capitalizes the first letter in the given string, if one is found.
static java.lang.String capitalizeFirstLetterAndEndSentence(java.lang.String name)
          Capitalizes the first letter in the given string, if one is found.
static java.lang.String centerPreserve(java.lang.String thisStr, int thisMuch)
          Pads the string equally to the left and right with spaces until it is the length of the given number.
static boolean compareStringArraysIgnoreCase(java.lang.String[] A1, java.lang.String[] A2)
          Compares the two string arrays to see if they are the same, but in a case-insensitive way.
static boolean contains(char[] anycs, char c)
          Checks whether the given character array contains the given character.
static boolean contains(java.lang.String[] strs, java.lang.String str)
          Returns whether the given string array contains the given string.
static boolean containsAny(java.lang.String str, char[] anycs)
          Checks whether the given string contains any of the given characters.
static boolean containsIgnoreCase(java.lang.String[] strs, java.lang.String str)
          Returns whether the given string array contains the given string.
static boolean containsStarterWith(java.lang.String[] strs, java.lang.String str)
          Returns whether the given string array contains a string that start is the first part of the given string, such that: str.startsWith(strs[x]) This check is Case Sensitive!
static boolean containsStartsWith(java.lang.String[] strs, java.lang.String str)
          Returns whether the given string array contains a string that starts with the given string.
static boolean containsWord(java.lang.String thisStr, java.lang.String word)
          Returns whether the given string contains the second string, without any following letter, which is the CMStrings definition of a "word".
static boolean containsWordIgnoreCase(java.lang.String thisStr, java.lang.String word)
          Returns whether the given string contains the second string, without any following letter, which is the CMStrings definition of a "word".
static java.lang.String convertHtmlToText(java.lang.StringBuilder finalData)
          This monstrous method converts an html document into a somewhat-readable text document for display in, for example, the text portion of an email, or in the mud command line.
static int countChars(java.lang.String str, char c)
          Counts the number of times the given character appears in the given string.
static int countSubstrings(java.lang.String[] set, java.lang.String[] things)
          Counts the number of times all of the strings in the second set appear in any of the strings in the first set.
static java.lang.String deEscape(java.lang.String str)
          This methods replaces any double-escapes to single escape characters, and any escaped double-quotes to double-quotes
static java.lang.String deleteAllofAny(java.lang.String str, char[] theseChars)
          Rebuilds the given string by deleting any instances of any of the characters in the given array.
static java.lang.String deleteAllofChar(java.lang.String str, char thisChar)
          Rebuilds the given string by deleting any instances of a given character The search is case-sensitive.
static java.lang.String determineEOLN(java.lang.CharSequence str)
          Returns the type of end-of-line used by the given charsequence.
static java.util.LinkedList<CMStrings.Diff> diff_main(java.lang.String text1, java.lang.String text2)
          Find the differences between two texts.
static java.util.LinkedList<CMStrings.Diff> diff_main(java.lang.String text1, java.lang.String text2, boolean checklines)
          Find the differences between two texts.
static java.lang.String ellipse(java.lang.String thisStr, int thisMuch)
          Pads the string to the right with three dots if the string is larger than the given number, or returns it unchanged otherwise.
static java.lang.String endWithAPeriod(java.lang.String str)
          Puts a period at the end of the last viewable character in this string, assuming there isn't already punctuation at the end.
static java.lang.String escape(java.lang.String str)
          This methods replaces any escapes to double-escape characters, and any double-quotes to escaped double-quotes
static boolean filenameMatcher(java.lang.String fileName, java.lang.String fileNameMask)
          Does traditional filename type matching, where ? substitutes for a single character, and * for a bunch.
static int finalDigits(java.lang.String s)
          Returns the value of any digits at the end of the given string.
static java.lang.String getEOL(java.lang.String str, java.lang.String defaultEOL)
          Returns the apparent end of line string used by the given string.
static java.lang.String getSayFromMessage(java.lang.String msg)
          Returns the string between the first and last ' characters in the given string, or null if no such characters were found.
static int indexOf(char[] anycs, char c)
          Checks whether the given character array contains the given character and if so, returns the index in the array of the character This method is case-sensitive!
static int indexOfEndOfWord(java.lang.String s, int startWith)
          Returns the next index in the given string of an end-of-word character, such as space,.;? or !.
static int indexOfLastVowel(java.lang.String s)
          Returns the character index of the last vowel in this string
static CMStrings instance()
          Returns a static instance of this singleton
static boolean isLowerCase(java.lang.String str)
          Returns true if the given string is in lowercase, meaning it has no uppercase characters.
static boolean isUpperCase(java.lang.String str)
          Returns true if the given string is in uppercase, meaning it has no lowercase characters.
static boolean isVowel(char c)
          Returns true if the given character is a vowel AEIOU, or false otherwise.
static java.lang.String lastWordIn(java.lang.String thisStr)
          Returns all characters after the last space in the given string, or just returns the given string if no spaces were found.
static int lengthMinusColors(java.lang.String thisStr)
          Returns the length of the string as if it has neither ansi nor cm color codes.
static java.lang.String limit(java.lang.String thisStr, int thisMuch)
          Truncates the given string if the string is larger than the given number, or returns it unchanged otherwise.
static java.lang.String limit(java.lang.String prefixColorStr, java.lang.String thisStr, java.lang.String suffixColorStr, int thisMuch)
          Truncates the given string if the string is larger than the given number, or returns it unchanged otherwise.
static java.lang.String ltrim(java.lang.String str)
          Trims the given string, but only from the front (left side).
static java.util.Map<java.lang.Object,java.lang.Integer> makeNumericHash(java.lang.Object[] obj)
          Given an array of objects, this method creates a map of those objects to their ordinal numeric values.
static java.util.Map<java.lang.Object,java.lang.Integer> makeNumericHash(java.lang.Object[] obj, int firstInt)
          Given an array of objects, this method creates a map of those objects to their ordinal numeric values, with a given opener.
static java.lang.String padCenter(java.lang.String thisStr, int thisMuch)
          Pads the string equally to the left and right with spaces until it is the length of the given number.
static java.lang.String padLeft(java.lang.String thisStr, int thisMuch)
          Pads the string to the left with spaces until it is the length of the given number.
static java.lang.String padLeft(java.lang.String thisStr, java.lang.String colorPrefix, int thisMuch)
          Pads the string to the left with spaces until it is the length of the given number.
static java.lang.String padLeftPreserve(java.lang.String thisStr, int thisMuch)
          Pads the string to the left with spaces until it is the length of the given number.
static java.lang.String padLeftWith(java.lang.String thisStr, char c, int thisMuch)
          Pads the string to the left with the given character until it is the length of the given number.
static java.lang.String padRight(java.lang.String thisStr, int thisMuch)
          Pads the string to the right with spaces until it is the length of the given number.
static java.lang.String padRight(java.lang.String thisStr, java.lang.String colorSuffix, int thisMuch)
          Pads the string to the right with spaces until it is the length of the given number.
static java.lang.String padRight(java.lang.String prefixColorStr, java.lang.String thisStr, java.lang.String suffixColorStr, int thisMuch)
          Pads the string to the right with spaces until it is the length of the given number.
static java.lang.String padRightPreserve(java.lang.String thisStr, int thisMuch)
          Pads the string to the right with spaces until it is the length of the given number.
static java.lang.String padRightWith(java.lang.String thisStr, char c, int thisMuch)
          Pads the string to the right with the given character until it is the length of the given number.
static boolean parseStringExpression(java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> variables, boolean emptyVarsOK)
          Parses a string comparison expression and returns the result of the evaluation.
static java.lang.String removeColors(java.lang.String s)
          Strips colors, of both the ansi, and cm code variety
static java.lang.String removePunctuation(java.lang.String s)
          Strips punctuation characters, leaving only letters and numbers and such.
static java.lang.String repeat(char chr1, int times)
          Builds a string consisting entirely of the given character, the given number of times in a row.
static java.lang.String repeat(java.lang.String str1, int times)
          Builds a string consisting entirely of the given String, the given number of times in a row.
static java.lang.String repeatWithLimit(char chr1, int times, int limit)
          Builds a string consisting entirely of the given character, the given number of times in a row.
static java.lang.StringBuffer replaceAll(java.lang.StringBuffer str, java.lang.String thisStr, java.lang.String withThisStr)
          Finds all instances of the second parameter string in the first StringBuffer, replaces them with the third word.
static java.lang.String replaceAll(java.lang.String str, java.lang.String thisStr, java.lang.String withThisStr)
          Finds all instances of the second parameter string in the first string, replaces them with the third word.
static java.lang.String replaceAllofAny(java.lang.String str, char[] theseChars, char with)
          Rebuilds the given string by replacing any instances of any of the characters in the given array with the given character.
static java.lang.String replaceAllofAny(java.lang.String str, char[] theseChars, char[] withThese)
          Rebuilds the given string by replacing any instances of any of the characters in the given array with the given character.
static java.lang.String replaceAlls(java.lang.String str, java.lang.String[][] pairs)
          Builds a new version of the given string by replacing all instances of the first string in each pair with the second string.
static java.lang.String replaceFirst(java.lang.String str, java.lang.String thisStr, java.lang.String withThisStr)
          Finds the first and only the first instance of the second parameter string in the first string, and replaces it with the third string.
static java.lang.String replaceFirstWord(java.lang.String str, java.lang.String thisStr, java.lang.String withThisStr)
          Finds the first and only the first instance of the second parameter word in the first string, and replaces it with the third word.
static java.lang.String[] replaceInAll(java.lang.String[] strs, java.lang.String thisStr, java.lang.String withThisStr)
          Finds all instances of the second parameter string in each of the strings in the array, replaces them with the third word.
static void replaceVariables(java.lang.StringBuffer str, java.lang.String[] values)
          Replaces @x1 type variables inside a stringbuffer with an actual value Not used in the main expression system, this is a stand alone function Also uniquely, supports @x numbers above 10.
static java.lang.String replaceVariables(java.lang.String str, java.lang.String[] values)
          Replaces @x1 type variables inside a stringbuffer with an actual value Not used in the main expression system, this is a stand alone function Also uniquely, supports @x numbers above 10.
static java.lang.String replaceWord(java.lang.String str, java.lang.String thisStr, java.lang.String withThisStr)
          Finds all instances of the second parameter word in the first string, and replaces it with the third word.
static java.lang.String rtrim(java.lang.String str)
          Trims the given string, but only from the end (right side).
static java.lang.String s_lowercase(java.lang.String str)
          Returns the given string in lowercase, or "" if the string was null.
static java.lang.String s_uppercase(java.lang.String str)
          Returns the given string in uppercase, or "" if the string was null.
static java.lang.String safeLeft(java.lang.String thisStr, int thisMuch)
          Truncates the given string if the string is larger than the given number, or returns it unchanged otherwise.
static java.lang.String sameCase(java.lang.String str, char c)
          Returns the given string in the same entire case as the character given.
static java.lang.String scrunchWord(java.lang.String s, int len)
          Attempts to make the given string only as long as the given length by first removing all spaces, and then removing all vowels, and finally just truncating it at the end.
static java.util.Map.Entry<java.lang.Character,java.lang.String>[] splitMulti(java.lang.String str, char[] splitters)
          This strange method parses the given string for one of the characters in the given array.
static void stripHeadHtmlTags(java.lang.StringBuilder finalData)
          Strips the leading and trailing <HTML>, <HEAD>, and <BODY> tags from the given StringBuilder.
static byte[] strToBytes(java.lang.String str)
          Converts the given string to bytes using the current threads CHARSETINPUT string encoding from the system properties.
static java.lang.String substituteSayInMessage(java.lang.String affmsg, java.lang.String msg)
          This method replaces the string between the first and last ' characters in the first string with the second string.
static java.lang.String trimQuotes(java.lang.String thisStr)
          If the given string both begins and ends with double-quotes ", then this method removes them before returning the string, and does nothing otherwise.
static java.lang.String truncate(java.lang.String thisStr, int thisMuch)
          Truncates the given string if the string is larger than the given number, or returns it unchanged otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

emptyStringArray

public static final java.lang.String[] emptyStringArray
A string array with 0 entries


SPACES

public static final java.lang.String SPACES
1024 spaces

Method Detail

instance

public static final CMStrings instance()
Returns a static instance of this singleton

Returns:
a static instance of this singleton

repeat

public static final java.lang.String repeat(java.lang.String str1,
                                            int times)
Builds a string consisting entirely of the given String, the given number of times in a row.

Parameters:
str1 - the String to repeat
times - the size of the string
Returns:
a string of those Strings

rtrim

public static final java.lang.String rtrim(java.lang.String str)
Trims the given string, but only from the end (right side). Otherwise, acts just like String.trim()

Parameters:
str - the string to trim
Returns:
the right-trimmed string

ltrim

public static final java.lang.String ltrim(java.lang.String str)
Trims the given string, but only from the front (left side). Otherwise, acts just like String.trim()

Parameters:
str - the string to trim
Returns:
the left-trimmed string

repeat

public static final java.lang.String repeat(char chr1,
                                            int times)
Builds a string consisting entirely of the given character, the given number of times in a row.

Parameters:
chr1 - the character to repeat
times - the size of the string
Returns:
a string of those characters

repeatWithLimit

public static final java.lang.String repeatWithLimit(char chr1,
                                                     int times,
                                                     int limit)
Builds a string consisting entirely of the given character, the given number of times in a row. If the number of times is higher than a given limit, then an "x" and a number of extra times over the limit is added.

Parameters:
chr1 - the character to repeat
times - the size of the string
limit - the maximum number of repeats before xNN
Returns:
a string of those characters

isUpperCase

public static final boolean isUpperCase(java.lang.String str)
Returns true if the given string is in uppercase, meaning it has no lowercase characters.

Parameters:
str - the string to check
Returns:
true if the string is in uppercase, false otherwise

isLowerCase

public static final boolean isLowerCase(java.lang.String str)
Returns true if the given string is in lowercase, meaning it has no uppercase characters.

Parameters:
str - the string to check
Returns:
true if the string is in lowercase, false otherwise

s_uppercase

public static final java.lang.String s_uppercase(java.lang.String str)
Returns the given string in uppercase, or "" if the string was null.

Parameters:
str - the string, or null
Returns:
the string in uppercase, or "" if null

s_lowercase

public static final java.lang.String s_lowercase(java.lang.String str)
Returns the given string in lowercase, or "" if the string was null.

Parameters:
str - the string, or null
Returns:
the string in lowercase, or "" if null

endWithAPeriod

public static final java.lang.String endWithAPeriod(java.lang.String str)
Puts a period at the end of the last viewable character in this string, assuming there isn't already punctuation at the end. Preserves any trailing special color codes.

Parameters:
str - the string to end with a period.
Returns:
the string, with a period at the end.

bytesToStr

public static final java.lang.String bytesToStr(java.lang.Object b)
Converts the given object to a string by the following method: 1. If it's a string, returns the string 2. If it's a byte array, returns it as a string decoded using the current threads CHARSETINPUT from the system properties 3. If it's non-null, it calls toString() 4. Returns ""

Parameters:
b - the object to inspect
Returns:
the string

bytesToStr

public static final java.lang.String bytesToStr(byte[] b)
Converts the given byte array back into a string using the current threads CHARSETINPUT string encoding from the system properties.

Parameters:
b - the byte array to decode
Returns:
the string representation of the byte array

strToBytes

public static final byte[] strToBytes(java.lang.String str)
Converts the given string to bytes using the current threads CHARSETINPUT string encoding from the system properties.

Parameters:
str - the string to encode
Returns:
the string, encoded into bytes from the

isVowel

public static final boolean isVowel(char c)
Returns true if the given character is a vowel AEIOU, or false otherwise. This check is case-insensitive

Parameters:
c - the character to look at
Returns:
true if the character is a vowel, false otherwise

indexOfEndOfWord

public static final int indexOfEndOfWord(java.lang.String s,
                                         int startWith)
Returns the next index in the given string of an end-of-word character, such as space,.;? or !. It returns that index.

Parameters:
s - the string to look inside of
startWith - the starting index for the search
Returns:
the index of the end-of-word char, or string length for no more

indexOfLastVowel

public static final int indexOfLastVowel(java.lang.String s)
Returns the character index of the last vowel in this string

Parameters:
s - the string to look in
Returns:
the index of the last vowel

scrunchWord

public static final java.lang.String scrunchWord(java.lang.String s,
                                                 int len)
Attempts to make the given string only as long as the given length by first removing all spaces, and then removing all vowels, and finally just truncating it at the end. No special accomodations are made about these strings -- they are assumed to be uncoded ascii.

Parameters:
s - the string to scrunch
len - the maximum length of the string
Returns:
the scrunches string, or the whole string, if <= len

finalDigits

public static final int finalDigits(java.lang.String s)
Returns the value of any digits at the end of the given string. If no digits are found, returns -1.

Parameters:
s - the string to look for digits at the end of
Returns:
the value of any trailing digits, or -1

splitMulti

public static final java.util.Map.Entry<java.lang.Character,java.lang.String>[] splitMulti(java.lang.String str,
                                                                                           char[] splitters)
This strange method parses the given string for one of the characters in the given array. Whenever one of the characters is encountered, a Map Entry where the splitter is the key and the preceding characters are the split string is added to a final array of map entries.

Parameters:
str - the string to parse
splitters - the delimiters, and also the keys to the map.entry
Returns:
an array of all key/delimiters and the preceiding characters.

containsWordIgnoreCase

public static final boolean containsWordIgnoreCase(java.lang.String thisStr,
                                                   java.lang.String word)
Returns whether the given string contains the second string, without any following letter, which is the CMStrings definition of a "word". This check is case in-sensitive.

Parameters:
thisStr - the string to look in
word - the string/word to look for
Returns:
true if the word is in the string, and false otherwise

containsWord

public static final boolean containsWord(java.lang.String thisStr,
                                         java.lang.String word)
Returns whether the given string contains the second string, without any following letter, which is the CMStrings definition of a "word". This check is case sensitive.

Parameters:
thisStr - the string to look in
word - the string/word to look for
Returns:
true if the word is in the string, and false otherwise

replaceAllofAny

public static final java.lang.String replaceAllofAny(java.lang.String str,
                                                     char[] theseChars,
                                                     char with)
Rebuilds the given string by replacing any instances of any of the characters in the given array with the given character. The search is case-sensitive.

Parameters:
str - the string to rebuild without those characters
theseChars - the characters to remove from the string
with - the character to replace all the array characters with.
Returns:
the rebuilt string, with all those characters replaced

replaceAllofAny

public static final java.lang.String replaceAllofAny(java.lang.String str,
                                                     char[] theseChars,
                                                     char[] withThese)
Rebuilds the given string by replacing any instances of any of the characters in the given array with the given character. The search is case-sensitive.

Parameters:
str - the string to rebuild without those characters
theseChars - the characters to remove from the string
withThese - the character to replace all the array characters with.
Returns:
the rebuilt string, with all those characters replaced

deleteAllofAny

public static final java.lang.String deleteAllofAny(java.lang.String str,
                                                    char[] theseChars)
Rebuilds the given string by deleting any instances of any of the characters in the given array. The search is case-sensitive.

Parameters:
str - the string to rebuild without those characters
theseChars - the characters to remove from the string
Returns:
the rebuilt string, without the characters

deleteAllofChar

public static final java.lang.String deleteAllofChar(java.lang.String str,
                                                     char thisChar)
Rebuilds the given string by deleting any instances of a given character The search is case-sensitive.

Parameters:
str - the string to rebuild without those characters
thisChar - the character to remove from the string
Returns:
the rebuilt string, without the character

replaceAll

public static final java.lang.String replaceAll(java.lang.String str,
                                                java.lang.String thisStr,
                                                java.lang.String withThisStr)
Finds all instances of the second parameter string in the first string, replaces them with the third word. Returns the string with or without changes. The search is case sensitive

Parameters:
str - the string to look inside of
thisStr - the string to look for inside the first string
withThisStr - the string to replace the second string with, where found.
Returns:
the string modified, or not modified if no replacements were made.

deEscape

public static final java.lang.String deEscape(java.lang.String str)
This methods replaces any double-escapes to single escape characters, and any escaped double-quotes to double-quotes

Parameters:
str - the string to de-escape
Returns:
the string, de-escaped

escape

public static final java.lang.String escape(java.lang.String str)
This methods replaces any escapes to double-escape characters, and any double-quotes to escaped double-quotes

Parameters:
str - the string to escape
Returns:
the string, escaped

replaceAll

public static final java.lang.StringBuffer replaceAll(java.lang.StringBuffer str,
                                                      java.lang.String thisStr,
                                                      java.lang.String withThisStr)
Finds all instances of the second parameter string in the first StringBuffer, replaces them with the third word. Returns the StringBuffer with or without changes. The search is case sensitive

Parameters:
str - the StringBuffer to look inside of
thisStr - the string to look for inside the first string
withThisStr - the string to replace the second string with, where found.
Returns:
the StringBuffer modified, or not modified if no replacements were made.

replaceInAll

public static final java.lang.String[] replaceInAll(java.lang.String[] strs,
                                                    java.lang.String thisStr,
                                                    java.lang.String withThisStr)
Finds all instances of the second parameter string in each of the strings in the array, replaces them with the third word. Returns the string array with or without changes. The search is case sensitive

Parameters:
strs - the string array to look inside of
thisStr - the string to look for inside the array strings
withThisStr - the string to replace the second string with, where found.
Returns:
the string array modified, or not modified if no replacements were made.

replaceAlls

public static final java.lang.String replaceAlls(java.lang.String str,
                                                 java.lang.String[][] pairs)
Builds a new version of the given string by replacing all instances of the first string in each pair with the second string. The pairs should be allocated String[N][2] where N is any number of pairs, and 0 index string is the one to replace with the string in the 1 index. This method is case-sensitive!

Parameters:
str - the string to rebuild
pairs - the string pairs for search/replace duties
Returns:
the rebuilt string

replaceWord

public static final java.lang.String replaceWord(java.lang.String str,
                                                 java.lang.String thisStr,
                                                 java.lang.String withThisStr)
Finds all instances of the second parameter word in the first string, and replaces it with the third word. Returns the first string with or without changes. The string is only altered where the second string appears as a inside the first string with no trailing letters to alter the word. Preceding letters appear to be ok. The search is case insensitive, but the replacement will be made intelligently to preserve the case of the word(s) being replaced.

Parameters:
str - the string to look inside of
thisStr - the string to look for inside the first string
withThisStr - the string to replace the second string with, where found.
Returns:
the string modified, or not modified if no replacements were made.

replaceFirstWord

public static final java.lang.String replaceFirstWord(java.lang.String str,
                                                      java.lang.String thisStr,
                                                      java.lang.String withThisStr)
Finds the first and only the first instance of the second parameter word in the first string, and replaces it with the third word. Returns the first string with or without changes. The string is only altered if the second string appears as a inside the first string with no trailing letters to alter the word. Preceding letters appear to be ok. The search is case insensitive, but the replacement will be made intelligently to preserve the case of the word being replaced.

Parameters:
str - the string to look inside of
thisStr - the string to look for inside the first string
withThisStr - the string to replace the second string with, if found.
Returns:
the string modified, or not modified if no replacement was made.

replaceFirst

public static final java.lang.String replaceFirst(java.lang.String str,
                                                  java.lang.String thisStr,
                                                  java.lang.String withThisStr)
Finds the first and only the first instance of the second parameter string in the first string, and replaces it with the third string. Returns the first string with or without changes. This method is case sensitive.

Parameters:
str - the string to look inside of
thisStr - the string to look for inside the first string
withThisStr - the string to replace the second string with, if found.
Returns:
the string modified, or not modified if no replacement was made.

capitalizeAndLower

public static final java.lang.String capitalizeAndLower(java.lang.String name)
Capitalizes the first letter in the given string, and forcibly lowercases the remaining letters in the string. This method respects special CoffeeMUD color codes, skipping over them to find that elusive first letter.

Parameters:
name - the string to capitalize and lowercase
Returns:
the string, capitalized, with other letters lowercased

capitalizeAllFirstLettersAndLower

public static final java.lang.String capitalizeAllFirstLettersAndLower(java.lang.String name)
Capitalizes the first letter in every word in the given string, and lowercases any other letters in each word. This method respects special CoffeeMUD color codes, skipping over them to find that elusive first letters.

Parameters:
name - the string with words to capitalize and lowercase.
Returns:
the string, with all words capitalized and remaining word letters lowercased.

capitalizeFirstLetterAndEndSentence

public static final java.lang.String capitalizeFirstLetterAndEndSentence(java.lang.String name)
Capitalizes the first letter in the given string, if one is found. This method respects special CoffeeMUD color codes, skipping over them to find that elusive first letter. This will also add a period at the end, if no other punctuation is found.

Parameters:
name - the string to capitalize and punctuationify
Returns:
the string, capitalized and punctuated

capitalizeFirstLetter

public static final java.lang.String capitalizeFirstLetter(java.lang.String name)
Capitalizes the first letter in the given string, if one is found. This method respects special CoffeeMUD color codes, skipping over them to find that elusive first letter.

Parameters:
name - the string to capitalize
Returns:
the string, capitalized

lastWordIn

public static final java.lang.String lastWordIn(java.lang.String thisStr)
Returns all characters after the last space in the given string, or just returns the given string if no spaces were found.

Parameters:
thisStr - the string to look for spaces in
Returns:
the substring after the last space, or the whole string

getSayFromMessage

public static final java.lang.String getSayFromMessage(java.lang.String msg)
Returns the string between the first and last ' characters in the given string, or null if no such characters were found.

Parameters:
msg - the string to parse out from
Returns:
the string between the ' characters, or null

substituteSayInMessage

public static final java.lang.String substituteSayInMessage(java.lang.String affmsg,
                                                            java.lang.String msg)
This method replaces the string between the first and last ' characters in the first string with the second string.

Parameters:
affmsg - the string to replace a portion of
msg - the string to insert into the first string, between the ' chars
Returns:
the new string, or unchanged if there is nothing to do

containsIgnoreCase

public static final boolean containsIgnoreCase(java.lang.String[] strs,
                                               java.lang.String str)
Returns whether the given string array contains the given string. This check is case insensitive.

Parameters:
strs - the array to look in
str - the string to look for
Returns:
true if the array contained the string, and false otherwise

compareStringArraysIgnoreCase

public static final boolean compareStringArraysIgnoreCase(java.lang.String[] A1,
                                                          java.lang.String[] A2)
Compares the two string arrays to see if they are the same, but in a case-insensitive way.

Parameters:
A1 - the first string array
A2 - the second string array
Returns:
true if the arrays are the same, and false otherwise.

contains

public static final boolean contains(java.lang.String[] strs,
                                     java.lang.String str)
Returns whether the given string array contains the given string. This check is Case Sensitive!

Parameters:
strs - the array to look in
str - the string to look for
Returns:
true if the array contained the string, and false otherwise

contains

public static final boolean contains(char[] anycs,
                                     char c)
Checks whether the given character array contains the given character. This method is case-sensitive!

Parameters:
anycs - the character array to look in
c - the character to look for
Returns:
true if the array contained the character, false otherwise

indexOf

public static final int indexOf(char[] anycs,
                                char c)
Checks whether the given character array contains the given character and if so, returns the index in the array of the character This method is case-sensitive!

Parameters:
anycs - the character array to look in
c - the character to look for
Returns:
the index of the character in the array, or -1

containsAny

public static final boolean containsAny(java.lang.String str,
                                        char[] anycs)
Checks whether the given string contains any of the given characters. This method is case sensitive!

Parameters:
str - the string to check
anycs - the list of characters to look for
Returns:
true if any characters were found, false otherwise

containsStartsWith

public static final boolean containsStartsWith(java.lang.String[] strs,
                                               java.lang.String str)
Returns whether the given string array contains a string that starts with the given string. This check is Case Sensitive!

Parameters:
strs - the array to look in
str - the string to look for
Returns:
true if the array contained the string beginning, and false otherwise

containsStarterWith

public static final boolean containsStarterWith(java.lang.String[] strs,
                                                java.lang.String str)
Returns whether the given string array contains a string that start is the first part of the given string, such that: str.startsWith(strs[x]) This check is Case Sensitive!

Parameters:
strs - the array to look in
str - the string to look for
Returns:
true if the array contained the string beginning, and false otherwise

replaceVariables

public static final void replaceVariables(java.lang.StringBuffer str,
                                          java.lang.String[] values)
Replaces @x1 type variables inside a stringbuffer with an actual value Not used in the main expression system, this is a stand alone function Also uniquely, supports @x numbers above 10. Values are *1* indexed!!

Parameters:
str - the stringbuffer to assess
values - values to replace each variable with

replaceVariables

public static final java.lang.String replaceVariables(java.lang.String str,
                                                      java.lang.String[] values)
Replaces @x1 type variables inside a stringbuffer with an actual value Not used in the main expression system, this is a stand alone function Also uniquely, supports @x numbers above 10. Values are *1* indexed!!

Parameters:
str - the stringbuffer to assess
values - values to replace each variable with
Returns:
the string with values replaced.

removePunctuation

public static final java.lang.String removePunctuation(java.lang.String s)
Strips punctuation characters, leaving only letters and numbers and such.

Parameters:
s - the string to strip
Returns:
the stripped string

removeColors

public static final java.lang.String removeColors(java.lang.String s)
Strips colors, of both the ansi, and cm code variety

Parameters:
s - the string to strip
Returns:
the stripped string

lengthMinusColors

public static final int lengthMinusColors(java.lang.String thisStr)
Returns the length of the string as if it has neither ansi nor cm color codes.

Parameters:
thisStr - the string to get the length of
Returns:
the length of thisStr w/o colors

convertHtmlToText

public static java.lang.String convertHtmlToText(java.lang.StringBuilder finalData)
This monstrous method converts an html document into a somewhat-readable text document for display in, for example, the text portion of an email, or in the mud command line. It does things like remove scripts, convert  -like tags to their ascii values, and converts <P>, <BR>, and <DIV> tags to CRLF.

Parameters:
finalData - the stringbuilder containing the html to convert.
Returns:
the converted string (finalData is also modified)

getEOL

public static java.lang.String getEOL(java.lang.String str,
                                      java.lang.String defaultEOL)
Returns the apparent end of line string used by the given string. Returns the default if it can't be determined.

Parameters:
str - the string to check
defaultEOL - eol string to use if undetermined
Returns:
the end of line string

stripHeadHtmlTags

public static void stripHeadHtmlTags(java.lang.StringBuilder finalData)
Strips the leading and trailing <HTML>, <HEAD>, and <BODY> tags from the given StringBuilder.

Parameters:
finalData - the StringBuilder to remove leading tags from.

makeNumericHash

public static final java.util.Map<java.lang.Object,java.lang.Integer> makeNumericHash(java.lang.Object[] obj)
Given an array of objects, this method creates a map of those objects to their ordinal numeric values.

Parameters:
obj - the array of objects
Returns:
a map of the objects and their ordinal numeric values.

makeNumericHash

public static final java.util.Map<java.lang.Object,java.lang.Integer> makeNumericHash(java.lang.Object[] obj,
                                                                                      int firstInt)
Given an array of objects, this method creates a map of those objects to their ordinal numeric values, with a given opener.

Parameters:
obj - the array of objects
firstInt - the ordinal value to start with
Returns:
a map of the objects and their ordinal numeric values.

padCenter

public static final java.lang.String padCenter(java.lang.String thisStr,
                                               int thisMuch)
Pads the string equally to the left and right with spaces until it is the length of the given number. If the string is already larger than the given number, no spaces are added, and the string is truncated. Color codes are removed if truncation is necessary. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad
thisMuch - the final minimum length of the string.
Returns:
the string padded, or truncated if already too long

padLeft

public static final java.lang.String padLeft(java.lang.String thisStr,
                                             int thisMuch)
Pads the string to the left with spaces until it is the length of the given number. If the string is already larger than the given number, the string is truncated at the end until it is the given length. If the string must be truncated, any color codes are also removed. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad or truncate
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

padLeftWith

public static final java.lang.String padLeftWith(java.lang.String thisStr,
                                                 char c,
                                                 int thisMuch)
Pads the string to the left with the given character until it is the length of the given number. If the string is already larger than the given number, the string is truncated at the end until it is the given length. If the string must be truncated, any color codes are also removed. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad or truncate
c - the character to pad the string with
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

padLeft

public static final java.lang.String padLeft(java.lang.String thisStr,
                                             java.lang.String colorPrefix,
                                             int thisMuch)
Pads the string to the left with spaces until it is the length of the given number. If the string is already larger than the given number, the string is truncated at the end until it is the given length. This method always prepends the given colorSuffix string to the beginning of the string after any spaces are added, before the string is truncated. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad or truncate
colorPrefix - the string to always add to the beginning of the given string before spaces
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

safeLeft

public static final java.lang.String safeLeft(java.lang.String thisStr,
                                              int thisMuch)
Truncates the given string if the string is larger than the given number, or returns it unchanged otherwise. NO special color codes are removed or evaluated -- this is simple string truncation.

Parameters:
thisStr - the string to pad or truncate
thisMuch - the final maximum length of the string.
Returns:
the string truncated, or unchanged if not long enough

truncate

public static final java.lang.String truncate(java.lang.String thisStr,
                                              int thisMuch)
Truncates the given string if the string is larger than the given number, or returns it unchanged otherwise. NO special color codes are removed or evaluated -- this is simple string truncation.

Parameters:
thisStr - the string to pad or truncate
thisMuch - the final maximum length of the string.
Returns:
the string truncated, or unchanged if not long enough

trimQuotes

public static final java.lang.String trimQuotes(java.lang.String thisStr)
If the given string both begins and ends with double-quotes ", then this method removes them before returning the string, and does nothing otherwise.

Parameters:
thisStr - the string to remove quotes from
Returns:
the string without prefix and suffix quotes, or unchanged

padRight

public static final java.lang.String padRight(java.lang.String thisStr,
                                              int thisMuch)
Pads the string to the right with spaces until it is the length of the given number. If the string is already larger than the given number, the string is truncated at the end until it is the given length. If the string must be truncated, any color codes are also removed. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad or truncate
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

padRight

public static final java.lang.String padRight(java.lang.String prefixColorStr,
                                              java.lang.String thisStr,
                                              java.lang.String suffixColorStr,
                                              int thisMuch)
Pads the string to the right with spaces until it is the length of the given number. If the string is already larger than the given number, the string is truncated at the end until it is the given length. If the string must be truncated, any color codes are also removed. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
prefixColorStr - the string to prefix the padded string with
thisStr - the string to pad or truncate
suffixColorStr - the string to suffix the string before padding
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

padRightWith

public static final java.lang.String padRightWith(java.lang.String thisStr,
                                                  char c,
                                                  int thisMuch)
Pads the string to the right with the given character until it is the length of the given number. If the string is already larger than the given number, the string is truncated at the end until it is the given length. If the string must be truncated, any color codes are also removed. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad or truncate
c - the character to pad the string with
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

limit

public static final java.lang.String limit(java.lang.String prefixColorStr,
                                           java.lang.String thisStr,
                                           java.lang.String suffixColorStr,
                                           int thisMuch)
Truncates the given string if the string is larger than the given number, or returns it unchanged otherwise. If the string is larger than the given number, color codes are removed. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
prefixColorStr - the string to prefix the padded string with
thisStr - the string to pad or truncate
suffixColorStr - the string to suffix the string before padding
thisMuch - the final maximum length of the string.
Returns:
the string truncated, or unchanged if not long enough

limit

public static final java.lang.String limit(java.lang.String thisStr,
                                           int thisMuch)
Truncates the given string if the string is larger than the given number, or returns it unchanged otherwise. If the string is larger than the given number, color codes are removed. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad or truncate
thisMuch - the final maximum length of the string.
Returns:
the string truncated, or unchanged if not long enough

ellipse

public static final java.lang.String ellipse(java.lang.String thisStr,
                                             int thisMuch)
Pads the string to the right with three dots if the string is larger than the given number, or returns it unchanged otherwise. If the string is larger than the given number, the string is truncated at the end, color codes removed, until it is the given length, and the ellipse added. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad or truncate
thisMuch - the final maximum length of the string before ...
Returns:
the string padded, or unchanged if not long enough

padRight

public static final java.lang.String padRight(java.lang.String thisStr,
                                              java.lang.String colorSuffix,
                                              int thisMuch)
Pads the string to the right with spaces until it is the length of the given number. If the string is already larger than the given number, the string is truncated at the end until it is the given length. This method always adds the given colorSuffix string to the end of the string before any spaces are added, or after the string is truncated. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad or truncate
colorSuffix - the string to always add to the end of the given string before spaces
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

padRightPreserve

public static final java.lang.String padRightPreserve(java.lang.String thisStr,
                                                      int thisMuch)
Pads the string to the right with spaces until it is the length of the given number. If the string is already larger than the given number, no spaces are added, and the string is returned unchanged. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

centerPreserve

public static final java.lang.String centerPreserve(java.lang.String thisStr,
                                                    int thisMuch)
Pads the string equally to the left and right with spaces until it is the length of the given number. If the string is already larger than the given number, no spaces are added, and the string is returned unchanged. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

padLeftPreserve

public static final java.lang.String padLeftPreserve(java.lang.String thisStr,
                                                     int thisMuch)
Pads the string to the left with spaces until it is the length of the given number. If the string is already larger than the given number, no spaces are added, and the string is returned unchanged. This method removes any special CoffeeMud/ANSI color codes before calculating length.

Parameters:
thisStr - the string to pad
thisMuch - the final minimum length of the string.
Returns:
the string padded, or unchanged if already too long

sameCase

public static final java.lang.String sameCase(java.lang.String str,
                                              char c)
Returns the given string in the same entire case as the character given.

Parameters:
str - the string to make upper or lowercase
c - if this character is uppercase, makes the whole string uppercase, etc.
Returns:
the given str, with the case changed.

parseStringExpression

public static final boolean parseStringExpression(java.lang.String expression,
                                                  java.util.Map<java.lang.String,java.lang.Object> variables,
                                                  boolean emptyVarsOK)
                                           throws java.lang.Exception
Parses a string comparison expression and returns the result of the evaluation. Basic comparison operators include = > < >= <= != and IN. The IN operator is a substring check. Comparisons may be between string literals/variables, or numeric literals/variables. Numeric literals and variables may be combined using +, -, *, /, and ?, where ? is a special operator for random-number generation, which separates the lowest and highest number in a range, inclusive. Conjunctions include AND & OR | and XOR. Parenthesis () may be used to group expressions. NOT is a valid prefix to negate an evaluation. All checks are always case-insensitive. Variables may be included, which are substituted at evaluation time. Variables are designated in the expression by prefix with $. Variables are checked case-sensitive first, and then as uppercase. If not found, an exception is thrown, unless the emptyVarsOk field was set to true. The value of variables should always be a String obj.

Parameters:
expression - the string expression to evaluate
variables - the map of variable names to String objects
emptyVarsOK - true if missing variables are "", and false otherwise.
Returns:
true if the expression evaluates to TRUE, and false otherwise
Throws:
java.lang.Exception - an error occurred in parsing

countSubstrings

public static final int countSubstrings(java.lang.String[] set,
                                        java.lang.String[] things)
Counts the number of times all of the strings in the second set appear in any of the strings in the first set. The search is substring based, so a second set string may appear multiple times in a first set string.

Parameters:
set - the set of strings to search through
things - the set of strings to search FOR
Returns:
the number of times any of the things appears in any of the set strings

countChars

public static final int countChars(java.lang.String str,
                                   char c)
Counts the number of times the given character appears in the given string.

Parameters:
str - the string to search through
c - the character to count
Returns:
the number of times the character appears in the string

determineEOLN

public static final java.lang.String determineEOLN(java.lang.CharSequence str)
Returns the type of end-of-line used by the given charsequence. Considers \r, \n, \n\r, and \r\n as valid options.

Parameters:
str - the char sequence to check
Returns:
the first valid end-of-line found.

diff_main

public static java.util.LinkedList<CMStrings.Diff> diff_main(java.lang.String text1,
                                                             java.lang.String text2)
Find the differences between two texts. Run a faster, slightly less optimal diff. This method allows the 'checklines' of diff_main() to be optional. Most of the time checklines is wanted, so default to true.

Parameters:
text1 - Old string to be diffed.
text2 - New string to be diffed.
Returns:
Linked List of Diff objects.

diff_main

public static java.util.LinkedList<CMStrings.Diff> diff_main(java.lang.String text1,
                                                             java.lang.String text2,
                                                             boolean checklines)
Find the differences between two texts.

Parameters:
text1 - Old string to be diffed.
text2 - New string to be diffed.
checklines - Speedup flag. If false, then don't run a line-level diff first to identify the changed areas. If true, then run a faster slightly less optimal diff.
Returns:
Linked List of Diff objects.

filenameMatcher

public static final boolean filenameMatcher(java.lang.String fileName,
                                            java.lang.String fileNameMask)
Does traditional filename type matching, where ? substitutes for a single character, and * for a bunch. This check is case sensitive! You need to upper or lower both strings before calling to make it insensitive

Parameters:
fileName - the name to check for a match
fileNameMask - the mask to match the fileName against
Returns:
true if they match, false otherwise