/** * Return a new string from last mark until current cursor position. * * @return */ public String substringFromLastMark() { return substringFromLastMark( 0 ); }
private void appendEqualsMatcherForBufferedTextUntilNow( final StringCursor cursor ) { final String token = cursor.substringFromLastMark( 1 ); if ( !token.isEmpty() ) patternMatchers.add( new EqualsMatcher( token ) ); }
@Override public boolean matches( final StringCursor string , final Map<String, String> foundParameters ) { final boolean existsNextChar = string.shiftCursorToNextChar( nextChar ); if ( existsNextChar ) foundParameters.put( placeholder, string.substringFromLastMark( GAP_BETWEEN_END_OF_PLACEHOLDER_AND_NEXT_CHAR ) ); return existsNextChar; }
@Override public boolean matches( final StringCursor string , final Map<String, String> foundParameters ) { string.mark(); string.end(); foundParameters.put(placeholder, string.substringFromLastMark()); return true; }
private UsernameAndPasswordCredential convertToCredential( StringCursor decodedCredentials ) { decodedCredentials.shiftCursorToNextChar( COLON ); final String username = decodedCredentials.substringFromLastMark(1); decodedCredentials.mark(); decodedCredentials.end(); final String password = decodedCredentials.substringFromLastMark(); return new UsernameAndPasswordCredential( username, password ); }
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 ) ); } }
private String getAuthString( StringCursor headerValue ) { headerValue.cursorAt( PREFIX_LENGTH ); headerValue.mark(); headerValue.end(); return headerValue.substringFromLastMark(); }
static Tuple<String, String> fixContentType( String contentType, String defaultEncoding ){ if ( contentType == null ) return Tuple.empty(); final StringCursor cursor = new StringCursor(contentType); if ( cursor.shiftCursorToNextChar( ';' ) ) { contentType = cursor.substringFromLastMark( 1 ); cursor.mark(1); cursor.end(); defaultEncoding = cursor.substringFromLastMark(); } return Tuple.of( contentType, defaultEncoding ); } }
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() ); }