3 stable releases

2.1.0 Apr 10, 2020
2.0.0 Mar 31, 2020
1.0.0 Feb 18, 2020

#28 in #case-insensitive

23 downloads per month
Used in ellidri

ISC license

8KB
131 lines

ellidri-unicase

A wrapper around str that makes comparisons case-insensitive.

Used for ellidri.


lib.rs:

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!"));

No runtime deps