1 21 22 package org.armedbear.j; 23 24 public final class StringPosition implements Constants 25 { 26 private final String text; 27 private final int length; 28 29 private int offset; 30 31 public StringPosition(String s) 32 { 33 text = s; 34 length = s.length(); 35 } 36 37 public StringPosition(String s, int offset) 38 { 39 this(s); 40 this.offset = offset; 41 } 42 43 public final String getText() 44 { 45 return text; 46 } 47 48 public final int getOffset() 49 { 50 return offset; 51 } 52 53 public final void setOffset(int n) 54 { 55 Debug.assertTrue(n <= length); 56 this.offset = n; 57 } 58 59 public final char getChar() 60 { 61 Debug.assertTrue(offset <= length); 62 if (offset == length) 63 return EOL; 64 return text.charAt(offset); 65 } 66 67 public final boolean lookingAt(String s) 68 { 69 return s.regionMatches(0, text, offset, s.length()); 70 } 71 72 public final boolean atEnd() 73 { 74 return offset >= length; 75 } 76 77 public final boolean charIsWhitespace() 78 { 79 return Character.isWhitespace(text.charAt(offset)); 80 } 81 82 public final boolean next() 83 { 84 if (offset < length) { 85 ++offset; 86 return true; 87 } 88 return false; 89 } 90 91 public final void skip(int count) 92 { 93 offset += count; 94 } 95 } 96 | Popular Tags |