Skip to main content

Crate ewts

Crate ewts 

Source
Expand description

Converter between EWTS (Extended Wylie Transliteration Scheme) and Tibetan Unicode, in both directions.

EWTS writes Tibetan in Latin letters: bkra shis bde legs/ is བཀྲ་ཤིས་བདེ་ལེགས།. The converter follows the EWTS rules of The Tibetan and Himalayan Library.

Neither fails nor panics: what they cannot convert is copied as is, escaped or put in brackets, and reported in warnings (EwtsWarning, UnicodeWarning), sorted by position. The converter does not fix the input: if it is written incorrectly, the result has incorrect characters.

§Examples

let unicode = ewts::ewts_to_unicode("oM aHhU~M` badz+ra gu ru pad+ma sid+d+hi hU~M`:").unicode;
assert_eq!(unicode, "ཨོཾ་ཨཿཧཱུྂ་བཛྲ་གུ་རུ་པདྨ་སིདྡྷི་ཧཱུྂ༔");

// And back.
assert_eq!(ewts::unicode_to_ewts("བཀྲ་ཤིས་བདེ་ལེགས།").ewts, "bkra shis bde legs/");

// "q" is not EWTS.
for warning in ewts::ewts_to_unicode("kqa").warnings {
    assert_eq!(warning.to_string(), "not EWTS at byte 1: 'q'");
}

§Round trip

unicode_to_ewts gives EWTS that ewts_to_unicode converts back to the source text, unless there is a lossy warning: with SignOrder the signs of a stack come back in canonical order (ཀིྱ gives kyi, which gives ཀྱི), with NotEquivalent a char comes back as chars that are not canonically equivalent to it (ༀ gives oM, which gives ཨོཾ).

Precomposed chars come back as their canonically equivalent parts: གྷ (U+0F43) gives g+ha, which gives ག + ྷ. Non-Tibetan text is kept: ASCII other than line breaks and tabs is put in [...], other text stays as is.

The other way round is not guaranteed: EWTS has several spellings for the same text, and unicode_to_ewts gives the usual one (k+ya gives ཀྱ, which gives kya).

§Typographic apostrophes

ʼ ʹ ‘ ’ ʾ, which word processors often put instead of ', are read as ': ba’i gives བའི. Inside [...] they are kept as is. unicode_to_ewts puts them in brackets (ka[’]), so its result converts back exactly.

Structs§

EwtsToUnicode
The result of ewts_to_unicode.
EwtsWarning
A problem in the input of ewts_to_unicode.
UnicodeToEwts
The result of unicode_to_ewts.
UnicodeWarning
A problem in the input of unicode_to_ewts.

Enums§

EwtsWarningKind
What is wrong in the input of ewts_to_unicode.
UnicodeWarningKind
The kind of a UnicodeWarning from unicode_to_ewts.

Functions§

ewts_to_unicode
Converts EWTS to Tibetan Unicode, with warnings about input that is not valid EWTS.
unicode_to_ewts
Converts Tibetan Unicode to EWTS, with warnings about input that does not convert back exactly or looks broken. Without lossy warnings, converting the result back with ewts_to_unicode gives the source string; precomposed chars come back decomposed. See Round trip.