public class

Chset

extends Parser<T>
implements Cloneable
java.lang.Object
   ↳ com.google.gdata.util.parser.Parser<T>
     ↳ com.google.gdata.util.parser.Chset

Class Overview

The Chset (character set) parser matches the current character in the parse buffer against an arbitrary character set. The character set is represented as a sorted array of ranges for which a match should be successful. Matching takes O(log nranges) time. There are predefined character sets for matching any character (ANYCHAR), no characters (NOTHING) and some standard 7-bit ASCII ranges (ALNUM, ALPHA, DIGIT, XDIGIT, LOWER, UPPER, WHITESPACE), and ASCII. Note that the character set parser only matches a single character of the parse buffer. The Sequence or Repeat parsers need to be used to match more than one character. The following matches vowels and digits: Parser p = new Chset("uoiea0-9"); p.parse("a") -> matches "a" p.parse("3") -> matches "3" p.parse("b") -> no match

See Also

Summary

Constants
char MAX_ASCII_CHAR
char MAX_CHAR
char MIN_CHAR
[Expand]
Inherited Constants
From class com.google.gdata.util.parser.Parser
Fields
public static final Chset ALNUM
public static final Chset ALPHA
public static final Chset ANYCHAR
public static final Chset ASCII
public static final Chset DIGIT
public static final Chset LOWER
public static final Chset NOTHING
public static final Chset UPPER
public static final Chset WHITESPACE
public static final Chset XDIGIT
private BitSet asciiSet A secondary representation for ASCII members of the character set.
private ArrayList<Chset.Range> ranges
Public Constructors
Chset()
Class constructor for an empty character set.
Chset(char ch)
Class constructor for a character literal.
Chset(char min, char max)
Class constructor for a single character range.
Chset(String spec)
Class constructor that initializes a Chset from a string specification.
Public Methods
Object clone()
Returns a clone character set of this.
static Chset difference(Chset left, Chset right)
Creates a new character set which matches a character if that character matches the left character set but does not match the right character set.
static Chset intersection(Chset left, Chset right)
Creates a new character set which matches a character if that character matches both the left and right character sets.
static Chset not(Chset subject)
Creates a new character set which matches a character if that character does not match the subject character set.
int parse(char[] buf, int start, int end, Object data)
Matches buf[start] against the character set.
boolean test(char ch)
Tests to see if a single character matches the character set.
String toString()
static Chset union(Chset left, Chset right)
Creates a new character set which matches a character if that character matches either the left or right character sets.
static Chset xor(Chset left, Chset right)
Creates a new character set which matches a character if that character matches the left character set or the right character set, but not both.
Protected Methods
void clear(char min, char max)
void set(char min, char max)
int size()
Returns the size of the range array.
boolean testRanges(char ch)
Tests to see if a single character matches the character set, but only looks at the ranges representation.
[Expand]
Inherited Methods
From class com.google.gdata.util.parser.Parser
From class java.lang.Object

Constants

private static final char MAX_ASCII_CHAR

Constant Value: 127 (0x0000007f)

protected static final char MAX_CHAR

Constant Value: 65535 (0x0000ffff)

protected static final char MIN_CHAR

Constant Value: 0 (0x00000000)

Fields

public static final Chset ALNUM

public static final Chset ALPHA

public static final Chset ANYCHAR

public static final Chset ASCII

public static final Chset DIGIT

public static final Chset LOWER

public static final Chset NOTHING

public static final Chset UPPER

public static final Chset WHITESPACE

public static final Chset XDIGIT

private BitSet asciiSet

A secondary representation for ASCII members of the character set. Maintaining this bitmap allows us to check ASCII characters for set membership quickly.

private ArrayList<Chset.Range> ranges

Public Constructors

public Chset ()

Class constructor for an empty character set.

public Chset (char ch)

Class constructor for a character literal.

Parameters
ch The character literal for this character set to match against.

public Chset (char min, char max)

Class constructor for a single character range. The range is inclusive: all character including min and max match.

Parameters
min The beginning of the character range.
max The end of the character range.

public Chset (String spec)

Class constructor that initializes a Chset from a string specification.

Parameters
spec The string specification to intialize the Chset from.

Public Methods

public Object clone ()

Returns a clone character set of this.

public static Chset difference (Chset left, Chset right)

Creates a new character set which matches a character if that character matches the left character set but does not match the right character set. left - right

Parameters
left The left source character set.
right The right source character set.

public static Chset intersection (Chset left, Chset right)

Creates a new character set which matches a character if that character matches both the left and right character sets. left & right --> left - ~right

Parameters
left The left source character set.
right The right source character set.

public static Chset not (Chset subject)

Creates a new character set which matches a character if that character does not match the subject character set. This operation is implemented by taking the difference of the ANYCHAR character set and the subject character set. ~subject --> anychar - subject

Parameters
subject The source character set.

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

Matches buf[start] against the character set.

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

public boolean test (char ch)

Tests to see if a single character matches the character set.

Parameters
ch The character to test.

public String toString ()

public static Chset union (Chset left, Chset right)

Creates a new character set which matches a character if that character matches either the left or right character sets. left | right

Parameters
left The left source character set.
right The right source character set.

public static Chset xor (Chset left, Chset right)

Creates a new character set which matches a character if that character matches the left character set or the right character set, but not both. left ^ right --> (left - right) | (right - left)

Parameters
left The left source character set.
right The right source character set.

Protected Methods

protected void clear (char min, char max)

Parameters
min
max

protected void set (char min, char max)

Parameters
min
max
See Also

protected int size ()

Returns the size of the range array.

protected boolean testRanges (char ch)

Tests to see if a single character matches the character set, but only looks at the ranges representation.

Parameters
ch The character to test.