unicode

Branch: main

Switch branches or tags

Branch: main
Go to file t

413 files indexed

History
Code

ucd/east_asian_width.mbt
1///|2/// Unicode East_Asian_Width values3/// See UAX #11: https://www.unicode.org/reports/tr11/4#derive(Debug, Eq)5pub(all) enum EastAsianWidth {6  A // Ambiguous7  F // Fullwidth8  H // Halfwidth9  N // Neutral10  Na // Narrow11  W // Wide12}1314///|15#deprecated("Use `Debug::to_repr` instead", skip_current_package=true)16#doc(hidden)17pub extend EastAsianWidth with Debug::{to_repr}1819///|20pub extend EastAsianWidth with Eq::{not_equal, equal}2122///|23pub extend EastAsianWidth with Show::{to_string, output}2425///|26pub impl Show for EastAsianWidth with fn output(self, logger) {27  match self {28    A => logger.write_string("A")29    F => logger.write_string("F")30    H => logger.write_string("H")31    N => logger.write_string("N")32    Na => logger.write_string("Na")33    W => logger.write_string("W")34  }35}3637///|38/// Convert a EastAsianWidth ordinal, below 6, to the enum value.39///40/// A constructor without arguments is its ordinal on every backend. A41/// `match` or a table would cost a jump table or a load on wasm, wasm-gc42/// and JS, slower there than the trie lookup itself.43fn ordinal_to_eaw(ordinal : Int32) -> EastAsianWidth = "%identity"4445///|46/// Get the East_Asian_Width for a character.47///48/// East_Asian_Width classifies characters by the width they have in East49/// Asian typography. It is a property of a single character, not a column50/// count: nonspacing marks and control characters have a value too. Code51/// points the Unicode Character Database does not list are Neutral, except52/// that unassigned code points in the CJK ideograph blocks and in planes 253/// and 3 are Wide.54pub fn east_asian_width(c : Char) -> EastAsianWidth {55  ordinal_to_eaw(@east_asian_width.lookup_east_asian_width(c))56}57