Struct icu_casemap::closer::CaseMapCloser

source ·
pub struct CaseMapCloser<CM> {
    cm: CM,
    unfold: DataPayload<CaseMapUnfoldV1Marker>,
}
Expand description

A wrapper around CaseMapper that can produce case mapping closures over a character or string. This wrapper can be constructed directly, or by wrapping a reference to an existing CaseMapper.

§Examples

use icu::casemap::CaseMapCloser;
use icu::collections::codepointinvlist::CodePointInversionListBuilder;

let cm = CaseMapCloser::new();
let mut builder = CodePointInversionListBuilder::new();
let found = cm.add_string_case_closure_to("ffi", &mut builder);
assert!(found);
let set = builder.build();

assert!(set.contains('ffi'));

let mut builder = CodePointInversionListBuilder::new();
let found = cm.add_string_case_closure_to("ss", &mut builder);
assert!(found);
let set = builder.build();

assert!(set.contains('ß'));
assert!(set.contains('ẞ'));

Fields§

§cm: CM§unfold: DataPayload<CaseMapUnfoldV1Marker>

Implementations§

source§

impl CaseMapCloser<CaseMapper>

source

pub const fn new() -> Self

A constructor which creates a CaseMapCloser using compiled data.

§Examples
use icu::casemap::CaseMapCloser;
use icu::collections::codepointinvlist::CodePointInversionListBuilder;

let cm = CaseMapCloser::new();
let mut builder = CodePointInversionListBuilder::new();
let found = cm.add_string_case_closure_to("ffi", &mut builder);
assert!(found);
let set = builder.build();

assert!(set.contains('ffi'));

let mut builder = CodePointInversionListBuilder::new();
let found = cm.add_string_case_closure_to("ss", &mut builder);
assert!(found);
let set = builder.build();

assert!(set.contains('ß'));
assert!(set.contains('ẞ'));

Enabled with the compiled_data Cargo feature.

📚 Help choosing a constructor

source

pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized), ) -> Result<Self, DataError>

A version of Self::new that uses custom data provided by an AnyProvider.

📚 Help choosing a constructor

source

pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>

A version of Self::new that uses custom data provided by a DataProvider.

📚 Help choosing a constructor

⚠️ The bounds on provider may change over time, including in SemVer minor releases.
source§

impl<CM: AsRef<CaseMapper>> CaseMapCloser<CM>

source

pub fn try_new_with_mapper_with_any_provider( provider: &(impl AnyProvider + ?Sized), casemapper: CM, ) -> Result<Self, DataError>

A version of Self::new_with_mapper that uses custom data provided by an AnyProvider.

📚 Help choosing a constructor

source

pub const fn new_with_mapper(casemapper: CM) -> Self

A constructor which creates a CaseMapCloser from an existing CaseMapper (either owned or as a reference)

Enabled with the compiled_data Cargo feature.

📚 Help choosing a constructor

source

pub fn try_new_with_mapper_unstable<P>( provider: &P, casemapper: CM, ) -> Result<Self, DataError>

Construct this object to wrap an existing CaseMapper (or a reference to one), loading additional data as needed. A version of Self::new_with_mapper that uses custom data provided by a DataProvider.

📚 Help choosing a constructor

⚠️ The bounds on provider may change over time, including in SemVer minor releases.
source

pub fn add_case_closure_to<S: ClosureSink>(&self, c: char, set: &mut S)

Adds all simple case mappings and the full case folding for c to set. Also adds special case closure mappings.

In other words, this adds all strings/characters that this casemaps to, as well as all characters that may casemap to this one.

The character itself is not added.

For example, the mappings

  • for s include long s
  • for sharp s include ss
  • for k include the Kelvin sign

This function is identical to CaseMapper::add_case_closure_to(); if you don’t need Self::add_string_case_closure_to() consider using a CaseMapper to avoid loading additional data.

§Examples
use icu::casemap::CaseMapCloser;
use icu::collections::codepointinvlist::CodePointInversionListBuilder;

let cm = CaseMapCloser::new();
let mut builder = CodePointInversionListBuilder::new();
cm.add_case_closure_to('s', &mut builder);

let set = builder.build();

assert!(set.contains('S'));
assert!(set.contains('ſ'));
assert!(!set.contains('s')); // does not contain itself
source

pub fn add_string_case_closure_to<S: ClosureSink>( &self, s: &str, set: &mut S, ) -> bool

Finds all characters and strings which may casemap to s as their full case folding string and adds them to the set. Includes the full case closure of each character mapping.

In other words, this performs a reverse full case folding and then adds the case closure items of the resulting code points.

The string itself is not added to the set.

Returns true if the string was found

§Examples
use icu::casemap::CaseMapCloser;
use icu::collections::codepointinvlist::CodePointInversionListBuilder;

let cm = CaseMapCloser::new();
let mut builder = CodePointInversionListBuilder::new();
let found = cm.add_string_case_closure_to("ffi", &mut builder);
assert!(found);
let set = builder.build();

assert!(set.contains('ffi'));

let mut builder = CodePointInversionListBuilder::new();
let found = cm.add_string_case_closure_to("ss", &mut builder);
assert!(found);
let set = builder.build();

assert!(set.contains('ß'));
assert!(set.contains('ẞ'));

Trait Implementations§

source§

impl<CM: Clone> Clone for CaseMapCloser<CM>

source§

fn clone(&self) -> CaseMapCloser<CM>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<CM: Debug> Debug for CaseMapCloser<CM>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for CaseMapCloser<CaseMapper>

source§

fn default() -> Self

Enabled with the compiled_data Cargo feature.

Auto Trait Implementations§

§

impl<CM> Freeze for CaseMapCloser<CM>
where CM: Freeze,

§

impl<CM> RefUnwindSafe for CaseMapCloser<CM>
where CM: RefUnwindSafe,

§

impl<CM> !Send for CaseMapCloser<CM>

§

impl<CM> !Sync for CaseMapCloser<CM>

§

impl<CM> Unpin for CaseMapCloser<CM>
where CM: Unpin,

§

impl<CM> UnwindSafe for CaseMapCloser<CM>
where CM: 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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,

source§

impl<T> MaybeSendSync for T