FileDocCategorySizeDatePackage
PatternScanner.javaAPI DocAndroid 5.1 API3404Thu Mar 12 22:22:30 GMT 2015android.filterfw.io

PatternScanner

public class PatternScanner extends Object
hide

Fields Summary
private String
mInput
private Pattern
mIgnorePattern
private int
mOffset
private int
mLineNo
private int
mStartOfLine
Constructors Summary
public PatternScanner(String input)


       
        mInput = input;
    
public PatternScanner(String input, Pattern ignorePattern)

        mInput = input;
        mIgnorePattern = ignorePattern;
        skip(mIgnorePattern);
    
Methods Summary
public booleanatEnd()

        return mOffset >= mInput.length();
    
public java.lang.Stringeat(java.util.regex.Pattern pattern, java.lang.String tokenName)

        String result = tryEat(pattern);
        if (result == null) {
            throw new RuntimeException(unexpectedTokenMessage(tokenName));
        }
        return result;
    
public intlineNo()

        return mLineNo;
    
public booleanpeek(java.util.regex.Pattern pattern)

        // Skip ignore pattern
        if (mIgnorePattern != null) {
            skip(mIgnorePattern);
        }

        // Create the matcher
        Matcher matcher = pattern.matcher(mInput);
        matcher.region(mOffset, mInput.length());

        // Attempt to match
        return matcher.lookingAt();
    
public voidskip(java.util.regex.Pattern pattern)

        Matcher matcher = pattern.matcher(mInput);
        matcher.region(mOffset, mInput.length());
        if (matcher.lookingAt()) {
            updateLineCount(mOffset, matcher.end());
            mOffset = matcher.end();
        }
    
public java.lang.StringtryEat(java.util.regex.Pattern pattern)

        // Skip ignore pattern
        if (mIgnorePattern != null) {
            skip(mIgnorePattern);
        }

        // Create the matcher
        Matcher matcher = pattern.matcher(mInput);
        matcher.region(mOffset, mInput.length());

        // Attempt to match
        String result = null;
        if (matcher.lookingAt()) {
            updateLineCount(mOffset, matcher.end());
            mOffset = matcher.end();
            result = mInput.substring(matcher.start(), matcher.end());
        }

        // Skip ignore pattern
        if (result != null && mIgnorePattern != null) {
            skip(mIgnorePattern);
        }

        return result;
    
public java.lang.StringunexpectedTokenMessage(java.lang.String tokenName)

        String line = mInput.substring(mStartOfLine, mOffset);
        return "Unexpected token on line " + (mLineNo + 1) + " after '" + line + "' <- Expected " +
                tokenName + "!";
    
public voidupdateLineCount(int start, int end)

        for (int i = start; i < end; ++i) {
            if (mInput.charAt(i) == '\n") {
                ++mLineNo;
                mStartOfLine = i + 1;
            }
        }