-
-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
When encoding to UTF-16 BE using basic_utf16_be<char> and an error occurs (requiring the replacement character U+FFFD), the replacement is output in little-endian byte order instead of big-endian.
Repro:
#include <ztd/text.hpp>
#include <span>
#include <iostream>
#include <iomanip>
int main() {
// Truncated UTF-8 sequence (incomplete 3-byte sequence for '中')
std::string input = "\xe4\xb8"; // Missing third byte
std::span<const char> input_span(input.data(), input.size());
// Transcode to UTF-16 BE - the truncated input causes a decode error,
// which should insert replacement character U+FFFD
auto result = ztd::text::transcode(input_span,
ztd::text::compat_utf8,
ztd::text::basic_utf16_be<char>{},
ztd::text::replacement_handler);
std::cout << "Result bytes: ";
for (unsigned char b : result) {
std::cout << std::hex << std::setfill('0') << std::setw(2) << (int)b << " ";
}
std::cout << std::endl;
// Expected (U+FFFD in big-endian): ff fd
// Actual (before fix): fd ff <-- WRONG! Native little-endian byte order
return 0;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels