All Packages Class Hierarchy This Package Previous Next Index
Class mesquite.lib.ParseUtil
java.lang.Object
|
+----mesquite.lib.StringUtil
|
+----mesquite.lib.ParseUtil
- public class ParseUtil
- extends mesquite.lib.StringUtil
A set of string parsing methods. Should be renamed StringParser or NEXUSParser.
-
ParseUtil()
-
-
charOnDeck(String, MesquiteInteger, int)
-
-
darkBeginsWithIgnoreCase(String, String)
- returns token from line starting at startChar; keeps track of pending square bracket closure, etc.*
public static String getToken(String line, MesquiteInteger startChar, MesquiteInteger pendingBrackets, StringBuffer comment) {
if (line==null)
return null;
else if (line.equals(""))
return "";
if (startChar.getValue() >= line.length())
return null;
StringBuffer temp = new StringBuffer(100); //better to pass from outside
char c;
try {
boolean continu = true;
while (whitespace(c=getNextChar(line, startChar, pendingBrackets, comment), null)) //skipping whitespace in front
;
if (punctuation(c, null)) {
continu = false;
if (c == defaultQuote) {
temp.setLength(0);
temp.append(getQuoted(line, startChar));
}
else if (c == '-') {
char cod = charOnDeck(line, startChar, 1);
char cod2 = charOnDeck(line, startChar, 2);
if (("0123456789".indexOf(cod)>=0)||(cod=='.' && ("0123456789".indexOf(cod2)>=0))) {
temp.append(c);
c=getNextChar(line, startChar, pendingBrackets, comment);
continu = true;
}
else {
temp.append(c);
}
}
else
temp.append(c);
}
if (continu) {
while ((!whitespace(c, null) && !punctuation(c, null)) && c !=0) {
if (c=='_')
c = ' ';
temp.append(c);
c=getNextChar(line, startChar, pendingBrackets, comment);
}
if (punctuation(c, null)) {
startChar.decrement();
}
}
}
catch (StringIndexOutOfBoundsException e) {
System.out.println("string bounds exceeded 1");
startChar.setValue(line.length());
}
return temp.toString();
}
/*.................................................................................................................
-
firstDarkChar(String)
-
-
getFirstToken(String, MesquiteInteger)
- returns first token from string; sets pos to end of token; excluding square bracket comments
-
getRemaining(String, MesquiteInteger)
- returns remainder of line starting at startChar; including square bracket comments
-
getSubcommands(String, MesquiteInteger)
-
-
getToken(String, MesquiteInteger)
- returns token from line starting at startChar; excluding square bracket comments
-
getToken(String, MesquiteInteger, String, String)
- returns token from line starting at startChar; excluding square bracket comments
-
getTokenNumber(String, MesquiteInteger, int)
-
-
getTokens(String, MesquiteInteger, int, int)
-
-
nextDarkChar(String, MesquiteInteger)
-
-
skipComment(String, MesquiteInteger)
-
-
skipToDarkspace(String, MesquiteInteger)
-
ParseUtil
public ParseUtil()
getRemaining
public static java.lang.String getRemaining(java.lang.String line,
mesquite.lib.MesquiteInteger startChar)
- returns remainder of line starting at startChar; including square bracket comments
getFirstToken
public static java.lang.String getFirstToken(java.lang.String line,
mesquite.lib.MesquiteInteger pos)
- returns first token from string; sets pos to end of token; excluding square bracket comments
getToken
public static java.lang.String getToken(java.lang.String line,
mesquite.lib.MesquiteInteger startChar)
- returns token from line starting at startChar; excluding square bracket comments
charOnDeck
public static char charOnDeck(java.lang.String line,
mesquite.lib.MesquiteInteger pos,
int ahead)
getToken
public static java.lang.String getToken(java.lang.String line,
mesquite.lib.MesquiteInteger startChar,
java.lang.String whitespaceString,
java.lang.String punctuationString)
- returns token from line starting at startChar; excluding square bracket comments
darkBeginsWithIgnoreCase
public static boolean darkBeginsWithIgnoreCase(java.lang.String s,
java.lang.String find)
- returns token from line starting at startChar; keeps track of pending square bracket closure, etc.*
public static String getToken(String line, MesquiteInteger startChar, MesquiteInteger pendingBrackets, StringBuffer comment) {
if (line==null)
return null;
else if (line.equals(""))
return "";
if (startChar.getValue() >= line.length())
return null;
StringBuffer temp = new StringBuffer(100); //better to pass from outside
char c;
try {
boolean continu = true;
while (whitespace(c=getNextChar(line, startChar, pendingBrackets, comment), null)) //skipping whitespace in front
;
if (punctuation(c, null)) {
continu = false;
if (c == defaultQuote) {
temp.setLength(0);
temp.append(getQuoted(line, startChar));
}
else if (c == '-') {
char cod = charOnDeck(line, startChar, 1);
char cod2 = charOnDeck(line, startChar, 2);
if (("0123456789".indexOf(cod)>=0)||(cod=='.' && ("0123456789".indexOf(cod2)>=0))) {
temp.append(c);
c=getNextChar(line, startChar, pendingBrackets, comment);
continu = true;
}
else {
temp.append(c);
}
}
else
temp.append(c);
}
if (continu) {
while ((!whitespace(c, null) && !punctuation(c, null)) && c !=0) {
if (c=='_')
c = ' ';
temp.append(c);
c=getNextChar(line, startChar, pendingBrackets, comment);
}
if (punctuation(c, null)) {
startChar.decrement();
}
}
}
catch (StringIndexOutOfBoundsException e) {
System.out.println("string bounds exceeded 1");
startChar.setValue(line.length());
}
return temp.toString();
}
/*.................................................................................................................
getTokenNumber
public static java.lang.String getTokenNumber(java.lang.String s,
mesquite.lib.MesquiteInteger startChar,
int tokenNumber)
getTokens
public static java.lang.String getTokens(java.lang.String s,
mesquite.lib.MesquiteInteger startChar,
int first,
int last)
getSubcommands
public static java.lang.String[][] getSubcommands(java.lang.String s,
mesquite.lib.MesquiteInteger startChar)
skipComment
public static void skipComment(java.lang.String line,
mesquite.lib.MesquiteInteger startChar)
skipToDarkspace
public static void skipToDarkspace(java.lang.String line,
mesquite.lib.MesquiteInteger startChar)
nextDarkChar
public static char nextDarkChar(java.lang.String line,
mesquite.lib.MesquiteInteger startChar)
firstDarkChar
public static char firstDarkChar(java.lang.String line)
All Packages Class Hierarchy This Package Previous Next Index