Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UTF_16BE encode decode result does not match #104

Open
liubaochuan opened this issue May 23, 2024 · 0 comments
Open

UTF_16BE encode decode result does not match #104

liubaochuan opened this issue May 23, 2024 · 0 comments

Comments

@liubaochuan
Copy link

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 字符串: 뫤뺋蟦鲬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant