private void appendMatcherForAsterisk( final StringCursor cursor ) { if ( cursor.hasNext() ) patternMatchers.add( new AnyStringNextValidCharMatcher( cursor.next() ) ); else patternMatchers.add( new AnyStringUntilEndMatcher() ); }
private void appendPlaceHolderMatcher( final StringCursor cursor ) { if ( !cursor.shiftCursorToNextChar( '}' ) ) throw new RuntimeException( "Invalid expression!" ); final String placeholder = cursor.substringFromLastMark( 1 ); if ( cursor.hasNext() ) { final char nextChar = cursor.next(); patternMatchers.add( new PlaceHolderMatcher( placeholder, nextChar ) ); } else patternMatchers.add( new PlaceHolderForAnyStringUntilEndMatcher( placeholder, doNotIgnoreSlashes ) ); } }
@Override public boolean matches( final StringCursor string , final Map<String, String> foundParameters ) { val pattern = new StringCursor( patternChars ); final char firstPatternChar = pattern.next(); return string.shiftCursorToNextChar( firstPatternChar ) && pattern.matches( string ); }
/** * Shift the cursor to the next occurrence of {@code ch} and returns * {@code true}. Otherwise, it will keep the cursor at same position, but * will return {@code false}. * * @param ch * @return */ public boolean shiftCursorToNextChar( final char ch ) { mark(); while ( hasNext() ) if ( next() == ch ) return true; flip(); return false; }
public void compile( final String string ) { final StringCursor cursor = new StringCursor( string ); while ( cursor.hasNext() ) compile( cursor, cursor.next() ); if ( remainsUnparsedDataInCursor ) patternMatchers.add( new EqualsMatcher( cursor.substringFromLastMark() ) ); patternMatchers.add( new EndOfStringMatcher() ); }