Skip to content

UTF_16BE encode decode result does not match  #104

Open
@liubaochuan

Description

@liubaochuan

rust version: rustc 1.80.0-nightly
encoding_rs version: 0.8.34

#[test]
fn test_utf16(){
    // UTF-8 字符串
    let utf8_string = "示例文本";
    // 将 UTF-8 字符串转换为 UTF-16BE 编码的字节向量
    let (utf16be_bytes, _, had_errors) = UTF_16BE.encode(utf8_string);
    println!("原始 UTF-8 字符串: {}", utf8_string);
    println!("UTF-16BE 编码的字节: {:?}", utf16be_bytes);
    // 将 UTF-16BE 编码的字节向量转换回 UTF-8 字符串
    let (decoded_utf8, _,_) = UTF_16BE.decode(&utf16be_bytes);
    println!("解码后的 UTF-8 字符串: {}", decoded_utf8);
}

result:
原始 UTF-8 字符串: 示例文本
UTF-16BE 编码的字节: [231, 164, 186, 228, 190, 139, 230, 150, 135, 230, 156, 172]
解码后的 UTF-8 字符串: 뫤뺋蟦鲬

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions