ICU 74.2 74.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:

## 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.
| ~BytesTrie ()
| Destructor.
| BytesTrie (const BytesTrie &other)
| Copy constructor, copies the other trie reader object and its state, but not the byte array which will be shared.
BytesTrie & | reset ()
| Resets this trie to its initial state.
uint64_t | getState64 () const
| Returns the state of this trie as a 64-bit integer.
BytesTrie & | resetToState64 (uint64_t state)
| Resets this trie to the saved state.
const BytesTrie & | saveState (State &state) const
| Saves the state of this trie.
BytesTrie & | resetToState (const State &state)
| Resets this trie to the saved state.
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.
UStringTrieResult | first (int32_t inByte)
| Traverses the trie from the initial state for this input byte.
UStringTrieResult | next (int32_t inByte)
| Traverses the trie from the current state for this input byte.
UStringTrieResult | next (const char *s, int32_t length)
| Traverses the trie from the current state for this byte sequence.
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.
UBool | hasUniqueValue (int32_t &uniqueValue) const
| Determines whether all byte sequences reachable from the current state map to the same value.
int32_t | getNextBytes (ByteSink &out) const
| Finds each byte which continues the byte sequence from the current state.

## Friends
class | BytesTrieBuilder
class | ::BytesTrieTest

## 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 55 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

  trieBytes | The byte array that contains the serialized trie.

Stable:
  ICU 4.8

Definition at line 71 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

  other | Another BytesTrie object.

Stable:
  ICU 4.8

Definition at line 87 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

  inByte | Input 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 203 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

  out | Each 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

## ◆ getState64()

uint64_t icu::BytesTrie::getState64 | ( |  | ) | const
| inline

Returns the state of this trie as a 64-bit integer.

The state value is never 0.

Returns
  opaque state value

See also
  resetToState64

Stable:
  ICU 65

Definition at line 110 of file bytestrie.h.

## ◆ 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 246 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

  uniqueValue | Receives 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 262 of file bytestrie.h.

## ◆ next() [1/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)
if(!USTRINGTRIE_HAS_NEXT(result)) return USTRINGTRIE_NO_MATCH;
result=next(c);
return result;
icu::BytesTrie::current
UStringTrieResult current() const
Determines whether the byte sequence so far matches, whether it has a value, and whether another inpu...
icu::BytesTrie::next
UStringTrieResult next(int32_t inByte)
Traverses the trie from the current state for this input byte.
USTRINGTRIE_NO_MATCH
@ USTRINGTRIE_NO_MATCH
The input unit(s) did not continue a matching string.
Definition ustringtrie.h:43
USTRINGTRIE_HAS_NEXT
#define USTRINGTRIE_HAS_NEXT(result)
Equivalent to (result==USTRINGTRIE_NO_VALUE || result==USTRINGTRIE_INTERMEDIATE_VALUE) but this macro...
Definition ustringtrie.h:95

Parameters

  s | A string or byte sequence. Can be nullptr if length is 0.
  length | The length of the byte sequence. Can be -1 if NUL-terminated.

Returns
  The match/value Result.

Stable:
  ICU 4.8

## ◆ next() [2/2]

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

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

Parameters

  inByte | Input 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

## ◆ reset()

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

Resets this trie to its initial state.

Returns
  *this

Stable:
  ICU 4.8

Definition at line 96 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

  state | The State object which holds a saved trie state.

Returns
  *this

See also
  saveState
  reset

Stable:
  ICU 4.8

Definition at line 179 of file bytestrie.h.

## ◆ resetToState64()

BytesTrie & icu::BytesTrie::resetToState64 | ( | uint64_t | state | ) |
| inline

Resets this trie to the saved state.

Unlike resetToState(State), the 64-bit state value must be from getState64() from the same trie object or from one initialized the exact same way. Because of no validation, this method is faster.

Parameters

  state | The opaque trie state value from getState64().

Returns
  *this

See also
  getState64
  resetToState
  reset

Stable:
  ICU 65

Definition at line 129 of file bytestrie.h.

## ◆ saveState()

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

Saves the state of this trie.

Parameters

  state | The State object to hold the trie's state.

Returns
  *this

See also
  resetToState

Stable:
  ICU 4.8

Definition at line 162 of file bytestrie.h.

## Friends And Related Symbol Documentation

## ◆ ::BytesTrieTest

friend class ::BytesTrieTest
| friend

Definition at line 383 of file bytestrie.h.

## ◆ BytesTrieBuilder

friend class BytesTrieBuilder
| friend

Definition at line 382 of file bytestrie.h.

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

- common/unicode/bytestrie.h