Crate ellidri_unicase

Source
Expand description

Wrapper around str that makes comparisons case-insensitive.

Intended for use within a HashMap. Actually used by ellidri’s State. It doesn’t support Unicode case-folding for now.

The wrapper is named UniCase. It implements traits so that &UniCase<str> behaves like &str, and UniCase<String> behaves like String, except for the comparisons of course, which are case-insensitive.

“Case-insensitivity” is defined by the CaseMapping trait. This trait defines how characters and bytes should match. Currently, the following case mappings are available:

  • Ascii (default): matches ascii lower case letters with their ascii upper case counterparts,
  • Rfc1459: same as Ascii, but also matches {}|^ with []\~.
  • Rfc1459Strict: same as Ascii, but also matches {}| with []\.

Currently, rfc7613 is not implemented.

§Usage

use ellidri_unicase::{u, UniCase};
use std::collections::HashSet;

let mut channels = HashSet::new();
channels.insert(UniCase::new("#Games".to_owned()));

assert!(channels.contains(u("#gameS")));
assert!(!channels.contains(u("#Gaming")));

assert_eq!(u("hello!"), u("HELLO!"));

Structs§

Ascii
ASCII case mapping.
Rfc1459
rfc1459 case mapping.
Rfc1459Strict
rfc1459-strict case mapping.
UniCase
Case-insensitive wrapper around strings.

Traits§

CaseMapping
Definition of case mappings.

Functions§

u
Converts a &str into a &UniCase<str, Ascii>.