30 lines
1.4 KiB
C++
30 lines
1.4 KiB
C++
#pragma once
|
|
// Windows ANSI code pages without the host iconv: MultiByteToWideChar / WideCharToMultiByte semantics
|
|
// driven by Microsoft's WindowsBestFit tables (scripts/gen_codepage_tables.py). One implementation for
|
|
// macOS, Linux, Android and iOS, so every platform decodes the 40250 locale and wire text the same way.
|
|
//
|
|
// Covered: 874, 932, 936, 949, 950, 1250-1258 (every code page 40250 EterLib/Util.cpp names).
|
|
// UTF-8 is not handled here.
|
|
|
|
#include <cstddef>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace mt_codepage {
|
|
|
|
bool supported(unsigned cp);
|
|
|
|
// Byte string -> code points, as MultiByteToWideChar. A lead byte takes the next non-NUL byte as its
|
|
// trail; an unmapped byte or pair becomes the code page's default char (U+30FB for 932, else '?').
|
|
// Returns false when a default char was substituted (MB_ERR_INVALID_CHARS would fail).
|
|
bool decode(unsigned cp, const unsigned char* p, size_t n, std::u32string& out);
|
|
|
|
// Code points -> bytes, as WideCharToMultiByte. With best_fit (no WC_NO_BEST_FIT_CHARS) a character
|
|
// without an exact mapping may take its WCTABLE best fit ("Ā" -> "A" on 1252); otherwise, and for
|
|
// anything unmapped, '?' is written and *used_default set.
|
|
void encode(unsigned cp, std::u32string_view in, std::string& out, bool best_fit, bool* used_default);
|
|
|
|
bool is_lead_byte(unsigned cp, unsigned char b);
|
|
|
|
} // namespace mt_codepage
|