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:
318 template <
size_t N>
struct ShiftedString {
321 constexpr ShiftedString(
char const (&Src)[N]) {
322 for (
size_t I = 0; I < N; ++I) {
324 throw "use U prefix for unicode string literals";
325 Str[I] = TranslateUnicode(Src[I]);
329 constexpr ShiftedString(char16_t
const (&Src)[N]) {
330 for (
size_t I = 0; I < N; ++I) {
331 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
332 throw "use U prefix for unicode string literals";
333 Str[I] = TranslateUnicode(Src[I]);
337 constexpr ShiftedString(char32_t
const (&Src)[N]) {
338 for (
size_t I = 0; I < N; ++I)
339 Str[I] = TranslateUnicode(Src[I]);
342 constexpr
char TranslateUnicode(char32_t C) {
348 case 0x0000 ... 0x001f:
618 template <
size_t N>
struct UnshiftedVideoString {
621 constexpr UnshiftedVideoString(
char const (&Src)[N]) {
622 for (
size_t I = 0; I < N; ++I) {
624 throw "use U prefix for unicode string literals";
625 Str[I] = TranslateUnicode(Src[I]);
629 constexpr UnshiftedVideoString(char16_t
const (&Src)[N]) {
630 for (
size_t I = 0; I < N; ++I) {
631 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
632 throw "use U prefix for unicode string literals";
633 Str[I] = TranslateUnicode(Src[I]);
637 constexpr UnshiftedVideoString(char32_t
const (&Src)[N]) {
638 for (
size_t I = 0; I < N; ++I)
639 Str[I] = TranslateUnicode(Src[I]);
642 constexpr
char TranslateUnicode(char32_t C) {
974 template <
size_t N>
struct UnshiftedReverseVideoString {
977 constexpr UnshiftedReverseVideoString(
char const (&Src)[N]) {
978 for (
size_t I = 0; I < N; ++I) {
980 throw "use U prefix for unicode string literals";
981 Str[I] = TranslateUnicode(Src[I]);
985 constexpr UnshiftedReverseVideoString(char16_t
const (&Src)[N]) {
986 for (
size_t I = 0; I < N; ++I) {
987 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
988 throw "use U prefix for unicode string literals";
989 Str[I] = TranslateUnicode(Src[I]);
993 constexpr UnshiftedReverseVideoString(char32_t
const (&Src)[N]) {
994 for (
size_t I = 0; I < N; ++I)
995 Str[I] = TranslateUnicode(Src[I]);
998 constexpr
char TranslateUnicode(char32_t C) {
1001 throw "Unsupported";
1330 template <
size_t N>
struct ShiftedVideoString {
1333 constexpr ShiftedVideoString(
char const (&Src)[N]) {
1334 for (
size_t I = 0; I < N; ++I) {
1336 throw "use U prefix for unicode string literals";
1337 Str[I] = TranslateUnicode(Src[I]);
1341 constexpr ShiftedVideoString(char16_t
const (&Src)[N]) {
1342 for (
size_t I = 0; I < N; ++I) {
1343 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
1344 throw "use U prefix for unicode string literals";
1345 Str[I] = TranslateUnicode(Src[I]);
1349 constexpr ShiftedVideoString(char32_t
const (&Src)[N]) {
1350 for (
size_t I = 0; I < N; ++I)
1351 Str[I] = TranslateUnicode(Src[I]);
1354 constexpr
char TranslateUnicode(char32_t C) {
1357 throw "Unsupported";
1679 template <
size_t N>
struct ShiftedReverseVideoString {
1682 constexpr ShiftedReverseVideoString(
char const (&Src)[N]) {
1683 for (
size_t I = 0; I < N; ++I) {
1685 throw "use U prefix for unicode string literals";
1686 Str[I] = TranslateUnicode(Src[I]);
1690 constexpr ShiftedReverseVideoString(char16_t
const (&Src)[N]) {
1691 for (
size_t I = 0; I < N; ++I) {
1692 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
1693 throw "use U prefix for unicode string literals";
1694 Str[I] = TranslateUnicode(Src[I]);
1698 constexpr ShiftedReverseVideoString(char32_t
const (&Src)[N]) {
1699 for (
size_t I = 0; I < N; ++I)
1700 Str[I] = TranslateUnicode(Src[I]);
1703 constexpr
char TranslateUnicode(char32_t C) {
1706 throw "Unsupported";
2031 template <
charset_impl::UnshiftedString S> constexpr
auto operator""_u() {
2035 template <
charset_impl::ShiftedString S> constexpr
auto operator""_s() {
2039 template <
charset_impl::UnshiftedV
ideoString S> constexpr
auto operator""_uv() {
2043 template <
charset_impl::UnshiftedReverseV
ideoString S>
2044 constexpr
auto operator""_urv() {
2048 template <
charset_impl::ShiftedV
ideoString S> constexpr
auto operator""_sv() {
2052 template <
charset_impl::ShiftedReverseV
ideoString S>
2053 constexpr
auto operator""_srv() {
2057 #endif // not _CHARSET_H
2058 #endif // __cplusplus >= 202002L