Example #1
0
 /**
  * Skips whitespace characters and then reads one "word" from input. Any additional characters on
  * the current line of input are retained, and will be read by the next input operation. A word is
  * defined as a sequence of non-whitespace characters (not just letters!). When using standard IO,
  * this will not produce an error. In other cases, an IllegalArgumentException will be thrown if
  * an end-of-file is encountered.
  */
 public static String getWord() {
   skipWhitespace();
   StringBuffer str = new StringBuffer(50);
   char ch = lookChar();
   while (ch == EOF || !Character.isWhitespace(ch)) {
     str.append(readChar());
     ch = lookChar();
   }
   return str.toString();
 }
Example #2
0
 private static String readIntegerString() { // read chars from input
   // following syntax of integers
   skipWhitespace();
   if (lookChar() == EOF) return null;
   if (integerMatcher == null) integerMatcher = integerRegex.matcher(buffer);
   integerMatcher.region(pos, buffer.length());
   if (integerMatcher.lookingAt()) {
     String str = integerMatcher.group();
     pos = integerMatcher.end();
     return str;
   } else return null;
 }
Example #3
0
 private static String readRealString() { // read chars from input
   // following syntax of real
   // numbers
   skipWhitespace();
   if (lookChar() == EOF) return null;
   if (floatMatcher == null) floatMatcher = floatRegex.matcher(buffer);
   floatMatcher.region(pos, buffer.length());
   if (floatMatcher.lookingAt()) {
     String str = floatMatcher.group();
     pos = floatMatcher.end();
     return str;
   } else return null;
 }
Example #4
0
 /**
  * Skips whitespace characters and then reads a single non-whitespace character from input. Any
  * additional characters on the current line of input are retained, and will be read by the next
  * input operation. When using standard IO, this will not produce an error. In other cases, an
  * IllegalArgumentException will be thrown if an end-of-file is encountered.
  */
 public static char getChar() {
   skipWhitespace();
   return readChar();
 }