#include <catch2/catch_test_macros.hpp>
#include <bit>
TEST_CASE("Empty string to BOM", "[Z]")
{
}
TEST_CASE("String to utf-8 vs stringview to utf-8", "[S]")
{
using namespace std::literals;
wchar_t wstr[] = L"一律轉成 utf-8";
for (auto &ch: wstr)
ch = std::byteswap(ch);
char32_t u32str[] = U"一律轉成 utf-8";
for (auto &ch: u32str)
ch = std::byteswap(ch);
char16_t u16str[] = u"一律轉成 utf-8";
#ifndef _WIN32
static constinit const char *const CHSETS_UTF16LE[] = {"UTF-16LE", "UTF16LE", "UCS-2LE", "USC2LE", 0};
CHECK(
bux::to_utf8(u16str, 0, CHSETS_UTF16LE) == (
const char*)u8
"一律轉成 utf-8");
#ifdef INDEFINITE_UTF16_
static constinit const char *const CHSETS_UTF16[] = {"UCS-2", "UTF-16", "USC2", "UTF16", 0};
CHECK(
bux::to_utf8(u16str, 0, CHSETS_UTF16) == (
const char*)u8
"一律轉成 utf-8");
#endif
CHECK(
bux::to_utf8(bomed_u16str) == (
const char*)u8
"一律轉成 utf-8");
#endif
#ifdef INDEFINITE_UTF16_
#endif
for (auto &ch: u16str)
ch = std::byteswap(ch);
for (auto &ch: bomed_u16str)
ch = std::byteswap(ch);
#ifndef _WIN32
#ifdef INDEFINITE_UTF16_
static constinit const char *const CHSETS_UTF16BE[] = {"UTF-16BE", "UTF16BE", "UCS-2BE", "USC2BE", 0};
CHECK(
bux::to_utf8(u16str, 0, CHSETS_UTF16BE) == (
const char*)u8
"一律轉成 utf-8");
#endif
CHECK(
bux::to_utf8(bomed_u16str) == (
const char*)u8
"一律轉成 utf-8");
#endif
#ifdef INDEFINITE_UTF16_
#endif
CHECK(
bux::to_utf8(u8
"一律轉成 utf-8") == (
const char*)u8
"一律轉成 utf-8");
CHECK(
bux::to_utf8(u8
"一律轉成 utf-8"s) == (
const char*)u8
"一律轉成 utf-8");
CHECK(
bux::to_utf8(u8
"一律轉成 utf-8"sv) == (
const char*)u8
"一律轉成 utf-8");
CHECK(
bux::to_utf8(
"一律轉成 utf-8") == (
const char*)u8
"一律轉成 utf-8");
CHECK(
bux::to_utf8(
"一律轉成 utf-8"s) == (
const char*)u8
"一律轉成 utf-8");
CHECK(
bux::to_utf8(
"一律轉成 utf-8"sv) == (
const char*)u8
"一律轉成 utf-8");
}
std::string_view to_utf8(T_Utf32 uc)
const T_Encoding ENCODING_UTF8
std::basic_string< T > BOM(std::basic_string_view< T > sv)