6 #if __cplusplus < 202002L
7 #error charset support requies C++20
14 namespace charset_impl {
16 template <
size_t N>
struct UnshiftedString {
19 constexpr UnshiftedString(
char const (&Src)[N]) {
20 for (
size_t I = 0; I < N; ++I) {
22 throw "use U prefix for unicode string literals";
23 Str[I] = TranslateUnicode(Src[I]);
27 constexpr UnshiftedString(char16_t
const (&Src)[N]) {
28 for (
size_t I = 0; I < N; ++I) {
29 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
30 throw "use U prefix for unicode string literals";
31 Str[I] = TranslateUnicode(Src[I]);
35 constexpr UnshiftedString(char32_t
const (&Src)[N]) {
36 for (
size_t I = 0; I < N; ++I)
37 Str[I] = TranslateUnicode(Src[I]);
40 constexpr
char TranslateUnicode(char32_t C) {
46 case 0x0000 ... 0x001f:
320 template <
size_t N>
struct ShiftedString {
323 constexpr ShiftedString(
char const (&Src)[N]) {
324 for (
size_t I = 0; I < N; ++I) {
326 throw "use U prefix for unicode string literals";
327 Str[I] = TranslateUnicode(Src[I]);
331 constexpr ShiftedString(char16_t
const (&Src)[N]) {
332 for (
size_t I = 0; I < N; ++I) {
333 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
334 throw "use U prefix for unicode string literals";
335 Str[I] = TranslateUnicode(Src[I]);
339 constexpr ShiftedString(char32_t
const (&Src)[N]) {
340 for (
size_t I = 0; I < N; ++I)
341 Str[I] = TranslateUnicode(Src[I]);
344 constexpr
char TranslateUnicode(char32_t C) {
350 case 0x0000 ... 0x001f:
620 template <
size_t N>
struct UnshiftedVideoString {
623 constexpr UnshiftedVideoString(
char const (&Src)[N]) {
624 for (
size_t I = 0; I < N; ++I) {
626 throw "use U prefix for unicode string literals";
627 Str[I] = TranslateUnicode(Src[I]);
631 constexpr UnshiftedVideoString(char16_t
const (&Src)[N]) {
632 for (
size_t I = 0; I < N; ++I) {
633 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
634 throw "use U prefix for unicode string literals";
635 Str[I] = TranslateUnicode(Src[I]);
639 constexpr UnshiftedVideoString(char32_t
const (&Src)[N]) {
640 for (
size_t I = 0; I < N; ++I)
641 Str[I] = TranslateUnicode(Src[I]);
644 constexpr
char TranslateUnicode(char32_t C) {
976 template <
size_t N>
struct UnshiftedReverseVideoString {
979 constexpr UnshiftedReverseVideoString(
char const (&Src)[N]) {
980 for (
size_t I = 0; I < N; ++I) {
982 throw "use U prefix for unicode string literals";
983 Str[I] = TranslateUnicode(Src[I]);
987 constexpr UnshiftedReverseVideoString(char16_t
const (&Src)[N]) {
988 for (
size_t I = 0; I < N; ++I) {
989 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
990 throw "use U prefix for unicode string literals";
991 Str[I] = TranslateUnicode(Src[I]);
995 constexpr UnshiftedReverseVideoString(char32_t
const (&Src)[N]) {
996 for (
size_t I = 0; I < N; ++I)
997 Str[I] = TranslateUnicode(Src[I]);
1000 constexpr
char TranslateUnicode(char32_t C) {
1003 throw "Unsupported";
1332 template <
size_t N>
struct ShiftedVideoString {
1335 constexpr ShiftedVideoString(
char const (&Src)[N]) {
1336 for (
size_t I = 0; I < N; ++I) {
1338 throw "use U prefix for unicode string literals";
1339 Str[I] = TranslateUnicode(Src[I]);
1343 constexpr ShiftedVideoString(char16_t
const (&Src)[N]) {
1344 for (
size_t I = 0; I < N; ++I) {
1345 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
1346 throw "use U prefix for unicode string literals";
1347 Str[I] = TranslateUnicode(Src[I]);
1351 constexpr ShiftedVideoString(char32_t
const (&Src)[N]) {
1352 for (
size_t I = 0; I < N; ++I)
1353 Str[I] = TranslateUnicode(Src[I]);
1356 constexpr
char TranslateUnicode(char32_t C) {
1359 throw "Unsupported";
1682 template <
size_t N>
struct ShiftedReverseVideoString {
1685 constexpr ShiftedReverseVideoString(
char const (&Src)[N]) {
1686 for (
size_t I = 0; I < N; ++I) {
1688 throw "use U prefix for unicode string literals";
1689 Str[I] = TranslateUnicode(Src[I]);
1693 constexpr ShiftedReverseVideoString(char16_t
const (&Src)[N]) {
1694 for (
size_t I = 0; I < N; ++I) {
1695 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
1696 throw "use U prefix for unicode string literals";
1697 Str[I] = TranslateUnicode(Src[I]);
1701 constexpr ShiftedReverseVideoString(char32_t
const (&Src)[N]) {
1702 for (
size_t I = 0; I < N; ++I)
1703 Str[I] = TranslateUnicode(Src[I]);
1706 constexpr
char TranslateUnicode(char32_t C) {
1709 throw "Unsupported";
2034 template <
charset_impl::UnshiftedString S> constexpr
auto operator""_u() {
2037 template <
charset_impl::ShiftedString S> constexpr
auto operator""_s() {
2041 template <
charset_impl::UnshiftedV
ideoString S> constexpr
auto operator""_uv() {
2045 template <
charset_impl::UnshiftedReverseV
ideoString S>
2046 constexpr
auto operator""_urv() {
2050 template <
charset_impl::ShiftedV
ideoString S> constexpr
auto operator""_sv() {
2054 template <
charset_impl::ShiftedReverseV
ideoString S>
2055 constexpr
auto operator""_srv() {
2059 #endif // not _CHARSET_H
2060 #endif // __cplusplus >= 202002L