#emoji #Unicode #ASCII #transliteration #unidecode

deunicode

Convert Unicode strings to pure ASCII by intelligently transliterating them. Suppors Emoji and Chinese.

5 releases (1 stable)

1.0.0 Dec 22, 2018
0.4.3 Sep 13, 2018
0.4.2 Sep 7, 2018
0.4.1 Sep 7, 2018
0.4.0 May 5, 2018

#16 in Text processing

Download history 792/week @ 2018-10-11 672/week @ 2018-10-18 715/week @ 2018-10-25 984/week @ 2018-11-01 1107/week @ 2018-11-08 1178/week @ 2018-11-15 1485/week @ 2018-11-22 1244/week @ 2018-11-29 1424/week @ 2018-12-06 1329/week @ 2018-12-13 1213/week @ 2018-12-20 1046/week @ 2018-12-27 1102/week @ 2019-01-03

4,801 downloads per month
Used in 65 crates (4 directly)

BSD-3-Clause

110KB
113 lines

deunicode

Documentation

The deunicode library transliterates Unicode strings such as "Æneid" into pure ASCII ones such as "AEneid."

It started as a Rust port of Text::Unidecode Perl module, and was extended to support emoji.

This is a fork of unidecode crate. This fork uses a compact representation of Unicode data to minimize memory overhead and executable size.

Examples

extern crate deunicode;
use deunicode::deunicode;

assert_eq!(deunicode("Æneid"), "AEneid");
assert_eq!(deunicode("étude"), "etude");
assert_eq!(deunicode("北亰"), "Bei Jing");
assert_eq!(deunicode("ᔕᓇᓇ"), "shanana");
assert_eq!(deunicode("げんまい茶"), "genmaiCha");
assert_eq!(deunicode("🦄☣"), "unicorn face biohazard");

Guarantees and Warnings

Here are some guarantees you have when calling deunicode():

  • The String returned will be valid ASCII; the decimal representation of every char in the string will be between 0 and 127, inclusive.
  • Every ASCII character (0x00 - 0x7F) is mapped to itself.
  • All Unicode characters will translate to printable ASCII characters (\n or characters in the range 0x20 - 0x7E).

There are, however, some things you should keep in mind:

  • As stated, some transliterations do produce \n characters.
  • Some Unicode characters transliterate to an empty string, either on purpose or because deunicode does not know about the character.
  • Some Unicode characters are unknown and transliterate to "[?]" (or a custom placeholder, or None if you use a chars iterator).
  • Many Unicode characters transliterate to multi-character strings. For example, "北" is transliterated as "Bei".
  • Han characters used in multiple languages are mapped to Mandarin, and will be mostly illegible to Japanese readers.

Unicode data

For a detailed explanation on the rationale behind the original dataset, refer to this article written by Burke in 2001.

No runtime deps