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>
impl CaseMapCloser<CaseMapper>
sourcepub const fn new() -> Self
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.
sourcepub fn try_new_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
) -> Result<Self, DataError>
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
.
sourcepub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
pub fn try_new_unstable<P>(provider: &P) -> Result<Self, DataError>
A version of Self::new
that uses custom data provided by a DataProvider
.
source§impl<CM: AsRef<CaseMapper>> CaseMapCloser<CM>
impl<CM: AsRef<CaseMapper>> CaseMapCloser<CM>
sourcepub fn try_new_with_mapper_with_any_provider(
provider: &(impl AnyProvider + ?Sized),
casemapper: CM,
) -> Result<Self, DataError>
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
.
sourcepub const fn new_with_mapper(casemapper: CM) -> Self
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.
sourcepub fn try_new_with_mapper_unstable<P>(
provider: &P,
casemapper: CM,
) -> Result<Self, DataError>
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
.
sourcepub fn add_case_closure_to<S: ClosureSink>(&self, c: char, set: &mut S)
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
sourcepub fn add_string_case_closure_to<S: ClosureSink>(
&self,
s: &str,
set: &mut S,
) -> bool
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>
impl<CM: Clone> Clone for CaseMapCloser<CM>
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 more