/** * A class that parses input strings of the form: * ,| * Where all spaces are ignored. * This parser assumes that there are no ',' or '|' characters * in the last name, first name, or ID #. * @author bederson */ public class ParserTwo { // These hold the data as they are parsed private StringBuffer lastName, firstName, studentId; // These are true when the relavant word has been parsed private boolean firstNameComplete, lastNameComplete; private char charValue; // The current character being analyzed /** * Resets the state of the parser to the initial state. * This is an internal method and is used internally in support * of the parsers. */ private void reset() { firstNameComplete = false; lastNameComplete = false; lastName = new StringBuffer("");; firstName = new StringBuffer(""); studentId = new StringBuffer(""); } /** * Parse the input string. When it is complete, the class * instance variables holding first name, last name and ID # will * be set, and can be accessed through the appropriate getter methods. * @see getFirstName() * @see getLastName() * @see getStudentID() * @param data The input string to parse */ void parseInput(String theData) { // This version is implemented with a switch statement reset(); // Crucial to reset parser before start, or there will // be problems if a second string is parsed StringBuffer data = new StringBuffer(theData); for (int i=0; i