pub struct Normalizer { /* private fields */ }Expand description
Folds case and diacritics, identically for terms and queries.
Both foldings are on by default (Normalizer::new). Diacritic folding
runs first, then case folding; the result depends only on the input and
the two flags, and normalising twice gives the same result as normalising
once.
use keyhammer::text::Normalizer;
let n = Normalizer::new();
assert_eq!(n.normalize("Ação"), "acao");
assert_eq!(n.normalize("naïve CAFÉ"), "naive cafe");
// A decomposed accent (e + U+0301) is dropped too.
assert_eq!(n.normalize("cafe\u{301}"), "cafe");
// No Turkish tailoring: every i-like letter becomes i.
assert_eq!(n.normalize("Iıİi"), "iiii");
// Other scripts are copied unchanged.
assert_eq!(n.normalize("Ωmega"), "Ωmega");Implementations§
Source§impl Normalizer
impl Normalizer
Sourcepub const fn with_case_folding(self, on: bool) -> Self
pub const fn with_case_folding(self, on: bool) -> Self
The same normaliser with case folding on or off.
Sourcepub const fn with_diacritic_folding(self, on: bool) -> Self
pub const fn with_diacritic_folding(self, on: bool) -> Self
The same normaliser with diacritic folding on or off.
Sourcepub const fn folds_case(self) -> bool
pub const fn folds_case(self) -> bool
Whether case is folded.
Sourcepub const fn folds_diacritics(self) -> bool
pub const fn folds_diacritics(self) -> bool
Whether diacritics are folded.
Sourcepub fn normalize_char(self, c: char, emit: impl FnMut(char))
pub fn normalize_char(self, c: char, emit: impl FnMut(char))
Calls emit with the characters c normalises to (none, one or up to
three), in order.
use keyhammer::text::Normalizer;
let mut out = String::new();
Normalizer::new().normalize_char('ß', |c| out.push(c));
assert_eq!(out, "ss");Sourcepub fn normalize_into(&self, s: &str, out: &mut String)
pub fn normalize_into(&self, s: &str, out: &mut String)
Clears out and writes the normalised form of s into it, reusing its
allocation.
Sourcepub fn normalize_mapped(&self, s: &str, map: &mut SourceMap) -> String
pub fn normalize_mapped(&self, s: &str, map: &mut SourceMap) -> String
The normalised form of s, and in map where each of its code points
came from (see SourceMap). map is cleared first.
use keyhammer::text::{Normalizer, SourceMap};
let mut map = SourceMap::new();
let n = Normalizer::new().normalize_mapped("Maße", &mut map);
assert_eq!(n, "masse");
// "ss" (output code points 2..4) comes from "ß" (input code point 2).
assert_eq!(map.to_source(2..4), Some(2..3));
assert_eq!(map.to_source(3..5), Some(2..4));Trait Implementations§
Source§impl Clone for Normalizer
impl Clone for Normalizer
Source§fn clone(&self) -> Normalizer
fn clone(&self) -> Normalizer
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for Normalizer
Source§impl Debug for Normalizer
impl Debug for Normalizer
Source§impl Default for Normalizer
impl Default for Normalizer
impl Eq for Normalizer
Source§impl Hash for Normalizer
impl Hash for Normalizer
Source§impl PartialEq for Normalizer
impl PartialEq for Normalizer
impl StructuralPartialEq for Normalizer
Auto Trait Implementations§
impl Freeze for Normalizer
impl RefUnwindSafe for Normalizer
impl Send for Normalizer
impl Sync for Normalizer
impl Unpin for Normalizer
impl UnsafeUnpin for Normalizer
impl UnwindSafe for Normalizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more