Share via


ICharacterIterator Interface

Definition

This interface defines a protocol for bidirectional iteration over text.

[Android.Runtime.Register("java/text/CharacterIterator", "", "Java.Text.ICharacterIteratorInvoker")]
public interface ICharacterIterator : IDisposable, Java.Interop.IJavaPeerable, Java.Lang.ICloneable
[<Android.Runtime.Register("java/text/CharacterIterator", "", "Java.Text.ICharacterIteratorInvoker")>]
type ICharacterIterator = interface
    interface ICloneable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Derived
Attributes
Implements

Remarks

This interface defines a protocol for bidirectional iteration over text. The iterator iterates over a bounded sequence of characters. Characters are indexed with values beginning with the value returned by getBeginIndex() and continuing through the value returned by getEndIndex()-1.

Iterators maintain a current character index, whose valid range is from getBeginIndex() to getEndIndex(); the value getEndIndex() is included to allow handling of zero-length text ranges and for historical reasons. The current index can be retrieved by calling getIndex() and set directly by calling setIndex(), first(), and last().

The methods previous() and next() are used for iteration. They return DONE if they would move outside the range from getBeginIndex() to getEndIndex() -1, signaling that the iterator has reached the end of the sequence. DONE is also returned by other methods to indicate that the current index is outside this range.

Examples:

Traverse the text from start to finish

{@code
            public void traverseForward(CharacterIterator iter) {
                for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
                    processChar(c);
                }
            }
            }

Traverse the text backwards, from end to start

{@code
            public void traverseBackward(CharacterIterator iter) {
                for(char c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) {
                    processChar(c);
                }
            }
            }

Traverse both forward and backward from a given position in the text. Calls to notBoundary() in this example represents some additional stopping criteria.

{@code
            public void traverseOut(CharacterIterator iter, int pos) {
                for (char c = iter.setIndex(pos);
                         c != CharacterIterator.DONE && notBoundary(c);
                         c = iter.next()) {
                }
                int end = iter.getIndex();
                for (char c = iter.setIndex(pos);
                        c != CharacterIterator.DONE && notBoundary(c);
                        c = iter.previous()) {
                }
                int start = iter.getIndex();
                processSection(start, end);
            }
            }

Added in 1.1.

Java documentation for java.text.CharacterIterator.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Fields

Done

Constant that is returned when the iterator has reached either the end or the beginning of the text.

Properties

BeginIndex

Returns the begin index.

EndIndex

Returns the end index.

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
Index

Returns the current index.

JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)

Methods

Clone()

Create a copy of this iterator

Current()

Gets the character at the current position (as returned by getIndex()).

Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
First()

Sets the position to getBeginIndex() and returns the character at that position.

Last()

Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) and returns the character at that position.

Next()

Increments the iterator's index by one and returns the character at the new index.

Previous()

Decrements the iterator's index by one and returns the character at the new index.

SetIndex(Int32)

Sets the position to the specified position in the text and returns that character.

SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to