ICU 64.2  64.2
Data Structures | Public Member Functions | Friends
icu::BytesTrie Class Reference

Light-weight, non-const reader class for a BytesTrie. More...

#include <bytestrie.h>

Inheritance diagram for icu::BytesTrie:
icu::UMemory

Data Structures

class  Iterator
 Iterator for all of the (byte sequence, value) pairs in a BytesTrie. More...
 
class  State
 BytesTrie state object, for saving a trie's current state and resetting the trie back to this state later. More...
 

Public Member Functions

 BytesTrie (const void *trieBytes)
 Constructs a BytesTrie reader instance. More...
 
 ~BytesTrie ()
 Destructor. More...
 
 BytesTrie (const BytesTrie &other)
 Copy constructor, copies the other trie reader object and its state, but not the byte array which will be shared. More...
 
BytesTriereset ()
 Resets this trie to its initial state. More...
 
const BytesTriesaveState (State &state) const
 Saves the state of this trie. More...
 
BytesTrieresetToState (const State &state)
 Resets this trie to the saved state. More...
 
UStringTrieResult current () const
 Determines whether the byte sequence so far matches, whether it has a value, and whether another input byte can continue a matching byte sequence. More...
 
UStringTrieResult first (int32_t inByte)
 Traverses the trie from the initial state for this input byte. More...
 
UStringTrieResult next (int32_t inByte)
 Traverses the trie from the current state for this input byte. More...
 
UStringTrieResult next (const char *s, int32_t length)
 Traverses the trie from the current state for this byte sequence. More...
 
int32_t getValue () const
 Returns a matching byte sequence's value if called immediately after current()/first()/next() returned USTRINGTRIE_INTERMEDIATE_VALUE or USTRINGTRIE_FINAL_VALUE. More...
 
UBool hasUniqueValue (int32_t &uniqueValue) const
 Determines whether all byte sequences reachable from the current state map to the same value. More...
 
int32_t getNextBytes (ByteSink &out) const
 Finds each byte which continues the byte sequence from the current state. More...
 

Friends

class BytesTrieBuilder
 

Detailed Description

Light-weight, non-const reader class for a BytesTrie.

Traverses a byte-serialized data structure with minimal state, for mapping byte sequences to non-negative integer values.

This class owns the serialized trie data only if it was constructed by the builder's build() method. The public constructor and the copy constructor only alias the data (only copy the pointer). There is no assignment operator.

This class is not intended for public subclassing.

Stable:
ICU 4.8

Definition at line 50 of file bytestrie.h.

Constructor & Destructor Documentation

◆ BytesTrie() [1/2]

icu::BytesTrie::BytesTrie ( const void *  trieBytes)
inline

Constructs a BytesTrie reader instance.

The trieBytes must contain a copy of a byte sequence from the BytesTrieBuilder, starting with the first byte of that sequence. The BytesTrie object will not read more bytes than the BytesTrieBuilder generated in the corresponding build() call.

The array is not copied/cloned and must not be modified while the BytesTrie object is in use.

Parameters
trieBytesThe byte array that contains the serialized trie.
Stable:
ICU 4.8

Definition at line 66 of file bytestrie.h.

◆ ~BytesTrie()

icu::BytesTrie::~BytesTrie ( )

Destructor.

Stable:
ICU 4.8

◆ BytesTrie() [2/2]

icu::BytesTrie::BytesTrie ( const BytesTrie other)
inline

Copy constructor, copies the other trie reader object and its state, but not the byte array which will be shared.

(Shallow copy.)

Parameters
otherAnother BytesTrie object.
Stable:
ICU 4.8

Definition at line 82 of file bytestrie.h.

Member Function Documentation

◆ current()

UStringTrieResult icu::BytesTrie::current ( ) const

Determines whether the byte sequence so far matches, whether it has a value, and whether another input byte can continue a matching byte sequence.

Returns
The match/value Result.
Stable:
ICU 4.8

◆ first()

UStringTrieResult icu::BytesTrie::first ( int32_t  inByte)
inline

Traverses the trie from the initial state for this input byte.

Equivalent to reset().next(inByte).

Parameters
inByteInput byte value. Values -0x100..-1 are treated like 0..0xff. Values below -0x100 and above 0xff will never match.
Returns
The match/value Result.
Stable:
ICU 4.8

Definition at line 165 of file bytestrie.h.

◆ getNextBytes()

int32_t icu::BytesTrie::getNextBytes ( ByteSink out) const

Finds each byte which continues the byte sequence from the current state.

That is, each byte b for which it would be next(b)!=USTRINGTRIE_NO_MATCH now.

Parameters
outEach next byte is appended to this object. (Only uses the out.Append(s, length) method.)
Returns
the number of bytes which continue the byte sequence from here
Stable:
ICU 4.8

◆ getValue()

int32_t icu::BytesTrie::getValue ( ) const
inline

Returns a matching byte sequence's value if called immediately after current()/first()/next() returned USTRINGTRIE_INTERMEDIATE_VALUE or USTRINGTRIE_FINAL_VALUE.

getValue() can be called multiple times.

Do not call getValue() after USTRINGTRIE_NO_MATCH or USTRINGTRIE_NO_VALUE!

Returns
The value for the byte sequence so far.
Stable:
ICU 4.8

Definition at line 208 of file bytestrie.h.

◆ hasUniqueValue()

UBool icu::BytesTrie::hasUniqueValue ( int32_t &  uniqueValue) const
inline

Determines whether all byte sequences reachable from the current state map to the same value.

Parameters
uniqueValueReceives the unique value, if this function returns TRUE. (output-only)
Returns
TRUE if all byte sequences reachable from the current state map to the same value.
Stable:
ICU 4.8

Definition at line 224 of file bytestrie.h.

References FALSE, and NULL.

◆ next() [1/2]

UStringTrieResult icu::BytesTrie::next ( int32_t  inByte)

Traverses the trie from the current state for this input byte.

Parameters
inByteInput byte value. Values -0x100..-1 are treated like 0..0xff. Values below -0x100 and above 0xff will never match.
Returns
The match/value Result.
Stable:
ICU 4.8

◆ next() [2/2]

UStringTrieResult icu::BytesTrie::next ( const char *  s,
int32_t  length 
)

Traverses the trie from the current state for this byte sequence.

Equivalent to

Result result=current();
for(each c in s)
result=next(c);
return result;
Parameters
sA string or byte sequence. Can be NULL if length is 0.
lengthThe length of the byte sequence. Can be -1 if NUL-terminated.
Returns
The match/value Result.
Stable:
ICU 4.8

◆ reset()

BytesTrie& icu::BytesTrie::reset ( )
inline

Resets this trie to its initial state.

Returns
*this
Stable:
ICU 4.8

Definition at line 91 of file bytestrie.h.

◆ resetToState()

BytesTrie& icu::BytesTrie::resetToState ( const State state)
inline

Resets this trie to the saved state.

If the state object contains no state, or the state of a different trie, then this trie remains unchanged.

Parameters
stateThe State object which holds a saved trie state.
Returns
*this
See also
saveState
reset
Stable:
ICU 4.8

Definition at line 141 of file bytestrie.h.

References NULL.

◆ saveState()

const BytesTrie& icu::BytesTrie::saveState ( State state) const
inline

Saves the state of this trie.

Parameters
stateThe State object to hold the trie's state.
Returns
*this
See also
resetToState
Stable:
ICU 4.8

Definition at line 124 of file bytestrie.h.


The documentation for this class was generated from the following file: