#include "nls.h" #include "nls-cp1252.h" #include "nls-sbcs.h" #include #include namespace raven { const NativeSingleBytePage *native_single_byte_page(uint32_t code_page) { for (const auto &page : native_single_byte_pages) if (page.id==code_page) return &page; return nullptr; } std::u16string decode_single_byte(const NativeSingleBytePage &page,std::string_view text) { std::u16string result; result.reserve(text.size()); for (const auto byte : text) result.push_back(char16_t(page.bytes[static_cast(byte)])); return result; } int encode_single_byte(const NativeSingleBytePage &page,char16_t character,bool exact) { const auto end=page.best_fit+page.best_fit_count; const auto found=std::lower_bound(page.best_fit,end,uint16_t(character), [](const std::array &entry,uint16_t value) { return entry[0](byte)); } return result; } if (code_page!=1252) throw std::runtime_error("unsupported native ANSI code page"); for (const auto character : text) result.push_back(static_cast(native_cp1252[character])); return result; } }