cvs -q diff -u -N LexerInput.java
Index: LexerInput.java
===================================================================
RCS file: /cvs/lexer/src/org/netbeans/spi/lexer/LexerInput.java,v
retrieving revision 1.2
diff -u -r1.2 LexerInput.java
--- LexerInput.java 4 Oct 2006 17:03:25 -0000 1.2
+++ LexerInput.java 3 Nov 2006 17:11:28 -0000
@@ -19,6 +19,7 @@
package org.netbeans.spi.lexer;
+import java.lang.Character;
import org.netbeans.lib.editor.util.AbstractCharSequence;
import org.netbeans.lib.lexer.CharProvider;
import org.netbeans.lib.lexer.IntegerCache;
@@ -60,6 +61,13 @@
public static final int EOF = -1;
/**
+ * Indicates successful match in methods
+ * {@link #match(String)} and
+ * {@link #matchIgnoreCase(String)}.
+ */
+ public static final int MATCH = -2;
+
+ /**
* Character provider to which this lexer input delegates
* its operation.
*/
@@ -273,6 +281,47 @@
backup(1);
return false;
}
+ }
+
+ /**
+ * Check whether the next characters in the input match the given text.
+ *
+ * The method reads the input characters and compares them to the given
+ * text. If all the charcters match the text the method returns {@link #MATCH}.
+ *
+ * Otherwise it returns a character that did not
+ * match the corresponding one in the text. The input stays positioned
+ * after that returned character.
+ *
+ * The {@link #readLength()} can be called before and after this method
+ * to find out how many characters this method consumed.
+ *
+ * @param text non-null text to be matched.
+ * @return {# MATCH} if the text was matched successfully or the character
+ * that did not matched the corresponding one in the text
+ * (it may be #EOF as well).
+ */
+ public int match(String text) {
+ for (int i = 0; i < text.length(); i++) {
+ int c = read();
+ if (c != text.charAt(i))
+ return c;
+ }
+ return MATCH;
+ }
+
+ /**
+ * Check whether the next characters in the input match the given lower case text
+ * in a case-insensitive way.
+ * @see #match(String)
+ */
+ public int matchIgnoreCase(String lowerCaseText) {
+ for (int i = 0; i < lowerCaseText.length(); i++) {
+ int c = read();
+ if (c != lowerCaseText.charAt(i) && c != Character.toUpperCase(lowerCaseText.charAt(i)))
+ return c;
+ }
+ return MATCH;
}
/**