Struct icu::casemap::CaseMapCloser
source · pub struct CaseMapCloser<CM> { /* private fields */ }
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('ẞ'));
Implementations§
source§impl CaseMapCloser<CaseMapper>
impl CaseMapCloser<CaseMapper>
sourcepub const fn new() -> CaseMapCloser<CaseMapper>
pub const fn new() -> CaseMapCloser<CaseMapper>
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.
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized)
) -> Result<CaseMapCloser<CaseMapper>, DataError>
pub fn try_new_with_any_provider( provider: &(impl AnyProvider + ?Sized) ) -> Result<CaseMapCloser<CaseMapper>, DataError>
A version of Self::new
that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized)
) -> Result<CaseMapCloser<CaseMapper>, DataError>
pub fn try_new_with_buffer_provider( provider: &(impl BufferProvider + ?Sized) ) -> Result<CaseMapCloser<CaseMapper>, DataError>
A version of Self::new
that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub fn try_new_unstable<P>(
provider: &P
) -> Result<CaseMapCloser<CaseMapper>, DataError>
pub fn try_new_unstable<P>( provider: &P ) -> Result<CaseMapCloser<CaseMapper>, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
source§impl<CM> CaseMapCloser<CM>where
CM: AsRef<CaseMapper>,
impl<CM> CaseMapCloser<CM>where
CM: AsRef<CaseMapper>,
sourcepub fn try_new_with_mapper_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
casemapper: CM
) -> Result<CaseMapCloser<CM>, DataError>
pub fn try_new_with_mapper_with_any_provider( provider: &(impl AnyProvider + ?Sized), casemapper: CM ) -> Result<CaseMapCloser<CM>, DataError>
A version of Self::new_with_mapper
that uses custom data provided by an AnyProvider
.
sourcepub fn try_new_with_mapper_with_buffer_provider(
provider: &(impl BufferProvider + ?Sized),
casemapper: CM
) -> Result<CaseMapCloser<CM>, DataError>
pub fn try_new_with_mapper_with_buffer_provider( provider: &(impl BufferProvider + ?Sized), casemapper: CM ) -> Result<CaseMapCloser<CM>, DataError>
A version of Self::new_with_mapper
that uses custom data provided by a BufferProvider
.
✨ Enabled with the serde
feature.
sourcepub const fn new_with_mapper(casemapper: CM) -> CaseMapCloser<CM>
pub const fn new_with_mapper(casemapper: CM) -> CaseMapCloser<CM>
A constructor which creates a CaseMapCloser
from an existing CaseMapper
(either owned or as a reference)
✨ Enabled with the compiled_data
Cargo feature.
sourcepub fn try_new_with_mapper_unstable<P>(
provider: &P,
casemapper: CM
) -> Result<CaseMapCloser<CM>, DataError>
pub fn try_new_with_mapper_unstable<P>( provider: &P, casemapper: CM ) -> Result<CaseMapCloser<CM>, 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
.
sourcepub fn add_case_closure_to<S>(&self, c: char, set: &mut S)where
S: ClosureSink,
pub fn add_case_closure_to<S>(&self, c: char, set: &mut S)where
S: ClosureSink,
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
sourcepub fn add_string_case_closure_to<S>(&self, s: &str, set: &mut S) -> boolwhere
S: ClosureSink,
pub fn add_string_case_closure_to<S>(&self, s: &str, set: &mut S) -> boolwhere
S: ClosureSink,
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 for CaseMapCloser<CM>where
CM: Clone,
impl<CM> Clone for CaseMapCloser<CM>where
CM: Clone,
source§fn clone(&self) -> CaseMapCloser<CM>
fn clone(&self) -> CaseMapCloser<CM>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<CM> Debug for CaseMapCloser<CM>where
CM: Debug,
impl<CM> Debug for CaseMapCloser<CM>where
CM: Debug,
source§impl Default for CaseMapCloser<CaseMapper>
impl Default for CaseMapCloser<CaseMapper>
source§fn default() -> CaseMapCloser<CaseMapper>
fn default() -> CaseMapCloser<CaseMapper>
✨ Enabled with the compiled_data
Cargo feature.