Top Description Inners Fields Constructors Methods
com.ibm.icu.impl

public Class RuleCharacterIterator

extends Object
Class Inheritance
Imports
java.text.ParsePosition, com.ibm.icu.text.SymbolTable, .UTF16

An iterator that returns 32-bit code points. This class is deliberately not related to any of the JDK or ICU4J character iterator classes in order to minimize complexity.
Author
Alan Liu
Since
ICU 2.8

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private String
buf

Current variable expansion, or null if none.

private int
bufPos

Position within buf[].

public static final int
DONE

Value returned when there are no more characters to iterate.

private boolean
isEscaped

Flag indicating whether the last character was parsed from an escape.

public static final int
PARSE_ESCAPES

Bitmask option to enable parsing of escape sequences.

public static final int
PARSE_VARIABLES

Bitmask option to enable parsing of variable names.

private ParsePosition
pos

Position of iterator.

public static final int
SKIP_WHITESPACE

Bitmask option to enable skipping of whitespace.

private SymbolTable
sym

Symbol table used to parse and dereference variables.

private String
text

Text being iterated.

Constructor Summary

AccessConstructor and Description
public
RuleCharacterIterator(String
the text to be iterated
text
,
SymbolTable
the symbol table, or null if there is none. If sym is null, then variables will not be dereferenced, even if the PARSE_VARIABLES option is set.
sym
,
ParsePosition
upon input, the index of the next character to return. If a variable has been dereferenced, then pos will not increment as characters of the variable value are iterated.
pos
)

Constructs an iterator over the given text, starting at the given position.

Method Summary

Modifier and TypeMethod and Description
private void
_advance(int
the number of 16-bit code units to advance past
count
)

Advances the position by the given amount.

private int

Returns:

the current 32-bit code point
_current
()

Returns the current 32-bit code point without parsing escapes, parsing variables, or skipping whitespace.

public boolean
atEnd()

Returns true if this iterator has no more characters to return.

public String

Returns:

a string containing the characters to be returned by future calls to next()
getCurrentBuffer
()

Returns a string containing the remainder of the characters to be returned by this iterator, without any option processing.

public int
public RuleCharacterIterator.Position

Returns:

a position object which may be passed to setPos(), either p, or if p == null, a newly-allocated object
getPos
(RuleCharacterIterator.Position
a position object previously returned by getPos(), or null. If not null, it will be updated and returned. If null, a new position object will be allocated and returned.
p
)

Returns an object which, when later passed to setPos(), will restore this iterator's position.

public boolean
inVariable()

Returns true if this iterator is currently within a variable expansion.

public boolean
isEscaped()

Returns true if the last character returned by next() was escaped.

public void
jumpahead(int
the number of 16-bit code units to jump over
count
)

Advances the position by the given number of 16-bit code units.

public int

Returns:

the current 32-bit code point, or DONE
next
(int
one or more of the following options, bitwise-OR-ed together: PARSE_VARIABLES, PARSE_ESCAPES, SKIP_WHITESPACE.
options
)

Returns the next character using the given options, or DONE if there are no more characters, and advance the position to the next character.

public void
setPos(RuleCharacterIterator.Position
a position object previously returned by getPos()
p
)

Restores this iterator to the position it had when getPos() returned the given object.

public void
skipIgnored(int
one or more of the following options, bitwise-OR-ed together: PARSE_VARIABLES, PARSE_ESCAPES, SKIP_WHITESPACE.
options
)

Skips ahead past any ignored characters, as indicated by the given options.

public String

Returns:

a string representation of this object
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this object, consisting of the characters being iterated, with a '|' marking the current position.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bufback to summary
private String buf

Current variable expansion, or null if none.

bufPosback to summary
private int bufPos

Position within buf[]. Meaningless if buf == null.

DONEback to summary
public static final int DONE

Value returned when there are no more characters to iterate.

isEscapedback to summary
private boolean isEscaped

Flag indicating whether the last character was parsed from an escape.

PARSE_ESCAPESback to summary
public static final int PARSE_ESCAPES

Bitmask option to enable parsing of escape sequences. If (options & PARSE_ESCAPES) != 0, then an embedded escape sequence will be expanded to its value. Escapes are parsed using Utility.unescapeAndLengthAt().

PARSE_VARIABLESback to summary
public static final int PARSE_VARIABLES

Bitmask option to enable parsing of variable names. If (options & PARSE_VARIABLES) != 0, then an embedded variable will be expanded to its value. Variables are parsed using the SymbolTable API.

posback to summary
private ParsePosition pos

Position of iterator.

SKIP_WHITESPACEback to summary
public static final int SKIP_WHITESPACE

Bitmask option to enable skipping of whitespace. If (options & SKIP_WHITESPACE) != 0, then Unicode Pattern_White_Space characters will be silently skipped, as if they were not present in the input.

symback to summary
private SymbolTable sym

Symbol table used to parse and dereference variables. May be null.

textback to summary
private String text

Text being iterated.

Constructor Detail

RuleCharacterIteratorback to summary
public RuleCharacterIterator(String text, SymbolTable sym, ParsePosition pos)

Constructs an iterator over the given text, starting at the given position.

Parameters
text:String

the text to be iterated

sym:SymbolTable

the symbol table, or null if there is none. If sym is null, then variables will not be dereferenced, even if the PARSE_VARIABLES option is set.

pos:ParsePosition

upon input, the index of the next character to return. If a variable has been dereferenced, then pos will not increment as characters of the variable value are iterated.

Method Detail

_advanceback to summary
private void _advance(int count)

Advances the position by the given amount.

Parameters
count:int

the number of 16-bit code units to advance past

_currentback to summary
private int _current()

Returns the current 32-bit code point without parsing escapes, parsing variables, or skipping whitespace.

Returns:int

the current 32-bit code point

atEndback to summary
public boolean atEnd()

Returns true if this iterator has no more characters to return.

getCurrentBufferback to summary
public String getCurrentBuffer()

Returns a string containing the remainder of the characters to be returned by this iterator, without any option processing. If the iterator is currently within a variable expansion, this will only extend to the end of the variable expansion. This method, together with getCurrentBufferPos() (which replace the former lookahead()), is provided so that iterators may interoperate with string-based APIs. The typical sequence of calls is to call skipIgnored(), then call these methods, then parse that substring, then call jumpahead() to resynchronize the iterator.

Returns:String

a string containing the characters to be returned by future calls to next()

getCurrentBufferPosback to summary
public int getCurrentBufferPos()
getPosback to summary
public RuleCharacterIterator.Position getPos(RuleCharacterIterator.Position p)

Returns an object which, when later passed to setPos(), will restore this iterator's position. Usage idiom: RuleCharacterIterator iterator = ...; Position pos = iterator.getPos(null); // allocate position object for (;;) { pos = iterator.getPos(pos); // reuse position object int c = iterator.next(...); ... } iterator.setPos(pos);

Parameters
p:RuleCharacterIterator.Position

a position object previously returned by getPos(), or null. If not null, it will be updated and returned. If null, a new position object will be allocated and returned.

Returns:RuleCharacterIterator.Position

a position object which may be passed to setPos(), either p, or if p == null, a newly-allocated object

inVariableback to summary
public boolean inVariable()

Returns true if this iterator is currently within a variable expansion.

isEscapedback to summary
public boolean isEscaped()

Returns true if the last character returned by next() was escaped. This will only be the case if the option passed in to next() included PARSE_ESCAPED and the next character was an escape sequence.

jumpaheadback to summary
public void jumpahead(int count)

Advances the position by the given number of 16-bit code units. This is useful in conjunction with getCurrentBuffer()+getCurrentBufferPos() (formerly lookahead()).

Parameters
count:int

the number of 16-bit code units to jump over

nextback to summary
public int next(int options)

Returns the next character using the given options, or DONE if there are no more characters, and advance the position to the next character.

Parameters
options:int

one or more of the following options, bitwise-OR-ed together: PARSE_VARIABLES, PARSE_ESCAPES, SKIP_WHITESPACE.

Returns:int

the current 32-bit code point, or DONE

setPosback to summary
public void setPos(RuleCharacterIterator.Position p)

Restores this iterator to the position it had when getPos() returned the given object.

Parameters
p:RuleCharacterIterator.Position

a position object previously returned by getPos()

skipIgnoredback to summary
public void skipIgnored(int options)

Skips ahead past any ignored characters, as indicated by the given options. This is useful in conjunction with the lookahead() method. Currently, this only has an effect for SKIP_WHITESPACE.

Parameters
options:int

one or more of the following options, bitwise-OR-ed together: PARSE_VARIABLES, PARSE_ESCAPES, SKIP_WHITESPACE.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this object, consisting of the characters being iterated, with a '|' marking the current position. Position within an expanded variable is not indicated.

Returns:String

a string representation of this object

Annotations
@Override
com.ibm.icu.impl back to summary

public final Class RuleCharacterIterator.Position

extends Object
Class Inheritance

For use with getPos(Position) & setPos(Position).

Field Summary

Modifier and TypeField and Description
private String
private int
private int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufback to summary
private String buf
bufPosback to summary
private int bufPos
posIndexback to summary
private int posIndex

Constructor Detail

Positionback to summary
public Position()