Crate rust_icu_utrans[−][src]
Expand description
ICU transliteration support for Rust
This crate provides a Rust implementation of the ICU transliteration APIs in utrans.h
.
Examples
Sample code use is given below.
ICU includes a number of built-in transliterators, which can be listed with
get_ids
.
Transliterators may be combined to form a sequence of text transformations by provding a
compound identifier as shown below.
use rust_icu_sys as sys; use rust_icu_utrans as utrans; let compound_id = "NFC; Latin; Latin-ASCII"; let ascii_trans = utrans::UTransliterator::new( compound_id, None, sys::UTransDirection::UTRANS_FORWARD).unwrap(); assert_eq!(ascii_trans.transliterate("литература").unwrap(), "literatura");
It is also possible to define your own transliterators by providing a set of rules to
new
.
use rust_icu_sys as sys; use rust_icu_utrans as utrans; let id = "Coffee"; let rules = r"a > o; f > ff; \u00e9 > ee;"; let custom_trans = utrans::UTransliterator::new( id, Some(rules), sys::UTransDirection::UTRANS_FORWARD).unwrap(); assert_eq!(custom_trans.transliterate("caf\u{00e9}").unwrap(), "coffee");
See the ICU user guide
and the C API documentation in the
utrans.h
header
for details.
Structs
UTransliterator | Rust wrapper for the ICU |