-
Notifications
You must be signed in to change notification settings - Fork 55
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_16LE.encode does not encode string to UTF-16 LE correctly? #31
Comments
This is expected documented behavior. The lack of UTF-16LE/BE encoders is mentioned in the rustdocs (also at the top of the docs for See also this tweet and the follow-up tweet. |
Note that the phenomenon you discovered is precisely why the |
Thank you for response. |
Got bit by this thinking that *: when using different APIs like Note that I'm using encoding_rs in a non-browser context. So I can't take the position that other encodings just shouldn't be used. I do however respect that as the stance of this project! |
Yes, the behavior arising the from the "output encoding" concept in the Encoding Standard is probably surprising (but documented!) when applied to situations other that URL parsing and HTML form submission. Still, as documented, this while this crate has non-Web secondary uses, the design follows the Encoding Standard to the point that secondary things like mappings from Windows code page numbers are outside this crate. As noted earlier, for non-Web uses that for legacy reasons require UTF-16LE or UTF-16BE output to be generated to conform to format that requires either UTF-16LE or UTF-16BE (so that using UTF-8 doesn't work), there seems to be a need in the Rust ecosystem for a crate for that purpose. However, this crate is not that crate. Notably, such functionality is unlikely to need to fit into the |
Right. The issue I raised is that certain APIs don't communicate output encoding AFAIU, like Besides that, (Taken from my project) fn encode_utf16<B>(buf: &mut Vec<u8>, s: &str)
where
B: byteorder::ByteOrder,
{
for c in s.encode_utf16() {
buf.extend(std::iter::repeat(0x0).take(2));
let s = buf.len() - 2;
B::write_u16(&mut buf[s..], c);
}
} |
Environment
rustc --version
output:and my encoding_rs version is
0.7.2
.Steps to reproduce
run the following program
Expected
output following text
Actual
output following text(24929 = 0x6161)
The text was updated successfully, but these errors were encountered: