pub fn encode_string_checked<'a, T: Into<Cow<'a, str>>>(
    src: T,
    encoding_table: &OEMCPHashMap<char, u8>
) -> Option<Vec<u8>>
Expand description

Encode Unicode string in SBCS (single byte character set)

If some undefined codepoints are found, returns None.

Arguments

  • src - Unicode string
  • encoding_table - table for encoding in SBCS

Examples

use oem_cp::encode_string_checked;
use oem_cp::code_table::{ENCODING_TABLE_CP437, ENCODING_TABLE_CP737};
assert_eq!(encode_string_checked("π≈22/7", &ENCODING_TABLE_CP437), Some(vec![0xE3, 0xF7, 0x32, 0x32, 0x2F, 0x37]));
// Archimedes in Greek
assert_eq!(encode_string_checked("Αρχιμήδης", &ENCODING_TABLE_CP737), Some(vec![0x80, 0xA8, 0xAE, 0xA0, 0xA3, 0xE3, 0x9B, 0x9E, 0xAA]));
// Japanese characters are not defined in CP437
assert_eq!(encode_string_checked("日本語ja_jp", &ENCODING_TABLE_CP437), None);