Expand description
§Chinese Telegraph Code
This crate provides utilities for converting Unicode Chinese characters to Chinese telegraph codes.
Chinese telegraph codes are numerical codes used historically for transmitting Chinese text over telegraph systems. This crate supports both Traditional Chinese (Taiwan) and Simplified Chinese character sets.
§Features
- Convert Chinese characters to telegraph codes
- Support for both Traditional and Simplified Chinese
no_stdcompatible (with optionalstdfeature for string formatting)- Fast lookups using perfect hash functions
§Usage
use chinese_telegraph::{to_telegraph, to_telegraph_string, Table};
// Look up a Traditional Chinese character
let code = to_telegraph("這", Table::TW);
assert_eq!(code, Some(6638));
// Look up a Simplified Chinese character
let code = to_telegraph("这", Table::CN);
assert_eq!(code, Some(6638));
// Search both tables
let code = to_telegraph("一", Table::Both);
assert_eq!(code, Some(1));
// Format as a 4-digit string (requires std feature)
let formatted = to_telegraph_string("一", Table::Both);
assert_eq!(formatted, Some("0001".to_string()));Enums§
- Table
- Specifies which character table(s) to use for telegraph code lookup.
Functions§
- to_
telegraph - Converts a Chinese character to its telegraph code.
- to_
telegraph_ string std - Converts a Chinese character to its telegraph code formatted as a 4-digit string.