public class

Action

extends Parser<T>
java.lang.Object
   ↳ com.google.gdata.util.parser.Parser<T>
     ↳ com.google.gdata.util.parser.Action<T, U extends T>

Class Overview

Actions are fired when their subject parser matches. The Callback class is passed the matching portion of the parse text. Note that the Action parser wraps around its subject. It will parse exactly the same text that its subject parser parses. Parser p = Chset.ALPHA.plus().action(new Callback() { public void handle(char[] buf, int start, int end, Object data) { StringBuffer str = (StringBuffer) data; str.delete(0, str.length()); str.append(buf, start, end - start); } }); StringBuffer buf = new StringBuffer(); p.parse("a") -> matches "a", buf == "a" p.parse("abcde") -> matches "abcde", buf == "abcde" p.parse("a0") -> matches "a", buf == "a" p.parse("0") -> no match, buf unchanged

See Also

Summary

[Expand]
Inherited Constants
From class com.google.gdata.util.parser.Parser
Fields
private Callback<U extends T> callback
private Parser<T> subject
Public Constructors
Action(Parser<T> subject, Callback<U> callback)
Class constructor.
Public Methods
int parse(char[] buf, int start, int end, U data)
Matches the subject parser against the current state of the buffer being parsed.
[Expand]
Inherited Methods
From class com.google.gdata.util.parser.Parser
From class java.lang.Object

Fields

private Callback<U extends T> callback

private Parser<T> subject

Public Constructors

public Action (Parser<T> subject, Callback<U> callback)

Class constructor.

Parameters
subject The Parser that this action is wrapping around.
callback The Callback that will be invoked if the subject parser returns a result different than NO_MATCH.

Public Methods

public int parse (char[] buf, int start, int end, U data)

Matches the subject parser against the current state of the buffer being parsed. If the subject parser hits (returns a result other than NO_MATCH), callback.handle will be invoked and passed the matching region of the parse buffer.

Parameters
buf The character array to match against.
start The start offset of data within the character array to match against.
end The end offset of data within the character array to match against.
data User defined object that is passed to Callback.handle when an Action fires.
See Also