6 #if __cplusplus < 202002L
7 #error charset support requies C++20
14 namespace charset_impl {
16 template <
size_t N>
struct AtasciiString {
19 constexpr AtasciiString(
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 AtasciiString(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 AtasciiString(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 AtasciiInternationalString {
321 constexpr AtasciiInternationalString(
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 AtasciiInternationalString(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 AtasciiInternationalString(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:
602 template <
size_t N>
struct AtasciiVideoString {
605 constexpr AtasciiVideoString(
char const (&Src)[N]) {
606 for (
size_t I = 0; I < N; ++I) {
608 throw "use U prefix for unicode string literals";
609 Str[I] = TranslateUnicode(Src[I]);
613 constexpr AtasciiVideoString(char16_t
const (&Src)[N]) {
614 for (
size_t I = 0; I < N; ++I) {
615 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
616 throw "use U prefix for unicode string literals";
617 Str[I] = TranslateUnicode(Src[I]);
621 constexpr AtasciiVideoString(char32_t
const (&Src)[N]) {
622 for (
size_t I = 0; I < N; ++I)
623 Str[I] = TranslateUnicode(Src[I]);
626 constexpr
char TranslateUnicode(char32_t C) {
920 template <
size_t N>
struct AtasciiReverseVideoString {
923 constexpr AtasciiReverseVideoString(
char const (&Src)[N]) {
924 for (
size_t I = 0; I < N; ++I) {
926 throw "use U prefix for unicode string literals";
927 Str[I] = TranslateUnicode(Src[I]);
931 constexpr AtasciiReverseVideoString(char16_t
const (&Src)[N]) {
932 for (
size_t I = 0; I < N; ++I) {
933 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
934 throw "use U prefix for unicode string literals";
935 Str[I] = TranslateUnicode(Src[I]);
939 constexpr AtasciiReverseVideoString(char32_t
const (&Src)[N]) {
940 for (
size_t I = 0; I < N; ++I)
941 Str[I] = TranslateUnicode(Src[I]);
944 constexpr
char TranslateUnicode(char32_t C) {
1202 template <
size_t N>
struct AtasciiInternationalVideoString {
1205 constexpr AtasciiInternationalVideoString(
char const (&Src)[N]) {
1206 for (
size_t I = 0; I < N; ++I) {
1208 throw "use U prefix for unicode string literals";
1209 Str[I] = TranslateUnicode(Src[I]);
1213 constexpr AtasciiInternationalVideoString(char16_t
const (&Src)[N]) {
1214 for (
size_t I = 0; I < N; ++I) {
1215 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
1216 throw "use U prefix for unicode string literals";
1217 Str[I] = TranslateUnicode(Src[I]);
1221 constexpr AtasciiInternationalVideoString(char32_t
const (&Src)[N]) {
1222 for (
size_t I = 0; I < N; ++I)
1223 Str[I] = TranslateUnicode(Src[I]);
1226 constexpr
char TranslateUnicode(char32_t C) {
1229 throw "Unsupported";
1502 template <
size_t N>
struct AtasciiInternationalReverseVideoString {
1505 constexpr AtasciiInternationalReverseVideoString(
char const (&Src)[N]) {
1506 for (
size_t I = 0; I < N; ++I) {
1508 throw "use U prefix for unicode string literals";
1509 Str[I] = TranslateUnicode(Src[I]);
1513 constexpr AtasciiInternationalReverseVideoString(char16_t
const (&Src)[N]) {
1514 for (
size_t I = 0; I < N; ++I) {
1515 if (Src[I] >= 0xD800 && Src[I] <= 0xDFFF)
1516 throw "use U prefix for unicode string literals";
1517 Str[I] = TranslateUnicode(Src[I]);
1521 constexpr AtasciiInternationalReverseVideoString(char32_t
const (&Src)[N]) {
1522 for (
size_t I = 0; I < N; ++I)
1523 Str[I] = TranslateUnicode(Src[I]);
1526 constexpr
char TranslateUnicode(char32_t C) {
1529 throw "Unsupported";
1804 template <
charset_impl::AtasciiString S> constexpr
auto operator""_a() {
1807 template <
charset_impl::AtasciiInternationalString S> constexpr
auto operator""_i() {
1811 template <
charset_impl::AtasciiV
ideoString S> constexpr
auto operator""_av() {
1815 template <
charset_impl::AtasciiReverseV
ideoString S>
1816 constexpr
auto operator""_arv() {
1820 template <
charset_impl::AtasciiInternationalV
ideoString S> constexpr
auto operator""_iv() {
1824 template <
charset_impl::AtasciiInternationalReverseV
ideoString S>
1825 constexpr
auto operator""_irv() {
1829 #endif // not _CHARSET_H
1830 #endif // __cplusplus >= 202002L