[][src]Function oem_cp::encode_string_lossy

pub fn encode_string_lossy<'a, T: Into<Cow<'a, str>>>(
    src: T,
    encoding_table: &AHashMap<char, u8>
) -> Vec<u8>

Encode Unicode string in SBCS (single byte character set)

Undefined codepoints are replaced with 0x3F (?).

Arguments

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

Examples

use oem_cp::encode_string_lossy;
use oem_cp::code_table::{ENCODING_TABLE_CP437, ENCODING_TABLE_CP737};
assert_eq!(encode_string_lossy("π≈22/7", &*ENCODING_TABLE_CP437), vec![0xE3, 0xF7, 0x32, 0x32, 0x2F, 0x37]);
// Archimedes in Greek
assert_eq!(encode_string_lossy("Αρχιμήδης", &*ENCODING_TABLE_CP737), vec![0x80, 0xA8, 0xAE, 0xA0, 0xA3, 0xE3, 0x9B, 0x9E, 0xAA]);
// Japanese characters are not defined in CP437 and replaced with `?` (0x3F)
// "日本語ja_jp" => "???ja_jp"
assert_eq!(encode_string_lossy("日本語ja_jp", &*ENCODING_TABLE_CP437), vec![0x3F, 0x3F, 0x3F, 0x6A, 0x61, 0x5F, 0x6A, 0x70]);