ICU 72.1 72.1

Data Structures | Public Member Functions | Friends
icu::UCharsTrie Class Reference

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

`#include <ucharstrie.h>`

Inheritance diagram for icu::UCharsTrie:

## Data Structures
class | Iterator
| Iterator for all of the (string, value) pairs in a UCharsTrie. More...
class | State
| UCharsTrie state object, for saving a trie's current state and resetting the trie back to this state later. More...

## Public Member Functions
| UCharsTrie (ConstChar16Ptr trieUChars)
| Constructs a UCharsTrie reader instance. More...
| ~UCharsTrie ()
| Destructor. More...
| UCharsTrie (const UCharsTrie &other)
| Copy constructor, copies the other trie reader object and its state, but not the char16_t array which will be shared. More...
UCharsTrie & | reset ()
| Resets this trie to its initial state. More...
uint64_t | getState64 () const
| Returns the state of this trie as a 64-bit integer. More...
UCharsTrie & | resetToState64 (uint64_t state)
| Resets this trie to the saved state. More...
const UCharsTrie & | saveState (State &state) const
| Saves the state of this trie. More...
UCharsTrie & | resetToState (const State &state)
| Resets this trie to the saved state. More...
UStringTrieResult | current () const
| Determines whether the string so far matches, whether it has a value, and whether another input char16_t can continue a matching string. More...
UStringTrieResult | first (int32_t uchar)
| Traverses the trie from the initial state for this input char16_t. More...
UStringTrieResult | firstForCodePoint (UChar32 cp)
| Traverses the trie from the initial state for the one or two UTF-16 code units for this input code point. More...
UStringTrieResult | next (int32_t uchar)
| Traverses the trie from the current state for this input char16_t. More...
UStringTrieResult | nextForCodePoint (UChar32 cp)
| Traverses the trie from the current state for the one or two UTF-16 code units for this input code point. More...
UStringTrieResult | next (ConstChar16Ptr s, int32_t length)
| Traverses the trie from the current state for this string. More...
int32_t | getValue () const
| Returns a matching string'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 strings reachable from the current state map to the same value. More...
int32_t | getNextUChars (Appendable &out) const
| Finds each char16_t which continues the string from the current state. More...

## Friends
class | UCharsTrieBuilder

## Detailed Description

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

Traverses a char16_t-serialized data structure with minimal state, for mapping strings (16-bit-unit 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 53 of file ucharstrie.h.

## Constructor & Destructor Documentation

## ◆ UCharsTrie() [1/2]

icu::UCharsTrie::UCharsTrie | ( | ConstChar16Ptr | trieUChars | ) |
| inline

Constructs a UCharsTrie reader instance.

The trieUChars must contain a copy of a char16_t sequence from the UCharsTrieBuilder, starting with the first char16_t of that sequence. The UCharsTrie object will not read more char16_ts than the UCharsTrieBuilder generated in the corresponding build() call.

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

Parameters

  trieUChars | The char16_t array that contains the serialized trie.

Stable:
  ICU 4.8

Definition at line 69 of file ucharstrie.h.

## ◆ ~UCharsTrie()

icu::UCharsTrie::~UCharsTrie | ( |  | ) |

Destructor.

Stable:
  ICU 4.8

## ◆ UCharsTrie() [2/2]

icu::UCharsTrie::UCharsTrie | ( | const UCharsTrie & | other | ) |
| inline

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

(Shallow copy.)

Parameters

  other | Another UCharsTrie object.

Stable:
  ICU 4.8

Definition at line 85 of file ucharstrie.h.

## Member Function Documentation

## ◆ current()

UStringTrieResult icu::UCharsTrie::current | ( |  | ) | const

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

Returns
  The match/value Result.

Stable:
  ICU 4.8

## ◆ first()

UStringTrieResult icu::UCharsTrie::first | ( | int32_t | uchar | ) |
| inline

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

Equivalent to reset().next(uchar).

Parameters

  uchar | Input char value. Values below 0 and above 0xffff will never match.

Returns
  The match/value Result.

Stable:
  ICU 4.8

Definition at line 200 of file ucharstrie.h.

## ◆ firstForCodePoint()

UStringTrieResult icu::UCharsTrie::firstForCodePoint | ( | UChar32 | cp | ) |

Traverses the trie from the initial state for the one or two UTF-16 code units for this input code point.

Equivalent to reset().nextForCodePoint(cp).

Parameters

  cp | A Unicode code point 0..0x10ffff.

Returns
  The match/value Result.

Stable:
  ICU 4.8

## ◆ getNextUChars()

int32_t icu::UCharsTrie::getNextUChars | ( | Appendable & | out | ) | const

Finds each char16_t which continues the string from the current state.

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

Parameters

  out | Each next char16_t is appended to this object.

Returns
  the number of char16_ts which continue the string from here

Stable:
  ICU 4.8

## ◆ getState64()

uint64_t icu::UCharsTrie::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 108 of file ucharstrie.h.

## ◆ getValue()

int32_t icu::UCharsTrie::getValue | ( |  | ) | const
| inline

Returns a matching string'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 string so far.

Stable:
  ICU 4.8

Definition at line 258 of file ucharstrie.h.

## ◆ hasUniqueValue()

UBool icu::UCharsTrie::hasUniqueValue | ( | int32_t & | uniqueValue | ) | const
| inline

Determines whether all strings 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 strings reachable from the current state map to the same value.

Stable:
  ICU 4.8

Definition at line 275 of file ucharstrie.h.

References NULL.

## ◆ next() [1/2]

UStringTrieResult icu::UCharsTrie::next | ( | ConstChar16Ptr | s,
|  | int32_t | length
| ) |  |

Traverses the trie from the current state for this string.

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::UCharsTrie::next
UStringTrieResult next(int32_t uchar)
Traverses the trie from the current state for this input char16_t.
icu::UCharsTrie::current
UStringTrieResult current() const
Determines whether the string so far matches, whether it has a value, and whether another input char1...
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. Can be NULL if length is 0.
  length | The length of the string. Can be -1 if NUL-terminated.

Returns
  The match/value Result.

Stable:
  ICU 4.8

## ◆ next() [2/2]

UStringTrieResult icu::UCharsTrie::next | ( | int32_t | uchar | ) |

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

Parameters

  uchar | Input char value. Values below 0 and above 0xffff will never match.

Returns
  The match/value Result.

Stable:
  ICU 4.8

## ◆ nextForCodePoint()

UStringTrieResult icu::UCharsTrie::nextForCodePoint | ( | UChar32 | cp | ) |

Traverses the trie from the current state for the one or two UTF-16 code units for this input code point.

Parameters

  cp | A Unicode code point 0..0x10ffff.

Returns
  The match/value Result.

Stable:
  ICU 4.8

## ◆ reset()

UCharsTrie& icu::UCharsTrie::reset | ( | void |  | ) |
| inline

Resets this trie to its initial state.

Returns
  *this

Stable:
  ICU 4.8

Definition at line 94 of file ucharstrie.h.

## ◆ resetToState()

UCharsTrie& icu::UCharsTrie::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 177 of file ucharstrie.h.

References NULL.

## ◆ resetToState64()

UCharsTrie& icu::UCharsTrie::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 127 of file ucharstrie.h.

## ◆ saveState()

const UCharsTrie& icu::UCharsTrie::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 160 of file ucharstrie.h.

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

- ucharstrie.h