Skip to main content

CollationElements

Struct CollationElements 

Source
pub(crate) struct CollationElements<'data, I, T>
where I: Iterator<Item = (char, u32)> + WithTrie<'data, T, u32>, T: AbstractCodePointTrie<'data, u32>,
{
Show 17 fields iter: I, pending: SmallVec<[CollationElement; 6]>, pending_pos: usize, prefix: [char; 2], upcoming: SmallVec<[CharacterAndClassAndTrieValue; 10]>, root: &'data CollationData<'data>, tailoring: &'data CollationData<'data>, jamo: &'data [<u32 as AsULE>::ULE; 256], diacritics: &'data ZeroSlice<u16>, scalars16: &'data ZeroSlice<u16>, scalars32: &'data ZeroSlice<char>, numeric_primary: Option<u8>, lithuanian_dot_above: bool, upcoming_normalized: bool, iter_exhausted: bool, initialized: bool, _phantom: PhantomData<T>,
}
Expand description

Iterator that transforms an iterator over char into an iterator over CollationElement with a tailoring. Not a real Rust iterator: Instead of None uses NO_CE to indicate end of iteration to optimize comparison.

It is extremely important for performance that SmallVecs not be moved. To facilitate move-avoidance, this struct has the following life cycle where new returns the struct in a state that is not yet valid for a next call until init is called:

  1. new.
  2. Some number of calls to iter_next_before_init and prepend_upcoming_before_init.
  3. init.
  4. Some number of calls to next.

Fields§

§iter: I

See components/normalizer/trie-value-format.md for the trie wrapped in iter.

§pending: SmallVec<[CollationElement; 6]>

Already computed but not yet returned CollationElements.

§pending_pos: usize

The index of the next item to be returned from pending. The purpose of this index is to avoid moving the rest of the items.

§prefix: [char; 2]

The characters most previously seen (or never-matching placeholders) CLDR, as of 40, has two kinds of prefixes: Prefixes that contain a single starter Prefixes that contain a starter followed by either U+3099 or U+309A Last-pushed is at index 0 and previously-pushed at index 1

§upcoming: SmallVec<[CharacterAndClassAndTrieValue; 10]>

upcoming holds the characters that have already been read from iter but haven’t yet been mapped to CollationElements.

Typically, upcoming holds one character and corresponds semantically to pending_unnormalized_starter in icu::normalizer::Decomposition. This is why there isn’t a move avoidance optimization similar to pending_pos above for this buffer. A complex decomposition, a Hangul syllable followed by a non-starter, or lookahead can cause pending to hold more than one char.

Invariant: upcoming is allowed to become empty only after iter has been exhausted.

Invariant: (Checked by debug_assert!) At the start of next() call, if upcoming isn’t empty (with iter having been exhausted), the first char in upcoming must have its decomposition start with a starter.

TODO: Reverse the order, since now insert(0, x) and remove(0) are used more often than push() and pop().

§root: &'data CollationData<'data>

The root collation data.

§tailoring: &'data CollationData<'data>

Tailoring if applicable.

§jamo: &'data [<u32 as AsULE>::ULE; 256]

The CollationElement32 mapping for the Hangul Jamo block.

Note: in ICU4C the jamo table contains only modern jamo. Here, the jamo table contains the whole Unicode block.

§diacritics: &'data ZeroSlice<u16>

The CollationElement32 mapping for the Combining Diacritical Marks block.

§scalars16: &'data ZeroSlice<u16>

NFD complex decompositions on the BMP

§scalars32: &'data ZeroSlice<char>

NFD complex decompositions on supplementary planes

§numeric_primary: Option<u8>

If numeric mode is enabled, the 8 high bits of the numeric primary. None if disabled.

§lithuanian_dot_above: bool

Whether the Lithuanian combining dot above handling is enabled.

§upcoming_normalized: bool

Whether upcoming (except the last item) has been normalized already

§iter_exhausted: bool

Whether iter has been exhausted

§initialized: bool

Whether init has been called

§_phantom: PhantomData<T>

Implementations§

Source§

impl<'data, I, T> CollationElements<'data, I, T>
where I: Iterator<Item = (char, u32)> + WithTrie<'data, T, u32> + 'data, T: AbstractCodePointTrie<'data, u32> + 'data,

Source

pub fn new( delegate: I, root: &'data CollationData<'_>, tailoring: &'data CollationData<'_>, jamo: &'data [<u32 as AsULE>::ULE; 256], diacritics: &'data ZeroSlice<u16>, tables: &'data DecompositionTables<'_>, numeric_primary: Option<u8>, lithuanian_dot_above: bool, ) -> Self

Source

pub fn iter_next_before_init(&mut self) -> Option<CharacterAndClassAndTrieValue>

Source

pub fn prepend_upcoming_before_init(&mut self, c: CharacterAndClassAndTrieValue)

Source

pub fn init(&mut self)

Source

fn iter_next(&mut self) -> Option<CharacterAndClassAndTrieValue>

Source

fn next_internal(&mut self) -> Option<CharacterAndClassAndTrieValue>

Source

fn maybe_gather_combining(&mut self)

Source

fn ensure_upcoming_normalized(&mut self)

Ensures that upcoming is normalized to NFD, except:

  1. When the last item is a starter, it isn’t necessarily normalized.
  2. Hangul syllable are unnormalized.
Source

fn push_decomposed_combining(&mut self, c: CharacterAndClassAndTrieValue)

Source

fn push_decomposed_starter(&mut self, c: CharacterAndClassAndTrieValue) -> usize

Source

fn push_decomposed_and_gather_combining( &mut self, c: CharacterAndClassAndTrieValue, )

Source

fn look_ahead(&mut self, pos: usize) -> Option<CharacterAndClassAndTrieValue>

Source

fn is_next_decomposition_starts_with_starter(&self) -> bool

Source

fn prepend_and_sort_non_starter_prefix_of_suffix( &mut self, c: CharacterAndClassAndTrieValue, )

Source

fn prefix_push(&mut self, c: char)

Source

fn mark_prefix_unmatchable(&mut self)

Micro optimization for doing a simpler write when we know the most recent character was a non-starter that is not a kana voicing mark.

Source

pub fn next(&mut self) -> CollationElement

Source

fn collect_combining( &mut self, combining_characters: &mut SmallVec<[CharacterAndClass; 7]>, )

Auto Trait Implementations§

§

impl<'data, I, T> Freeze for CollationElements<'data, I, T>
where I: Freeze,

§

impl<'data, I, T> RefUnwindSafe for CollationElements<'data, I, T>

§

impl<'data, I, T> Send for CollationElements<'data, I, T>
where I: Send, T: Send,

§

impl<'data, I, T> Sync for CollationElements<'data, I, T>
where I: Sync, T: Sync,

§

impl<'data, I, T> Unpin for CollationElements<'data, I, T>
where I: Unpin, T: Unpin,

§

impl<'data, I, T> UnsafeUnpin for CollationElements<'data, I, T>
where I: UnsafeUnpin,

§

impl<'data, I, T> UnwindSafe for CollationElements<'data, I, T>
where I: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,