jatha
Class MacroUtil

java.lang.Object
  |
  +--jatha.MacroUtil

public class MacroUtil
extends java.lang.Object

Helper functions for macros.


Constructor Summary
MacroUtil()
           
 
Method Summary
static java.lang.String capitalize(java.lang.String str)
          Capitalize the first character in a String.
static java.lang.String clip(java.lang.String str, int front, int back)
          Removes characters from both ends of a string.
static java.lang.String escapify(java.lang.String str)
          Replaces special characters like newlines, tabs, quotes, and backslashes into escaped character sequences (e.g.
static int findMatchingEndParen(java.lang.String str, int startIndex)
          Searches through a string to find a matching ')' character.
static boolean isJavaReservedWord(java.lang.String str)
          Returns true if the string is a Java reserved word.
static java.lang.String pluralize(java.lang.String str)
          Turn a singular noun into a plural noun.
static char reverseCharAt(java.lang.String str, int index)
          Just like String.charAt(), but it counts from the end of the string.
static java.lang.String[] splitString(java.lang.String str, char separator, boolean trim, boolean allowEmpty, boolean nestParens, boolean stringMode)
          Split a String into an array of Strings, using a given separator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MacroUtil

public MacroUtil()
Method Detail

capitalize

public static java.lang.String capitalize(java.lang.String str)
Capitalize the first character in a String.

pluralize

public static java.lang.String pluralize(java.lang.String str)
Turn a singular noun into a plural noun. This works for most English words, but not all of them. The algorithm is simple: if the word ends in 's', "es" is stuck on the end. Otherwise, "s" is stuck on. So "dog" becomes "dogs", and "pass" becomes "passes".

splitString

public static java.lang.String[] splitString(java.lang.String str,
                                             char separator,
                                             boolean trim,
                                             boolean allowEmpty,
                                             boolean nestParens,
                                             boolean stringMode)
Split a String into an array of Strings, using a given separator.

Examples:

 String str = "a(x ,y)b \"c,d\" ,"
 splitString(str, ',', true, true, true, true)  == {"a(x ,y)b \"c,d\"", ""}
 splitString(str, ',', false, true, true, true) == {"a(x ,y)b \"c,d\" ", ""}
 splitString(str, ',', true, false, true, true) == {"a(x ,y)b \"c,d\""}
 splitString(str, ',', true, true, false, true) == {"a(x", "y)b \"c,d\"", ""}
 splitString(str, ',', true, true, true, false) == {"a(x ,y)b \"c", "d\"", ""}
 
Parameters:
trim - if true, trims each element in the result.
allowEmpty - if false, empty strings are not included in result.
nestParens - if true, separators inside parentheses are ignored.
stringMode - if true, separators inside quotes are ignored.

findMatchingEndParen

public static int findMatchingEndParen(java.lang.String str,
                                       int startIndex)
Searches through a string to find a matching ')' character. Returns -1 if no matching ')' exists. For example, if str is "a(b())+c(", and index is 1, then the result is 5. If index is 3, the result is 4. If index is 8, the result is -1. If the character at the given startIndex is not a '(' character (e.g. 0,2,4-7), the result is -1.

escapify

public static java.lang.String escapify(java.lang.String str)
Replaces special characters like newlines, tabs, quotes, and backslashes into escaped character sequences (e.g. "\n", "\t", "\\"), and turns unportable characters (<32 or >127) into unicode escapes (e.g. "?").

isJavaReservedWord

public static boolean isJavaReservedWord(java.lang.String str)
Returns true if the string is a Java reserved word. For example, "this", "if", "static", or "package".

reverseCharAt

public static char reverseCharAt(java.lang.String str,
                                 int index)
Just like String.charAt(), but it counts from the end of the string. reverseCharAt("foobar", 0) returns 'r'.

clip

public static java.lang.String clip(java.lang.String str,
                                    int front,
                                    int back)
Removes characters from both ends of a string. clip("foobar", 1, 2) would return "oob".