1 21 22 package net.percederberg.grammatica.parser.re; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 27 import net.percederberg.grammatica.parser.LookAheadReader; 28 29 36 class StringElement extends Element { 37 38 41 private String value = null; 42 43 48 public StringElement(char c) { 49 this(String.valueOf(c)); 50 } 51 52 57 public StringElement(String str) { 58 value = str; 59 } 60 61 66 public String getString() { 67 return value; 68 } 69 70 75 public Object clone() { 76 return this; 77 } 78 79 96 public int match(Matcher m, LookAheadReader input, int start, int skip) 97 throws IOException { 98 99 int c; 100 101 if (skip != 0) { 102 return -1; 103 } 104 for (int i = 0; i < value.length(); i++) { 105 c = input.peek(start + i); 106 if (c < 0) { 107 m.setReadEndOfString(); 108 return -1; 109 } 110 if (m.isCaseInsensitive()) { 111 c = Character.toLowerCase((char) c); 112 } 113 if (c != value.charAt(i)) { 114 return -1; 115 } 116 } 117 return value.length(); 118 } 119 120 126 public void printTo(PrintWriter output, String indent) { 127 output.println(indent + "'" + value + "'"); 128 } 129 130 } 131 | Popular Tags |