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:
316 template <
size_t N>
struct ShiftedString {
319 constexpr ShiftedString(
char const (&Src)[N]) {
320 for (
size_t I = 0; I < N; ++I) {
322 throw "use U prefix for unicode string literals";
323 Str[I] = TranslateUnicode(Src[I]);
327 constexpr ShiftedString(char16_t
const (&Src)[N]) {
328 for (
size_t I = 0; I < N; ++I) {
329 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
330 throw "use U prefix for unicode string literals";
331 Str[I] = TranslateUnicode(Src[I]);
335 constexpr ShiftedString(char32_t
const (&Src)[N]) {
336 for (
size_t I = 0; I < N; ++I)
337 Str[I] = TranslateUnicode(Src[I]);
340 constexpr
char TranslateUnicode(char32_t C) {
346 case 0x0000 ... 0x001f:
616 template <
size_t N>
struct UnshiftedVideoString {
619 constexpr UnshiftedVideoString(
char const (&Src)[N]) {
620 for (
size_t I = 0; I < N; ++I) {
622 throw "use U prefix for unicode string literals";
623 Str[I] = TranslateUnicode(Src[I]);
627 constexpr UnshiftedVideoString(char16_t
const (&Src)[N]) {
628 for (
size_t I = 0; I < N; ++I) {
629 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
630 throw "use U prefix for unicode string literals";
631 Str[I] = TranslateUnicode(Src[I]);
635 constexpr UnshiftedVideoString(char32_t
const (&Src)[N]) {
636 for (
size_t I = 0; I < N; ++I)
637 Str[I] = TranslateUnicode(Src[I]);
640 constexpr
char TranslateUnicode(char32_t C) {
970 template <
size_t N>
struct UnshiftedReverseVideoString {
973 constexpr UnshiftedReverseVideoString(
char const (&Src)[N]) {
974 for (
size_t I = 0; I < N; ++I) {
976 throw "use U prefix for unicode string literals";
977 Str[I] = TranslateUnicode(Src[I]);
981 constexpr UnshiftedReverseVideoString(char16_t
const (&Src)[N]) {
982 for (
size_t I = 0; I < N; ++I) {
983 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
984 throw "use U prefix for unicode string literals";
985 Str[I] = TranslateUnicode(Src[I]);
989 constexpr UnshiftedReverseVideoString(char32_t
const (&Src)[N]) {
990 for (
size_t I = 0; I < N; ++I)
991 Str[I] = TranslateUnicode(Src[I]);
994 constexpr
char TranslateUnicode(char32_t C) {
1216 template <
size_t N>
struct ShiftedVideoString {
1219 constexpr ShiftedVideoString(
char const (&Src)[N]) {
1220 for (
size_t I = 0; I < N; ++I) {
1222 throw "use U prefix for unicode string literals";
1223 Str[I] = TranslateUnicode(Src[I]);
1227 constexpr ShiftedVideoString(char16_t
const (&Src)[N]) {
1228 for (
size_t I = 0; I < N; ++I) {
1229 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
1230 throw "use U prefix for unicode string literals";
1231 Str[I] = TranslateUnicode(Src[I]);
1235 constexpr ShiftedVideoString(char32_t
const (&Src)[N]) {
1236 for (
size_t I = 0; I < N; ++I)
1237 Str[I] = TranslateUnicode(Src[I]);
1240 constexpr
char TranslateUnicode(char32_t C) {
1243 throw "Unsupported";
1566 template <
size_t N>
struct ShiftedReverseVideoString {
1569 constexpr ShiftedReverseVideoString(
char const (&Src)[N]) {
1570 for (
size_t I = 0; I < N; ++I) {
1572 throw "use U prefix for unicode string literals";
1573 Str[I] = TranslateUnicode(Src[I]);
1577 constexpr ShiftedReverseVideoString(char16_t
const (&Src)[N]) {
1578 for (
size_t I = 0; I < N; ++I) {
1579 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
1580 throw "use U prefix for unicode string literals";
1581 Str[I] = TranslateUnicode(Src[I]);
1585 constexpr ShiftedReverseVideoString(char32_t
const (&Src)[N]) {
1586 for (
size_t I = 0; I < N; ++I)
1587 Str[I] = TranslateUnicode(Src[I]);
1590 constexpr
char TranslateUnicode(char32_t C) {
1593 throw "Unsupported";
1818 template <
charset_impl::UnshiftedString S> constexpr
auto operator""_u() {
1821 template <
charset_impl::ShiftedString S> constexpr
auto operator""_s() {
1825 template <
charset_impl::UnshiftedV
ideoString S> constexpr
auto operator""_uv() {
1829 template <
charset_impl::UnshiftedReverseV
ideoString S>
1830 constexpr
auto operator""_urv() {
1834 template <
charset_impl::ShiftedV
ideoString S> constexpr
auto operator""_sv() {
1838 template <
charset_impl::ShiftedReverseV
ideoString S>
1839 constexpr
auto operator""_srv() {
1843 #endif // not _CHARSET_H
1844 #endif // __cplusplus >= 202002L