6 releases (2 stable)

1.0.1 Jul 9, 2021
1.0.0 May 4, 2021
0.3.0 Mar 13, 2021
0.2.0 Apr 7, 2020
0.1.1 Apr 6, 2020

#90 in Text processing

Download history 249/week @ 2021-08-11 286/week @ 2021-08-18 209/week @ 2021-08-25 196/week @ 2021-09-01 172/week @ 2021-09-08 185/week @ 2021-09-15 161/week @ 2021-09-22 244/week @ 2021-09-29 193/week @ 2021-10-06 167/week @ 2021-10-13 377/week @ 2021-10-20 307/week @ 2021-10-27 297/week @ 2021-11-03 243/week @ 2021-11-10 223/week @ 2021-11-17 219/week @ 2021-11-24

1,013 downloads per month
Used in 2 crates

MIT license

1MB
66K SLoC

Secular

MIT Latest Version Chat on Miaou

Provide a lowercased diacritics-free version of a character or a string.

For example return e for é.

Secular's char lookup is an inlined lookup of a static table, which means it's possible to use it in performance sensitive code.

Secular also performs (optionally) Unicode normalization.

A common use case for the removal of diacritics and some unicode arterfacts is to ease searches:

broot search

(diacritics ignoring normalized search in broot: the user typed rève)

Declaration

By default, diacritics removal is only done on ascii chars, so to include a smaller table.

If you want to handle the whole BMP, use the "bmp" feature" (the downside is that the binary is bigger as it includes a big map).

Default import:

[dependencies]
secular = "0.3"

For more characters (the BMP):

[dependencies]
secular = { version="0.3", features=["bmp"] }

With Unicode normalization functions (using the unicode-normalization crate):

[dependencies]
secular = { version="0.3", features=["normalization"] }

or

[dependencies]
secular = { version="0.3", features=["bmp","normalization"] }

This feature is optional so that you can avoid importing the unicode-normalization crate (note that it's used in many other crates so it's possible your text processing application already uses it).

Usage

On characters:

use secular::*;
let s = "Comunicações"; // normalized string (length=12)
let chars: Vec<char> = s.chars().collect();
assert_eq!(chars.len(), 12);
assert_eq!(chars[0], 'C');
assert_eq!(lower_lay_char(chars[0]), 'c');
assert_eq!(chars[8], 'ç');
assert_eq!(lower_lay_char(chars[8]), 'c');

On strings:

use secular::*;
let s = "Comunicações"; // unnormalized string (length=14)
assert_eq!(s.chars().count(), 14);
let s = normalized_lower_lay_string(s);
assert_eq!(s.chars().count(), 12);
assert_eq!(s, "comunicacoes");

Dependencies