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.
ewts_to_unicodeconverts EWTS to Unicode and returnsEwtsToUnicode.unicode_to_ewtsconverts Unicode to EWTS and returnsUnicodeToEwts.
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§
- Ewts
ToUnicode - The result of
ewts_to_unicode. - Ewts
Warning - A problem in the input of
ewts_to_unicode. - Unicode
ToEwts - The result of
unicode_to_ewts. - Unicode
Warning - A problem in the input of
unicode_to_ewts.
Enums§
- Ewts
Warning Kind - What is wrong in the input of
ewts_to_unicode. - Unicode
Warning Kind - The kind of a
UnicodeWarningfromunicode_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_unicodegives the source string; precomposed chars come back decomposed. See Round trip.