| 1 |
/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */ |
| 2 |
|
| 3 |
#ifndef MPT_STRING_TRANSCODE_TRANSCODE_HPP |
| 4 |
#define MPT_STRING_TRANSCODE_TRANSCODE_HPP |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "mpt/base/detect.hpp" |
| 9 |
#include "mpt/base/integer.hpp" |
| 10 |
#include "mpt/base/macros.hpp" |
| 11 |
#include "mpt/base/namespace.hpp" |
| 12 |
#include "mpt/base/saturate_cast.hpp" |
| 13 |
#include "mpt/detect/mfc.hpp" |
| 14 |
#include "mpt/out_of_memory/out_of_memory.hpp" |
| 15 |
#include "mpt/string/types.hpp" |
| 16 |
#include "mpt/string/utility.hpp" |
| 17 |
|
| 18 |
#include <array> |
| 19 |
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 20 |
#include <locale> |
| 21 |
#endif // !MPT_COMPILER_QUIRK_NO_WCHAR |
| 22 |
#include <optional> |
| 23 |
#include <stdexcept> |
| 24 |
#include <string> |
| 25 |
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 26 |
#include <type_traits> |
| 27 |
#endif // !MPT_COMPILER_QUIRK_NO_WCHAR |
| 28 |
#include <utility> |
| 29 |
#include <vector> |
| 30 |
|
| 31 |
#include <cstddef> |
| 32 |
|
| 33 |
#if MPT_OS_DJGPP |
| 34 |
#include <cstring> |
| 35 |
#endif // MPT_OS_DJGPP |
| 36 |
|
| 37 |
#if MPT_OS_WINDOWS |
| 38 |
#include <windows.h> |
| 39 |
#endif // MPT_OS_WINDOWS |
| 40 |
|
| 41 |
#if MPT_OS_DJGPP |
| 42 |
#include <dpmi.h> |
| 43 |
#endif // MPT_OS_DJGPP |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
namespace mpt { |
| 48 |
inline namespace MPT_INLINE_NS { |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
inline constexpr char32_t UCS4ud = 0xffffffffu; |
| 55 |
|
| 56 |
// default 1:1 mapping |
| 57 |
inline constexpr char32_t CharsetTableISO8859_1[256] = { |
| 58 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 59 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 60 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 61 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 62 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 63 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 64 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 65 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 66 |
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, |
| 67 |
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, |
| 68 |
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, |
| 69 |
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, |
| 70 |
0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, |
| 71 |
0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, |
| 72 |
0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, |
| 73 |
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff}; |
| 74 |
|
| 75 |
inline constexpr char32_t CharsetTableISO8859_15[256] = { |
| 76 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 77 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 78 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 79 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 80 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 81 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 82 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 83 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 84 |
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, |
| 85 |
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, |
| 86 |
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x20ac, 0x00a5, 0x0160, 0x00a7, 0x0161, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, |
| 87 |
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x017d, 0x00b5, 0x00b6, 0x00b7, 0x017e, 0x00b9, 0x00ba, 0x00bb, 0x0152, 0x0153, 0x0178, 0x00bf, |
| 88 |
0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, |
| 89 |
0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, |
| 90 |
0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, |
| 91 |
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff}; |
| 92 |
|
| 93 |
inline constexpr char32_t CharsetTableWindows1252[256] = { |
| 94 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 95 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 96 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 97 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 98 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 99 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 100 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 101 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 102 |
0x20ac, 0x0081, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008d, 0x017d, 0x008f, |
| 103 |
0x0090, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x009d, 0x017e, 0x0178, |
| 104 |
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, |
| 105 |
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, |
| 106 |
0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, |
| 107 |
0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, |
| 108 |
0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, |
| 109 |
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff}; |
| 110 |
|
| 111 |
// cat CP437.TXT | grep -v '^#' | head -n 256 | awk '{print $2;}' | ./tablerize.py > cp437.h |
| 112 |
/* |
| 113 |
#!/usr/bin/env python3 |
| 114 |
|
| 115 |
import fileinput |
| 116 |
|
| 117 |
i = 0 |
| 118 |
for line in fileinput.input(): |
| 119 |
if i % 16 == 0: |
| 120 |
print("\t", end='') |
| 121 |
print(line.strip(), end='') |
| 122 |
i = i + 1 |
| 123 |
if i % 256 != 0: |
| 124 |
print(",", end='') |
| 125 |
if i % 16 != 0: |
| 126 |
print(" ", end='') |
| 127 |
if i % 16 == 0: |
| 128 |
if i % 256 == 0: |
| 129 |
print("};\n", end='') |
| 130 |
else: |
| 131 |
print("\n", end='') |
| 132 |
*/ |
| 133 |
|
| 134 |
inline constexpr char32_t CharsetTableCP437[256] = { |
| 135 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 136 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 137 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 138 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 139 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 140 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 141 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 142 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 143 |
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5, |
| 144 |
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, 0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192, |
| 145 |
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, |
| 146 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, |
| 147 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, |
| 148 |
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, |
| 149 |
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, |
| 150 |
0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0}; |
| 151 |
|
| 152 |
inline constexpr char32_t CharsetTableCP737[256] = { |
| 153 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 154 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 155 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 156 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 157 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 158 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 159 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 160 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 161 |
0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 0x039e, 0x039f, 0x03a0, |
| 162 |
0x03a1, 0x03a3, 0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x03b1, 0x03b2, 0x03b3, 0x03b4, 0x03b5, 0x03b6, 0x03b7, 0x03b8, |
| 163 |
0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, 0x03c0, 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, |
| 164 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, |
| 165 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, |
| 166 |
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, |
| 167 |
0x03c9, 0x03ac, 0x03ad, 0x03ae, 0x03ca, 0x03af, 0x03cc, 0x03cd, 0x03cb, 0x03ce, 0x0386, 0x0388, 0x0389, 0x038a, 0x038c, 0x038e, |
| 168 |
0x038f, 0x00b1, 0x2265, 0x2264, 0x03aa, 0x03ab, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0}; |
| 169 |
|
| 170 |
inline constexpr char32_t CharsetTableCP775[256] = { |
| 171 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 172 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 173 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 174 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 175 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 176 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 177 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 178 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 179 |
0x0106, 0x00fc, 0x00e9, 0x0101, 0x00e4, 0x0123, 0x00e5, 0x0107, 0x0142, 0x0113, 0x0156, 0x0157, 0x012b, 0x0179, 0x00c4, 0x00c5, |
| 180 |
0x00c9, 0x00e6, 0x00c6, 0x014d, 0x00f6, 0x0122, 0x00a2, 0x015a, 0x015b, 0x00d6, 0x00dc, 0x00f8, 0x00a3, 0x00d8, 0x00d7, 0x00a4, |
| 181 |
0x0100, 0x012a, 0x00f3, 0x017b, 0x017c, 0x017a, 0x201d, 0x00a6, 0x00a9, 0x00ae, 0x00ac, 0x00bd, 0x00bc, 0x0141, 0x00ab, 0x00bb, |
| 182 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010c, 0x0118, 0x0116, 0x2563, 0x2551, 0x2557, 0x255d, 0x012e, 0x0160, 0x2510, |
| 183 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x0172, 0x016a, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x017d, |
| 184 |
0x0105, 0x010d, 0x0119, 0x0117, 0x012f, 0x0161, 0x0173, 0x016b, 0x017e, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, |
| 185 |
0x00d3, 0x00df, 0x014c, 0x0143, 0x00f5, 0x00d5, 0x00b5, 0x0144, 0x0136, 0x0137, 0x013b, 0x013c, 0x0146, 0x0112, 0x0145, 0x2019, |
| 186 |
0x00ad, 0x00b1, 0x201c, 0x00be, 0x00b6, 0x00a7, 0x00f7, 0x201e, 0x00b0, 0x2219, 0x00b7, 0x00b9, 0x00b3, 0x00b2, 0x25a0, 0x00a0}; |
| 187 |
|
| 188 |
inline constexpr char32_t CharsetTableCP850[256] = { |
| 189 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 190 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 191 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 192 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 193 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 194 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 195 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 196 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 197 |
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5, |
| 198 |
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, 0x00ff, 0x00d6, 0x00dc, 0x00f8, 0x00a3, 0x00d8, 0x00d7, 0x0192, |
| 199 |
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x00ae, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, |
| 200 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00c1, 0x00c2, 0x00c0, 0x00a9, 0x2563, 0x2551, 0x2557, 0x255d, 0x00a2, 0x00a5, 0x2510, |
| 201 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x00e3, 0x00c3, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x00a4, |
| 202 |
0x00f0, 0x00d0, 0x00ca, 0x00cb, 0x00c8, 0x0131, 0x00cd, 0x00ce, 0x00cf, 0x2518, 0x250c, 0x2588, 0x2584, 0x00a6, 0x00cc, 0x2580, |
| 203 |
0x00d3, 0x00df, 0x00d4, 0x00d2, 0x00f5, 0x00d5, 0x00b5, 0x00fe, 0x00de, 0x00da, 0x00db, 0x00d9, 0x00fd, 0x00dd, 0x00af, 0x00b4, |
| 204 |
0x00ad, 0x00b1, 0x2017, 0x00be, 0x00b6, 0x00a7, 0x00f7, 0x00b8, 0x00b0, 0x00a8, 0x00b7, 0x00b9, 0x00b3, 0x00b2, 0x25a0, 0x00a0}; |
| 205 |
|
| 206 |
inline constexpr char32_t CharsetTableCP852[256] = { |
| 207 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 208 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 209 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 210 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 211 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 212 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 213 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 214 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 215 |
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x016f, 0x0107, 0x00e7, 0x0142, 0x00eb, 0x0150, 0x0151, 0x00ee, 0x0179, 0x00c4, 0x0106, |
| 216 |
0x00c9, 0x0139, 0x013a, 0x00f4, 0x00f6, 0x013d, 0x013e, 0x015a, 0x015b, 0x00d6, 0x00dc, 0x0164, 0x0165, 0x0141, 0x00d7, 0x010d, |
| 217 |
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x0104, 0x0105, 0x017d, 0x017e, 0x0118, 0x0119, 0x00ac, 0x017a, 0x010c, 0x015f, 0x00ab, 0x00bb, |
| 218 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00c1, 0x00c2, 0x011a, 0x015e, 0x2563, 0x2551, 0x2557, 0x255d, 0x017b, 0x017c, 0x2510, |
| 219 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x0102, 0x0103, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x00a4, |
| 220 |
0x0111, 0x0110, 0x010e, 0x00cb, 0x010f, 0x0147, 0x00cd, 0x00ce, 0x011b, 0x2518, 0x250c, 0x2588, 0x2584, 0x0162, 0x016e, 0x2580, |
| 221 |
0x00d3, 0x00df, 0x00d4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161, 0x0154, 0x00da, 0x0155, 0x0170, 0x00fd, 0x00dd, 0x0163, 0x00b4, |
| 222 |
0x00ad, 0x02dd, 0x02db, 0x02c7, 0x02d8, 0x00a7, 0x00f7, 0x00b8, 0x00b0, 0x00a8, 0x02d9, 0x0171, 0x0158, 0x0159, 0x25a0, 0x00a0}; |
| 223 |
|
| 224 |
inline constexpr char32_t CharsetTableCP855[256] = { |
| 225 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 226 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 227 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 228 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 229 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 230 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 231 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 232 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 233 |
0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404, 0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408, |
| 234 |
0x0459, 0x0409, 0x045a, 0x040a, 0x045b, 0x040b, 0x045c, 0x040c, 0x045e, 0x040e, 0x045f, 0x040f, 0x044e, 0x042e, 0x044a, 0x042a, |
| 235 |
0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414, 0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00ab, 0x00bb, |
| 236 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438, 0x0418, 0x2563, 0x2551, 0x2557, 0x255d, 0x0439, 0x0419, 0x2510, |
| 237 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x043a, 0x041a, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x00a4, |
| 238 |
0x043b, 0x041b, 0x043c, 0x041c, 0x043d, 0x041d, 0x043e, 0x041e, 0x043f, 0x2518, 0x250c, 0x2588, 0x2584, 0x041f, 0x044f, 0x2580, |
| 239 |
0x042f, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443, 0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044c, 0x042c, 0x2116, |
| 240 |
0x00ad, 0x044b, 0x042b, 0x0437, 0x0417, 0x0448, 0x0428, 0x044d, 0x042d, 0x0449, 0x0429, 0x0447, 0x0427, 0x00a7, 0x25a0, 0x00a0}; |
| 241 |
|
| 242 |
inline constexpr char32_t CharsetTableCP857[256] = { |
| 243 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 244 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 245 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 246 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 247 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 248 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 249 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 250 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 251 |
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x0131, 0x00c4, 0x00c5, |
| 252 |
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, 0x0130, 0x00d6, 0x00dc, 0x00f8, 0x00a3, 0x00d8, 0x015e, 0x015f, |
| 253 |
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x011e, 0x011f, 0x00bf, 0x00ae, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, |
| 254 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00c1, 0x00c2, 0x00c0, 0x00a9, 0x2563, 0x2551, 0x2557, 0x255d, 0x00a2, 0x00a5, 0x2510, |
| 255 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x00e3, 0x00c3, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x00a4, |
| 256 |
0x00ba, 0x00aa, 0x00ca, 0x00cb, 0x00c8, UCS4ud, 0x00cd, 0x00ce, 0x00cf, 0x2518, 0x250c, 0x2588, 0x2584, 0x00a6, 0x00cc, 0x2580, |
| 257 |
0x00d3, 0x00df, 0x00d4, 0x00d2, 0x00f5, 0x00d5, 0x00b5, UCS4ud, 0x00d7, 0x00da, 0x00db, 0x00d9, 0x00ec, 0x00ff, 0x00af, 0x00b4, |
| 258 |
0x00ad, 0x00b1, UCS4ud, 0x00be, 0x00b6, 0x00a7, 0x00f7, 0x00b8, 0x00b0, 0x00a8, 0x00b7, 0x00b9, 0x00b3, 0x00b2, 0x25a0, 0x00a0}; |
| 259 |
|
| 260 |
inline constexpr char32_t CharsetTableCP860[256] = { |
| 261 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 262 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 263 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 264 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 265 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 266 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 267 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 268 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 269 |
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e3, 0x00e0, 0x00c1, 0x00e7, 0x00ea, 0x00ca, 0x00e8, 0x00cd, 0x00d4, 0x00ec, 0x00c3, 0x00c2, |
| 270 |
0x00c9, 0x00c0, 0x00c8, 0x00f4, 0x00f5, 0x00f2, 0x00da, 0x00f9, 0x00cc, 0x00d5, 0x00dc, 0x00a2, 0x00a3, 0x00d9, 0x20a7, 0x00d3, |
| 271 |
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x00d2, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, |
| 272 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, |
| 273 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, |
| 274 |
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, |
| 275 |
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, |
| 276 |
0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0}; |
| 277 |
|
| 278 |
inline constexpr char32_t CharsetTableCP861[256] = { |
| 279 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 280 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 281 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 282 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 283 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 284 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 285 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 286 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 287 |
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00d0, 0x00f0, 0x00de, 0x00c4, 0x00c5, |
| 288 |
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00fe, 0x00fb, 0x00dd, 0x00fd, 0x00d6, 0x00dc, 0x00f8, 0x00a3, 0x00d8, 0x20a7, 0x0192, |
| 289 |
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00c1, 0x00cd, 0x00d3, 0x00da, 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, |
| 290 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, |
| 291 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, |
| 292 |
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, |
| 293 |
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, |
| 294 |
0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0}; |
| 295 |
|
| 296 |
inline constexpr char32_t CharsetTableCP862[256] = { |
| 297 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 298 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 299 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 300 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 301 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 302 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 303 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 304 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 305 |
0x05d0, 0x05d1, 0x05d2, 0x05d3, 0x05d4, 0x05d5, 0x05d6, 0x05d7, 0x05d8, 0x05d9, 0x05da, 0x05db, 0x05dc, 0x05dd, 0x05de, 0x05df, |
| 306 |
0x05e0, 0x05e1, 0x05e2, 0x05e3, 0x05e4, 0x05e5, 0x05e6, 0x05e7, 0x05e8, 0x05e9, 0x05ea, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192, |
| 307 |
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb, |
| 308 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, |
| 309 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, |
| 310 |
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, |
| 311 |
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, |
| 312 |
0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0}; |
| 313 |
|
| 314 |
inline constexpr char32_t CharsetTableCP863[256] = { |
| 315 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 316 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 317 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 318 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 319 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 320 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 321 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 322 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 323 |
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00c2, 0x00e0, 0x00b6, 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x2017, 0x00c0, 0x00a7, |
| 324 |
0x00c9, 0x00c8, 0x00ca, 0x00f4, 0x00cb, 0x00cf, 0x00fb, 0x00f9, 0x00a4, 0x00d4, 0x00dc, 0x00a2, 0x00a3, 0x00d9, 0x00db, 0x0192, |
| 325 |
0x00a6, 0x00b4, 0x00f3, 0x00fa, 0x00a8, 0x00b8, 0x00b3, 0x00af, 0x00ce, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00be, 0x00ab, 0x00bb, |
| 326 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, |
| 327 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, |
| 328 |
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, |
| 329 |
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, |
| 330 |
0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0}; |
| 331 |
|
| 332 |
inline constexpr char32_t CharsetTableCP864[256] = { |
| 333 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 334 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 335 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x066a, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 336 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 337 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 338 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 339 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 340 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 341 |
0x00b0, 0x00b7, 0x2219, 0x221a, 0x2592, 0x2500, 0x2502, 0x253c, 0x2524, 0x252c, 0x251c, 0x2534, 0x2510, 0x250c, 0x2514, 0x2518, |
| 342 |
0x03b2, 0x221e, 0x03c6, 0x00b1, 0x00bd, 0x00bc, 0x2248, 0x00ab, 0x00bb, 0xfef7, 0xfef8, UCS4ud, UCS4ud, 0xfefb, 0xfefc, UCS4ud, |
| 343 |
0x00a0, 0x00ad, 0xfe82, 0x00a3, 0x00a4, 0xfe84, UCS4ud, UCS4ud, 0xfe8e, 0xfe8f, 0xfe95, 0xfe99, 0x060c, 0xfe9d, 0xfea1, 0xfea5, |
| 344 |
0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, 0x0668, 0x0669, 0xfed1, 0x061b, 0xfeb1, 0xfeb5, 0xfeb9, 0x061f, |
| 345 |
0x00a2, 0xfe80, 0xfe81, 0xfe83, 0xfe85, 0xfeca, 0xfe8b, 0xfe8d, 0xfe91, 0xfe93, 0xfe97, 0xfe9b, 0xfe9f, 0xfea3, 0xfea7, 0xfea9, |
| 346 |
0xfeab, 0xfead, 0xfeaf, 0xfeb3, 0xfeb7, 0xfebb, 0xfebf, 0xfec1, 0xfec5, 0xfecb, 0xfecf, 0x00a6, 0x00ac, 0x00f7, 0x00d7, 0xfec9, |
| 347 |
0x0640, 0xfed3, 0xfed7, 0xfedb, 0xfedf, 0xfee3, 0xfee7, 0xfeeb, 0xfeed, 0xfeef, 0xfef3, 0xfebd, 0xfecc, 0xfece, 0xfecd, 0xfee1, |
| 348 |
0xfe7d, 0x0651, 0xfee5, 0xfee9, 0xfeec, 0xfef0, 0xfef2, 0xfed0, 0xfed5, 0xfef5, 0xfef6, 0xfedd, 0xfed9, 0xfef1, 0x25a0, UCS4ud}; |
| 349 |
|
| 350 |
inline constexpr char32_t CharsetTableCP865[256] = { |
| 351 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 352 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 353 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 354 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 355 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 356 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 357 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 358 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 359 |
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5, |
| 360 |
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, 0x00ff, 0x00d6, 0x00dc, 0x00f8, 0x00a3, 0x00d8, 0x20a7, 0x0192, |
| 361 |
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00a4, |
| 362 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, |
| 363 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, |
| 364 |
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, |
| 365 |
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03c4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229, |
| 366 |
0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0}; |
| 367 |
|
| 368 |
inline constexpr char32_t CharsetTableCP866[256] = { |
| 369 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 370 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 371 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 372 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 373 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 374 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 375 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 376 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 377 |
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041a, 0x041b, 0x041c, 0x041d, 0x041e, 0x041f, |
| 378 |
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042a, 0x042b, 0x042c, 0x042d, 0x042e, 0x042f, |
| 379 |
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043a, 0x043b, 0x043c, 0x043d, 0x043e, 0x043f, |
| 380 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510, |
| 381 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567, |
| 382 |
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580, |
| 383 |
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044a, 0x044b, 0x044c, 0x044d, 0x044e, 0x044f, |
| 384 |
0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040e, 0x045e, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x2116, 0x00a4, 0x25a0, 0x00a0}; |
| 385 |
|
| 386 |
inline constexpr char32_t CharsetTableCP869[256] = { |
| 387 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 388 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 389 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 390 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 391 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 392 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 393 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 394 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 395 |
UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, 0x0386, UCS4ud, 0x00b7, 0x00ac, 0x00a6, 0x2018, 0x2019, 0x0388, 0x2015, 0x0389, |
| 396 |
0x038a, 0x03aa, 0x038c, UCS4ud, UCS4ud, 0x038e, 0x03ab, 0x00a9, 0x038f, 0x00b2, 0x00b3, 0x03ac, 0x00a3, 0x03ad, 0x03ae, 0x03af, |
| 397 |
0x03ca, 0x0390, 0x03cc, 0x03cd, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x00bd, 0x0398, 0x0399, 0x00ab, 0x00bb, |
| 398 |
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x039a, 0x039b, 0x039c, 0x039d, 0x2563, 0x2551, 0x2557, 0x255d, 0x039e, 0x039f, 0x2510, |
| 399 |
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x03a0, 0x03a1, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x03a3, |
| 400 |
0x03a4, 0x03a5, 0x03a6, 0x03a7, 0x03a8, 0x03a9, 0x03b1, 0x03b2, 0x03b3, 0x2518, 0x250c, 0x2588, 0x2584, 0x03b4, 0x03b5, 0x2580, |
| 401 |
0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf, 0x03c0, 0x03c1, 0x03c3, 0x03c2, 0x03c4, 0x0384, |
| 402 |
0x00ad, 0x00b1, 0x03c5, 0x03c6, 0x03c7, 0x00a7, 0x03c8, 0x0385, 0x00b0, 0x00a8, 0x03c9, 0x03cb, 0x03b0, 0x03ce, 0x25a0, 0x00a0}; |
| 403 |
|
| 404 |
inline constexpr char32_t CharsetTableCP874[256] = { |
| 405 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, |
| 406 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, |
| 407 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, |
| 408 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, |
| 409 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, |
| 410 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F, |
| 411 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, |
| 412 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, |
| 413 |
0x20AC, UCS4ud, UCS4ud, UCS4ud, UCS4ud, 0x2026, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, |
| 414 |
UCS4ud, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, UCS4ud, |
| 415 |
0x00A0, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07, 0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F, |
| 416 |
0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17, 0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F, |
| 417 |
0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27, 0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F, |
| 418 |
0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37, 0x0E38, 0x0E39, 0x0E3A, UCS4ud, UCS4ud, UCS4ud, UCS4ud, 0x0E3F, |
| 419 |
0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47, 0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F, |
| 420 |
0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57, 0x0E58, 0x0E59, 0x0E5A, 0x0E5B, UCS4ud, UCS4ud, UCS4ud, UCS4ud}; |
| 421 |
|
| 422 |
// <https://de.wikipedia.org/wiki/Commodore_Amiga_(Zeichensatz)> |
| 423 |
inline constexpr char32_t CharsetTableAmiga[256] = { |
| 424 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 425 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 426 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 427 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 428 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 429 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 430 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 431 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2592, |
| 432 |
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, 0x008a, 0x008b, 0x008c, 0x008d, 0x008e, 0x008f, |
| 433 |
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, 0x0098, 0x0099, 0x009a, 0x009b, 0x009c, 0x009d, 0x009e, 0x009f, |
| 434 |
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x2013, 0x00ae, 0x00af, |
| 435 |
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, |
| 436 |
0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, |
| 437 |
0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, |
| 438 |
0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, |
| 439 |
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff}; |
| 440 |
|
| 441 |
// Based on RISCOSI.TXT from <https://www.unicode.org/L2/L2019/19025-terminals-prop.pdf>, |
| 442 |
// with gaps filled in from standard set at <https://en.wikipedia.org/wiki/RISC_OS_character_set>. |
| 443 |
inline constexpr char32_t CharsetTableRISC_OS[256] = { |
| 444 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 445 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 446 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 447 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 448 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 449 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 450 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 451 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 452 |
0x20AC, 0x0174, 0x0175, 0x25f0, 0x1fbc0, 0x0176, 0x0177, 0xfffd, 0x21e6, 0x21e8, 0x21e9, 0x21e7, 0x2026, 0x2122, 0x2030, 0x2022, |
| 453 |
0x2018, 0x2019, 0x2039, 0x203A, 0x201C, 0x201D, 0x201E, 0x2013, 0x2014, 0x2212, 0x0152, 0x0153, 0x2020, 0x2021, 0xFB01, 0xFB02, |
| 454 |
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af, |
| 455 |
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf, |
| 456 |
0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf, |
| 457 |
0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df, |
| 458 |
0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef, |
| 459 |
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff}; |
| 460 |
|
| 461 |
// <https://www.unicode.org/Public/MAPPINGS/VENDORS/MISC/ATARIST.TXT> |
| 462 |
inline constexpr char32_t CharsetTableAtariST[256] = { |
| 463 |
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f, |
| 464 |
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f, |
| 465 |
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f, |
| 466 |
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f, |
| 467 |
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f, |
| 468 |
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f, |
| 469 |
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f, |
| 470 |
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f, |
| 471 |
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5, |
| 472 |
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x00DF, 0x0192, |
| 473 |
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB, |
| 474 |
0x00E3, 0x00F5, 0x00D8, 0x00F8, 0x0153, 0x0152, 0x00C0, 0x00C3, 0x00D5, 0x00A8, 0x00B4, 0x2020, 0x00B6, 0x00A9, 0x00AE, 0x2122, |
| 475 |
0x0133, 0x0132, 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, 0x05D8, 0x05D9, 0x05DB, 0x05DC, 0x05DE, 0x05E0, |
| 476 |
0x05E1, 0x05E2, 0x05E4, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA, 0x05DF, 0x05DA, 0x05DD, 0x05E3, 0x05E5, 0x00A7, 0x2227, 0x221E, |
| 477 |
0x03B1, 0x03B2, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x222E, 0x03C6, 0x2208, 0x2229, |
| 478 |
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x00B3, 0x00AF}; |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
template <typename Tdststring> |
| 483 |
inline void encode_single_utf16(Tdststring & out, char32_t ucs4) { |
| 484 |
static_assert(sizeof(typename Tdststring::value_type) == 2); |
| 485 |
if (ucs4 <= 0xffff) { |
| 486 |
out.push_back(static_cast<typename Tdststring::value_type>(static_cast<uint16>(static_cast<uint32>(ucs4)))); |
| 487 |
} else { |
| 488 |
uint32 surrogate = static_cast<uint32>(ucs4) - 0x10000; |
| 489 |
uint16 hi_sur = static_cast<uint16>((0x36 << 10) | ((surrogate >> 10) & ((1 << 10) - 1))); |
| 490 |
uint16 lo_sur = static_cast<uint16>((0x37 << 10) | ((surrogate >> 0) & ((1 << 10) - 1))); |
| 491 |
out.push_back(static_cast<typename Tdststring::value_type>(hi_sur)); |
| 492 |
out.push_back(static_cast<typename Tdststring::value_type>(lo_sur)); |
| 493 |
} |
| 494 |
} |
| 495 |
|
| 496 |
template <typename Tsrcstring> |
| 497 |
inline char32_t decode_single_utf16(std::size_t & i, const Tsrcstring & in) { |
| 498 |
static_assert(sizeof(typename Tsrcstring::value_type) == 2); |
| 499 |
char32_t ucs4 = 0; |
| 500 |
typename Tsrcstring::value_type wc = in[i]; |
| 501 |
uint16 c = static_cast<uint16>(wc); |
| 502 |
if (i + 1 < in.length()) { |
| 503 |
// check for surrogate pair |
| 504 |
uint16 hi_sur = in[i + 0]; |
| 505 |
uint16 lo_sur = in[i + 1]; |
| 506 |
if (hi_sur >> 10 == 0x36 && lo_sur >> 10 == 0x37) { |
| 507 |
// surrogate pair |
| 508 |
++i; |
| 509 |
hi_sur &= (1 << 10) - 1; |
| 510 |
lo_sur &= (1 << 10) - 1; |
| 511 |
ucs4 = (static_cast<uint32>(hi_sur) << 10) | (static_cast<uint32>(lo_sur) << 0); |
| 512 |
} else { |
| 513 |
// no surrogate pair |
| 514 |
ucs4 = static_cast<char32_t>(c); |
| 515 |
} |
| 516 |
} else { |
| 517 |
// no surrogate possible |
| 518 |
ucs4 = static_cast<char32_t>(c); |
| 519 |
} |
| 520 |
return ucs4; |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
inline void encode_single_wide(mpt::widestring & out, char32_t ucs4) { |
| 526 |
if constexpr (sizeof(mpt::widechar) == 2) { |
| 527 |
if (ucs4 <= 0xffff) { |
| 528 |
out.push_back(static_cast<mpt::widechar>(static_cast<uint16>(static_cast<uint32>(ucs4)))); |
| 529 |
} else { |
| 530 |
uint32 surrogate = static_cast<uint32>(ucs4) - 0x10000; |
| 531 |
uint16 hi_sur = static_cast<uint16>((0x36 << 10) | ((surrogate >> 10) & ((1 << 10) - 1))); |
| 532 |
uint16 lo_sur = static_cast<uint16>((0x37 << 10) | ((surrogate >> 0) & ((1 << 10) - 1))); |
| 533 |
out.push_back(static_cast<mpt::widechar>(hi_sur)); |
| 534 |
out.push_back(static_cast<mpt::widechar>(lo_sur)); |
| 535 |
} |
| 536 |
} else { |
| 537 |
out.push_back(static_cast<mpt::widechar>(static_cast<uint32>(ucs4))); |
| 538 |
} |
| 539 |
} |
| 540 |
|
| 541 |
inline char32_t decode_single_wide(std::size_t & i, const mpt::widestring & in) { |
| 542 |
char32_t ucs4 = 0; |
| 543 |
mpt::widechar wc = in[i]; |
| 544 |
if constexpr (sizeof(mpt::widechar) == 2) { |
| 545 |
uint16 c = static_cast<uint16>(wc); |
| 546 |
if (i + 1 < in.length()) { |
| 547 |
// check for surrogate pair |
| 548 |
uint16 hi_sur = in[i + 0]; |
| 549 |
uint16 lo_sur = in[i + 1]; |
| 550 |
if (hi_sur >> 10 == 0x36 && lo_sur >> 10 == 0x37) { |
| 551 |
// surrogate pair |
| 552 |
++i; |
| 553 |
hi_sur &= (1 << 10) - 1; |
| 554 |
lo_sur &= (1 << 10) - 1; |
| 555 |
ucs4 = (static_cast<uint32>(hi_sur) << 10) | (static_cast<uint32>(lo_sur) << 0); |
| 556 |
} else { |
| 557 |
// no surrogate pair |
| 558 |
ucs4 = static_cast<char32_t>(c); |
| 559 |
} |
| 560 |
} else { |
| 561 |
// no surrogate possible |
| 562 |
ucs4 = static_cast<char32_t>(c); |
| 563 |
} |
| 564 |
} else { |
| 565 |
ucs4 = static_cast<char32_t>(static_cast<uint32>(wc)); |
| 566 |
} |
| 567 |
return ucs4; |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
template <typename Tsrcstring> |
| 573 |
inline mpt::widestring decode_8bit(const Tsrcstring & str, const char32_t (&table)[256], mpt::widechar replacement = MPT_WIDECHAR('\uFFFD')) { |
| 574 |
mpt::widestring res; |
| 575 |
res.reserve(str.length()); |
| 576 |
for (std::size_t i = 0; i < str.length(); ++i) { |
| 577 |
std::size_t c = static_cast<std::size_t>(mpt::char_value(str[i])); |
| 578 |
if (c < std::size(table)) { |
| 579 |
encode_single_wide(res, table[c]); |
| 580 |
} else { |
| 581 |
res.push_back(replacement); |
| 582 |
} |
| 583 |
} |
| 584 |
return res; |
| 585 |
} |
| 586 |
|
| 587 |
template <typename Tdststring> |
| 588 |
inline Tdststring encode_8bit(const mpt::widestring & str, const char32_t (&table)[256], char replacement = '?') { |
| 589 |
Tdststring res; |
| 590 |
res.reserve(str.length()); |
| 591 |
for (std::size_t i = 0; i < str.length(); ++i) { |
| 592 |
char32_t c = decode_single_wide(i, str); |
| 593 |
bool found = false; |
| 594 |
// Try non-control characters first. |
| 595 |
// In cases where there are actual characters mirrored in this range (like in AMS/AMS2 character sets), |
| 596 |
// characters in the common range are preferred this way. |
| 597 |
for (std::size_t x = 0x20; x < std::size(table); ++x) { |
| 598 |
if (c == table[x]) { |
| 599 |
res.push_back(static_cast<typename Tdststring::value_type>(static_cast<uint8>(x))); |
| 600 |
found = true; |
| 601 |
break; |
| 602 |
} |
| 603 |
} |
| 604 |
if (!found) { |
| 605 |
// try control characters |
| 606 |
for (std::size_t x = 0x00; x < std::size(table) && x < 0x20; ++x) { |
| 607 |
if (c == table[x]) { |
| 608 |
res.push_back(static_cast<typename Tdststring::value_type>(static_cast<uint8>(x))); |
| 609 |
found = true; |
| 610 |
break; |
| 611 |
} |
| 612 |
} |
| 613 |
} |
| 614 |
if (!found) { |
| 615 |
res.push_back(replacement); |
| 616 |
} |
| 617 |
} |
| 618 |
return res; |
| 619 |
} |
| 620 |
|
| 621 |
template <typename Tsrcstring> |
| 622 |
inline mpt::widestring decode_8bit_no_c1(const Tsrcstring & str, const char32_t (&table)[256], mpt::widechar replacement = MPT_WIDECHAR('\uFFFD')) { |
| 623 |
mpt::widestring res; |
| 624 |
res.reserve(str.length()); |
| 625 |
for (std::size_t i = 0; i < str.length(); ++i) { |
| 626 |
std::size_t c = static_cast<std::size_t>(mpt::char_value(str[i])); |
| 627 |
if ((0x80 <= c) && (c <= 0x9f)) { |
| 628 |
res.push_back(replacement); |
| 629 |
} else if (c < std::size(table)) { |
| 630 |
encode_single_wide(res, table[c]); |
| 631 |
} else { |
| 632 |
res.push_back(replacement); |
| 633 |
} |
| 634 |
} |
| 635 |
return res; |
| 636 |
} |
| 637 |
|
| 638 |
template <typename Tdststring> |
| 639 |
inline Tdststring encode_8bit_no_c1(const mpt::widestring & str, const char32_t (&table)[256], char replacement = '?') { |
| 640 |
Tdststring res; |
| 641 |
res.reserve(str.length()); |
| 642 |
for (std::size_t i = 0; i < str.length(); ++i) { |
| 643 |
char32_t c = decode_single_wide(i, str); |
| 644 |
bool found = false; |
| 645 |
// Try non-control characters first. |
| 646 |
// In cases where there are actual characters mirrored in this range (like in AMS/AMS2 character sets), |
| 647 |
// characters in the common range are preferred this way. |
| 648 |
for (std::size_t x = 0x20; x < std::size(table); ++x) { |
| 649 |
if ((0x80 <= c) && (c <= 0x9f)) { |
| 650 |
continue; |
| 651 |
} |
| 652 |
if (c == table[x]) { |
| 653 |
res.push_back(static_cast<typename Tdststring::value_type>(static_cast<uint8>(x))); |
| 654 |
found = true; |
| 655 |
break; |
| 656 |
} |
| 657 |
} |
| 658 |
if (!found) { |
| 659 |
// try control characters |
| 660 |
for (std::size_t x = 0x00; x < std::size(table) && x < 0x20; ++x) { |
| 661 |
if (c == table[x]) { |
| 662 |
res.push_back(static_cast<typename Tdststring::value_type>(static_cast<uint8>(x))); |
| 663 |
found = true; |
| 664 |
break; |
| 665 |
} |
| 666 |
} |
| 667 |
} |
| 668 |
if (!found) { |
| 669 |
res.push_back(replacement); |
| 670 |
} |
| 671 |
} |
| 672 |
return res; |
| 673 |
} |
| 674 |
|
| 675 |
template <typename Tsrcstring> |
| 676 |
inline mpt::widestring decode_ascii(const Tsrcstring & str, mpt::widechar replacement = MPT_WIDECHAR('\uFFFD')) { |
| 677 |
mpt::widestring res; |
| 678 |
res.reserve(str.length()); |
| 679 |
for (std::size_t i = 0; i < str.length(); ++i) { |
| 680 |
uint8 c = mpt::char_value(str[i]); |
| 681 |
if (c <= 0x7f) { |
| 682 |
encode_single_wide(res, static_cast<char32_t>(static_cast<uint32>(c))); |
| 683 |
} else { |
| 684 |
res.push_back(replacement); |
| 685 |
} |
| 686 |
} |
| 687 |
return res; |
| 688 |
} |
| 689 |
|
| 690 |
template <typename Tdststring> |
| 691 |
inline Tdststring encode_ascii(const mpt::widestring & str, char replacement = '?') { |
| 692 |
Tdststring res; |
| 693 |
res.reserve(str.length()); |
| 694 |
for (std::size_t i = 0; i < str.length(); ++i) { |
| 695 |
char32_t c = decode_single_wide(i, str); |
| 696 |
if (c <= 0x7f) { |
| 697 |
res.push_back(static_cast<typename Tdststring::value_type>(static_cast<uint8>(static_cast<uint32>(c)))); |
| 698 |
} else { |
| 699 |
res.push_back(replacement); |
| 700 |
} |
| 701 |
} |
| 702 |
return res; |
| 703 |
} |
| 704 |
|
| 705 |
template <typename Tsrcstring> |
| 706 |
inline mpt::widestring decode_iso8859_1(const Tsrcstring & str, mpt::widechar replacement = MPT_WIDECHAR('\uFFFD')) { |
| 707 |
MPT_UNUSED(replacement); |
| 708 |
mpt::widestring res; |
| 709 |
res.reserve(str.length()); |
| 710 |
for (std::size_t i = 0; i < str.length(); ++i) { |
| 711 |
uint8 c = mpt::char_value(str[i]); |
| 712 |
encode_single_wide(res, static_cast<char32_t>(static_cast<uint32>(c))); |
| 713 |
} |
| 714 |
return res; |
| 715 |
} |
| 716 |
|
| 717 |
template <typename Tdststring> |
| 718 |
inline Tdststring encode_iso8859_1(const mpt::widestring & str, char replacement = '?') { |
| 719 |
Tdststring res; |
| 720 |
res.reserve(str.length()); |
| 721 |
for (std::size_t i = 0; i < str.length(); ++i) { |
| 722 |
char32_t c = decode_single_wide(i, str); |
| 723 |
if (c <= 0xff) { |
| 724 |
res.push_back(static_cast<typename Tdststring::value_type>(static_cast<uint8>(c))); |
| 725 |
} else { |
| 726 |
res.push_back(replacement); |
| 727 |
} |
| 728 |
} |
| 729 |
return res; |
| 730 |
} |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
template <typename Tsrcstring> |
| 735 |
inline mpt::widestring decode_utf8(const Tsrcstring & str, mpt::widechar replacement = MPT_WIDECHAR('\uFFFD')) { |
| 736 |
const Tsrcstring & in = str; |
| 737 |
mpt::widestring out; |
| 738 |
// state: |
| 739 |
std::size_t charsleft = 0; |
| 740 |
char32_t ucs4 = 0; |
| 741 |
for (uint8 c : in) { |
| 742 |
if (charsleft == 0) { |
| 743 |
if ((c & 0x80) == 0x00) { |
| 744 |
out.push_back(static_cast<mpt::widechar>(c)); |
| 745 |
} else if ((c & 0xE0) == 0xC0) { |
| 746 |
ucs4 = c & 0x1F; |
| 747 |
charsleft = 1; |
| 748 |
} else if ((c & 0xF0) == 0xE0) { |
| 749 |
ucs4 = c & 0x0F; |
| 750 |
charsleft = 2; |
| 751 |
} else if ((c & 0xF8) == 0xF0) { |
| 752 |
ucs4 = c & 0x07; |
| 753 |
charsleft = 3; |
| 754 |
} else { |
| 755 |
out.push_back(replacement); |
| 756 |
ucs4 = 0; |
| 757 |
charsleft = 0; |
| 758 |
} |
| 759 |
} else { |
| 760 |
if ((c & 0xC0) != 0x80) { |
| 761 |
out.push_back(replacement); |
| 762 |
ucs4 = 0; |
| 763 |
charsleft = 0; |
| 764 |
} |
| 765 |
ucs4 <<= 6; |
| 766 |
ucs4 |= c & 0x3F; |
| 767 |
charsleft--; |
| 768 |
if (charsleft == 0) { |
| 769 |
if constexpr (sizeof(mpt::widechar) == 2) { |
| 770 |
if (ucs4 > 0x1fffff) { |
| 771 |
out.push_back(replacement); |
| 772 |
ucs4 = 0; |
| 773 |
charsleft = 0; |
| 774 |
continue; |
| 775 |
} |
| 776 |
} |
| 777 |
encode_single_wide(out, ucs4); |
| 778 |
ucs4 = 0; |
| 779 |
} |
| 780 |
} |
| 781 |
} |
| 782 |
if (charsleft != 0) { |
| 783 |
out.push_back(replacement); |
| 784 |
ucs4 = 0; |
| 785 |
charsleft = 0; |
| 786 |
} |
| 787 |
return out; |
| 788 |
} |
| 789 |
|
| 790 |
template <typename Tdststring> |
| 791 |
inline Tdststring encode_utf8(const mpt::widestring & str, typename Tdststring::value_type replacement = static_cast<typename Tdststring::value_type>(mpt::char_value('?'))) { |
| 792 |
const mpt::widestring & in = str; |
| 793 |
Tdststring out; |
| 794 |
for (std::size_t i = 0; i < in.length(); i++) { |
| 795 |
char32_t ucs4 = decode_single_wide(i, in); |
| 796 |
if (ucs4 > 0x1fffff) { |
| 797 |
out.push_back(replacement); |
| 798 |
continue; |
| 799 |
} |
| 800 |
uint8 utf8[6]; |
| 801 |
std::size_t numchars = 0; |
| 802 |
for (numchars = 0; numchars < 6; numchars++) { |
| 803 |
utf8[numchars] = ucs4 & 0x3F; |
| 804 |
ucs4 >>= 6; |
| 805 |
if (ucs4 == 0) { |
| 806 |
break; |
| 807 |
} |
| 808 |
} |
| 809 |
numchars++; |
| 810 |
if (numchars == 1) { |
| 811 |
out.push_back(utf8[0]); |
| 812 |
continue; |
| 813 |
} |
| 814 |
if (numchars == 2 && utf8[numchars - 1] == 0x01) { |
| 815 |
// generate shortest form |
| 816 |
out.push_back(utf8[0] | 0x40); |
| 817 |
continue; |
| 818 |
} |
| 819 |
std::size_t charsleft = numchars; |
| 820 |
while (charsleft > 0) { |
| 821 |
if (charsleft == numchars) { |
| 822 |
// cppcheck false-positive |
| 823 |
// cppcheck-suppress arrayIndexOutOfBounds |
| 824 |
out.push_back(static_cast<uint8>(utf8[charsleft - 1] | (((1 << numchars) - 1) << (8 - numchars)))); |
| 825 |
} else { |
| 826 |
// cppcheck false-positive |
| 827 |
// cppcheck-suppress arrayIndexOutOfBounds |
| 828 |
out.push_back(static_cast<uint8>(utf8[charsleft - 1] | 0x80u)); |
| 829 |
} |
| 830 |
charsleft--; |
| 831 |
} |
| 832 |
} |
| 833 |
return out; |
| 834 |
} |
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
template <typename Tdststring, typename Tsrcstring> |
| 839 |
inline Tdststring utf32_from_utf16(const Tsrcstring & in, mpt::widechar replacement = MPT_WIDECHAR('\uFFFD')) { |
| 840 |
static_assert(sizeof(typename Tsrcstring::value_type) == 2); |
| 841 |
static_assert(sizeof(typename Tdststring::value_type) == 4); |
| 842 |
MPT_UNUSED(replacement); |
| 843 |
Tdststring out; |
| 844 |
out.reserve(in.length()); |
| 845 |
for (std::size_t i = 0; i < in.length(); i++) { |
| 846 |
char32_t ucs4 = decode_single_utf16(i, in); |
| 847 |
out.push_back(static_cast<typename Tdststring::value_type>(static_cast<uint32>(ucs4))); |
| 848 |
} |
| 849 |
return out; |
| 850 |
} |
| 851 |
|
| 852 |
template <typename Tdststring, typename Tsrcstring> |
| 853 |
inline Tdststring utf16_from_utf32(const Tsrcstring & in, mpt::widechar replacement = MPT_WIDECHAR('\uFFFD')) { |
| 854 |
static_assert(sizeof(typename Tsrcstring::value_type) == 4); |
| 855 |
static_assert(sizeof(typename Tdststring::value_type) == 2); |
| 856 |
Tdststring out; |
| 857 |
out.reserve(in.length()); |
| 858 |
for (std::size_t i = 0; i < in.length(); i++) { |
| 859 |
char32_t ucs4 = static_cast<char32_t>(static_cast<uint32>(in[i])); |
| 860 |
if (ucs4 > 0x1fffff) { |
| 861 |
out.push_back(static_cast<typename Tdststring::value_type>(static_cast<uint16>(replacement))); |
| 862 |
continue; |
| 863 |
} |
| 864 |
encode_single_utf16(out, ucs4); |
| 865 |
} |
| 866 |
return out; |
| 867 |
} |
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
#if MPT_OS_WINDOWS |
| 872 |
|
| 873 |
inline bool has_codepage(UINT cp) { |
| 874 |
return IsValidCodePage(cp) ? true : false; |
| 875 |
} |
| 876 |
|
| 877 |
inline bool windows_has_encoding(common_encoding encoding) { |
| 878 |
bool result = false; |
| 879 |
switch (encoding) { |
| 880 |
case common_encoding::utf8: |
| 881 |
result = has_codepage(CP_UTF8); |
| 882 |
break; |
| 883 |
case common_encoding::ascii: |
| 884 |
result = has_codepage(20127); |
| 885 |
break; |
| 886 |
case common_encoding::iso8859_1: |
| 887 |
result = has_codepage(28591); |
| 888 |
break; |
| 889 |
case common_encoding::iso8859_15: |
| 890 |
result = has_codepage(28605); |
| 891 |
break; |
| 892 |
case common_encoding::cp437: |
| 893 |
result = has_codepage(437); |
| 894 |
break; |
| 895 |
case common_encoding::cp737: |
| 896 |
result = has_codepage(737); |
| 897 |
break; |
| 898 |
case common_encoding::cp775: |
| 899 |
result = has_codepage(775); |
| 900 |
break; |
| 901 |
case common_encoding::cp850: |
| 902 |
result = has_codepage(850); |
| 903 |
break; |
| 904 |
case common_encoding::cp852: |
| 905 |
result = has_codepage(852); |
| 906 |
break; |
| 907 |
case common_encoding::cp855: |
| 908 |
result = has_codepage(855); |
| 909 |
break; |
| 910 |
case common_encoding::cp857: |
| 911 |
result = has_codepage(857); |
| 912 |
break; |
| 913 |
case common_encoding::cp860: |
| 914 |
result = has_codepage(860); |
| 915 |
break; |
| 916 |
case common_encoding::cp861: |
| 917 |
result = has_codepage(861); |
| 918 |
break; |
| 919 |
case common_encoding::cp862: |
| 920 |
result = has_codepage(862); |
| 921 |
break; |
| 922 |
case common_encoding::cp863: |
| 923 |
result = has_codepage(863); |
| 924 |
break; |
| 925 |
case common_encoding::cp864: |
| 926 |
result = has_codepage(864); |
| 927 |
break; |
| 928 |
case common_encoding::cp865: |
| 929 |
result = has_codepage(865); |
| 930 |
break; |
| 931 |
case common_encoding::cp866: |
| 932 |
result = has_codepage(866); |
| 933 |
break; |
| 934 |
case common_encoding::cp869: |
| 935 |
result = has_codepage(869); |
| 936 |
break; |
| 937 |
case common_encoding::cp874: |
| 938 |
result = has_codepage(874); |
| 939 |
break; |
| 940 |
case common_encoding::windows1252: |
| 941 |
result = has_codepage(1252); |
| 942 |
break; |
| 943 |
case common_encoding::amiga: |
| 944 |
result = false; |
| 945 |
break; |
| 946 |
case common_encoding::riscos: |
| 947 |
result = false; |
| 948 |
break; |
| 949 |
case common_encoding::atarist: |
| 950 |
result = false; |
| 951 |
break; |
| 952 |
case common_encoding::iso8859_1_no_c1: |
| 953 |
result = false; |
| 954 |
break; |
| 955 |
case common_encoding::iso8859_15_no_c1: |
| 956 |
result = false; |
| 957 |
break; |
| 958 |
case common_encoding::amiga_no_c1: |
| 959 |
result = false; |
| 960 |
break; |
| 961 |
} |
| 962 |
return result; |
| 963 |
} |
| 964 |
|
| 965 |
inline bool windows_has_encoding(logical_encoding encoding) { |
| 966 |
bool result = false; |
| 967 |
switch (encoding) { |
| 968 |
case logical_encoding::locale: |
| 969 |
result = true; |
| 970 |
break; |
| 971 |
case logical_encoding::active_locale: |
| 972 |
result = false; |
| 973 |
break; |
| 974 |
} |
| 975 |
return result; |
| 976 |
} |
| 977 |
|
| 978 |
inline UINT codepage_from_encoding(logical_encoding encoding) { |
| 979 |
UINT result = 0; |
| 980 |
switch (encoding) { |
| 981 |
case logical_encoding::locale: |
| 982 |
result = CP_ACP; |
| 983 |
break; |
| 984 |
case logical_encoding::active_locale: |
| 985 |
throw std::domain_error("unsupported encoding"); |
| 986 |
break; |
| 987 |
} |
| 988 |
return result; |
| 989 |
} |
| 990 |
|
| 991 |
inline UINT codepage_from_encoding(common_encoding encoding) { |
| 992 |
UINT result = 0; |
| 993 |
switch (encoding) { |
| 994 |
case common_encoding::utf8: |
| 995 |
result = CP_UTF8; |
| 996 |
break; |
| 997 |
case common_encoding::ascii: |
| 998 |
result = 20127; |
| 999 |
break; |
| 1000 |
case common_encoding::iso8859_1: |
| 1001 |
result = 28591; |
| 1002 |
break; |
| 1003 |
case common_encoding::iso8859_15: |
| 1004 |
result = 28605; |
| 1005 |
break; |
| 1006 |
case common_encoding::cp437: |
| 1007 |
result = 437; |
| 1008 |
break; |
| 1009 |
case common_encoding::cp737: |
| 1010 |
result = 737; |
| 1011 |
break; |
| 1012 |
case common_encoding::cp775: |
| 1013 |
result = 775; |
| 1014 |
break; |
| 1015 |
case common_encoding::cp850: |
| 1016 |
result = 850; |
| 1017 |
break; |
| 1018 |
case common_encoding::cp852: |
| 1019 |
result = 852; |
| 1020 |
break; |
| 1021 |
case common_encoding::cp855: |
| 1022 |
result = 855; |
| 1023 |
break; |
| 1024 |
case common_encoding::cp857: |
| 1025 |
result = 857; |
| 1026 |
break; |
| 1027 |
case common_encoding::cp860: |
| 1028 |
result = 860; |
| 1029 |
break; |
| 1030 |
case common_encoding::cp861: |
| 1031 |
result = 861; |
| 1032 |
break; |
| 1033 |
case common_encoding::cp862: |
| 1034 |
result = 862; |
| 1035 |
break; |
| 1036 |
case common_encoding::cp863: |
| 1037 |
result = 863; |
| 1038 |
break; |
| 1039 |
case common_encoding::cp864: |
| 1040 |
result = 864; |
| 1041 |
break; |
| 1042 |
case common_encoding::cp865: |
| 1043 |
result = 865; |
| 1044 |
break; |
| 1045 |
case common_encoding::cp866: |
| 1046 |
result = 866; |
| 1047 |
break; |
| 1048 |
case common_encoding::cp869: |
| 1049 |
result = 869; |
| 1050 |
break; |
| 1051 |
case common_encoding::cp874: |
| 1052 |
result = 874; |
| 1053 |
break; |
| 1054 |
case common_encoding::windows1252: |
| 1055 |
result = 1252; |
| 1056 |
break; |
| 1057 |
case common_encoding::amiga: |
| 1058 |
throw std::domain_error("unsupported encoding"); |
| 1059 |
break; |
| 1060 |
case common_encoding::riscos: |
| 1061 |
throw std::domain_error("unsupported encoding"); |
| 1062 |
break; |
| 1063 |
case common_encoding::atarist: |
| 1064 |
throw std::domain_error("unsupported encoding"); |
| 1065 |
break; |
| 1066 |
case common_encoding::iso8859_1_no_c1: |
| 1067 |
throw std::domain_error("unsupported encoding"); |
| 1068 |
break; |
| 1069 |
case common_encoding::iso8859_15_no_c1: |
| 1070 |
throw std::domain_error("unsupported encoding"); |
| 1071 |
break; |
| 1072 |
case common_encoding::amiga_no_c1: |
| 1073 |
throw std::domain_error("unsupported encoding"); |
| 1074 |
break; |
| 1075 |
} |
| 1076 |
return result; |
| 1077 |
} |
| 1078 |
|
| 1079 |
inline std::optional<common_encoding> optional_encoding_from_codepage(UINT codepage) { |
| 1080 |
std::optional<common_encoding> result = std::nullopt; |
| 1081 |
switch (codepage) { |
| 1082 |
case CP_UTF8: |
| 1083 |
result = common_encoding::utf8; |
| 1084 |
break; |
| 1085 |
case 20127: |
| 1086 |
result = common_encoding::ascii; |
| 1087 |
break; |
| 1088 |
case 28591: |
| 1089 |
result = common_encoding::iso8859_1; |
| 1090 |
break; |
| 1091 |
case 28605: |
| 1092 |
result = common_encoding::iso8859_15; |
| 1093 |
break; |
| 1094 |
case 437: |
| 1095 |
result = common_encoding::cp437; |
| 1096 |
break; |
| 1097 |
case 737: |
| 1098 |
result = common_encoding::cp737; |
| 1099 |
break; |
| 1100 |
case 775: |
| 1101 |
result = common_encoding::cp775; |
| 1102 |
break; |
| 1103 |
case 850: |
| 1104 |
result = common_encoding::cp850; |
| 1105 |
break; |
| 1106 |
case 852: |
| 1107 |
result = common_encoding::cp852; |
| 1108 |
break; |
| 1109 |
case 855: |
| 1110 |
result = common_encoding::cp855; |
| 1111 |
break; |
| 1112 |
case 857: |
| 1113 |
result = common_encoding::cp857; |
| 1114 |
break; |
| 1115 |
case 860: |
| 1116 |
result = common_encoding::cp860; |
| 1117 |
break; |
| 1118 |
case 861: |
| 1119 |
result = common_encoding::cp861; |
| 1120 |
break; |
| 1121 |
case 862: |
| 1122 |
result = common_encoding::cp862; |
| 1123 |
break; |
| 1124 |
case 863: |
| 1125 |
result = common_encoding::cp863; |
| 1126 |
break; |
| 1127 |
case 864: |
| 1128 |
result = common_encoding::cp864; |
| 1129 |
break; |
| 1130 |
case 865: |
| 1131 |
result = common_encoding::cp865; |
| 1132 |
break; |
| 1133 |
case 866: |
| 1134 |
result = common_encoding::cp866; |
| 1135 |
break; |
| 1136 |
case 869: |
| 1137 |
result = common_encoding::cp869; |
| 1138 |
break; |
| 1139 |
case 874: |
| 1140 |
result = common_encoding::cp874; |
| 1141 |
break; |
| 1142 |
case 1252: |
| 1143 |
result = common_encoding::windows1252; |
| 1144 |
break; |
| 1145 |
default: |
| 1146 |
result = std::nullopt; |
| 1147 |
break; |
| 1148 |
} |
| 1149 |
return result; |
| 1150 |
} |
| 1151 |
|
| 1152 |
inline common_encoding encoding_from_codepage(UINT codepage) { |
| 1153 |
std::optional<common_encoding> optional_result = optional_encoding_from_codepage(codepage); |
| 1154 |
if (!optional_result) { |
| 1155 |
throw std::domain_error("unsupported encoding"); |
| 1156 |
} |
| 1157 |
return *optional_result; |
| 1158 |
} |
| 1159 |
|
| 1160 |
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1161 |
|
| 1162 |
template <typename Tdststring> |
| 1163 |
inline Tdststring encode_codepage(UINT codepage, const mpt::widestring & src) { |
| 1164 |
static_assert(sizeof(typename Tdststring::value_type) == sizeof(char)); |
| 1165 |
static_assert(mpt::is_character<typename Tdststring::value_type>::value); |
| 1166 |
Tdststring encoded_string; |
| 1167 |
int required_size = WideCharToMultiByte(codepage, 0, src.data(), mpt::saturate_cast<int>(src.size()), nullptr, 0, nullptr, nullptr); |
| 1168 |
if (required_size > 0) { |
| 1169 |
encoded_string.resize(required_size); |
| 1170 |
WideCharToMultiByte(codepage, 0, src.data(), mpt::saturate_cast<int>(src.size()), reinterpret_cast<CHAR *>(encoded_string.data()), required_size, nullptr, nullptr); |
| 1171 |
} |
| 1172 |
return encoded_string; |
| 1173 |
} |
| 1174 |
|
| 1175 |
template <typename Tsrcstring> |
| 1176 |
inline mpt::widestring decode_codepage(UINT codepage, const Tsrcstring & src) { |
| 1177 |
static_assert(sizeof(typename Tsrcstring::value_type) == sizeof(char)); |
| 1178 |
static_assert(mpt::is_character<typename Tsrcstring::value_type>::value); |
| 1179 |
mpt::widestring decoded_string; |
| 1180 |
int required_size = MultiByteToWideChar(codepage, 0, reinterpret_cast<const CHAR *>(src.data()), mpt::saturate_cast<int>(src.size()), nullptr, 0); |
| 1181 |
if (required_size > 0) { |
| 1182 |
decoded_string.resize(required_size); |
| 1183 |
MultiByteToWideChar(codepage, 0, reinterpret_cast<const CHAR *>(src.data()), mpt::saturate_cast<int>(src.size()), decoded_string.data(), required_size); |
| 1184 |
} |
| 1185 |
return decoded_string; |
| 1186 |
} |
| 1187 |
|
| 1188 |
#endif // !MPT_COMPILER_QUIRK_NO_WCHAR |
| 1189 |
|
| 1190 |
#endif // MPT_OS_WINDOWS |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
#if MPT_OS_DJGPP |
| 1195 |
|
| 1196 |
inline common_encoding djgpp_get_locale_encoding() { |
| 1197 |
uint16 active_codepage = 437; |
| 1198 |
uint16 system_codepage = 437; |
| 1199 |
__dpmi_regs regs; |
| 1200 |
std::memset(®s, 0, sizeof(__dpmi_regs)); |
| 1201 |
regs.x.ax = 0x6601; |
| 1202 |
if (__dpmi_int(0x21, ®s) == 0) { |
| 1203 |
int cf = (regs.x.flags >> 0) & 1; |
| 1204 |
if (cf == 0) { |
| 1205 |
active_codepage = regs.x.bx; |
| 1206 |
system_codepage = regs.x.dx; |
| 1207 |
} |
| 1208 |
} |
| 1209 |
common_encoding result = common_encoding::cp437; |
| 1210 |
if (active_codepage == 0) { |
| 1211 |
result = common_encoding::cp437; |
| 1212 |
} else if (active_codepage == 437) { |
| 1213 |
result = common_encoding::cp437; |
| 1214 |
} else if (active_codepage == 737) { |
| 1215 |
result = common_encoding::cp737; |
| 1216 |
} else if (active_codepage == 775) { |
| 1217 |
result = common_encoding::cp775; |
| 1218 |
} else if (active_codepage == 850) { |
| 1219 |
result = common_encoding::cp850; |
| 1220 |
} else if (active_codepage == 852) { |
| 1221 |
result = common_encoding::cp852; |
| 1222 |
} else if (active_codepage == 855) { |
| 1223 |
result = common_encoding::cp855; |
| 1224 |
} else if (active_codepage == 857) { |
| 1225 |
result = common_encoding::cp857; |
| 1226 |
} else if (active_codepage == 860) { |
| 1227 |
result = common_encoding::cp860; |
| 1228 |
} else if (active_codepage == 861) { |
| 1229 |
result = common_encoding::cp861; |
| 1230 |
} else if (active_codepage == 862) { |
| 1231 |
result = common_encoding::cp862; |
| 1232 |
} else if (active_codepage == 863) { |
| 1233 |
result = common_encoding::cp863; |
| 1234 |
} else if (active_codepage == 864) { |
| 1235 |
result = common_encoding::cp864; |
| 1236 |
} else if (active_codepage == 865) { |
| 1237 |
result = common_encoding::cp865; |
| 1238 |
} else if (active_codepage == 866) { |
| 1239 |
result = common_encoding::cp866; |
| 1240 |
} else if (active_codepage == 869) { |
| 1241 |
result = common_encoding::cp869; |
| 1242 |
} else if (active_codepage == 874) { |
| 1243 |
result = common_encoding::cp874; |
| 1244 |
} else if (system_codepage == 437) { |
| 1245 |
result = common_encoding::cp437; |
| 1246 |
} else if (system_codepage == 737) { |
| 1247 |
result = common_encoding::cp737; |
| 1248 |
} else if (system_codepage == 775) { |
| 1249 |
result = common_encoding::cp775; |
| 1250 |
} else if (system_codepage == 850) { |
| 1251 |
result = common_encoding::cp850; |
| 1252 |
} else if (system_codepage == 852) { |
| 1253 |
result = common_encoding::cp852; |
| 1254 |
} else if (system_codepage == 855) { |
| 1255 |
result = common_encoding::cp855; |
| 1256 |
} else if (system_codepage == 857) { |
| 1257 |
result = common_encoding::cp857; |
| 1258 |
} else if (system_codepage == 860) { |
| 1259 |
result = common_encoding::cp860; |
| 1260 |
} else if (system_codepage == 861) { |
| 1261 |
result = common_encoding::cp861; |
| 1262 |
} else if (system_codepage == 862) { |
| 1263 |
result = common_encoding::cp862; |
| 1264 |
} else if (system_codepage == 863) { |
| 1265 |
result = common_encoding::cp863; |
| 1266 |
} else if (system_codepage == 864) { |
| 1267 |
result = common_encoding::cp864; |
| 1268 |
} else if (system_codepage == 865) { |
| 1269 |
result = common_encoding::cp865; |
| 1270 |
} else if (system_codepage == 866) { |
| 1271 |
result = common_encoding::cp866; |
| 1272 |
} else if (system_codepage == 869) { |
| 1273 |
result = common_encoding::cp869; |
| 1274 |
} else if (system_codepage == 874) { |
| 1275 |
result = common_encoding::cp874; |
| 1276 |
} else { |
| 1277 |
result = common_encoding::cp437; |
| 1278 |
} |
| 1279 |
return result; |
| 1280 |
} |
| 1281 |
|
| 1282 |
#endif // MPT_OS_DJGPP |
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
inline std::optional<common_encoding> optional_encoding_from_codepage(uint16 codepage) { |
| 1287 |
std::optional<common_encoding> result = std::nullopt; |
| 1288 |
switch (codepage) { |
| 1289 |
case 65001: |
| 1290 |
result = common_encoding::utf8; |
| 1291 |
break; |
| 1292 |
case 20127: |
| 1293 |
result = common_encoding::ascii; |
| 1294 |
break; |
| 1295 |
case 28591: |
| 1296 |
result = common_encoding::iso8859_1; |
| 1297 |
break; |
| 1298 |
case 28605: |
| 1299 |
result = common_encoding::iso8859_15; |
| 1300 |
break; |
| 1301 |
case 437: |
| 1302 |
result = common_encoding::cp437; |
| 1303 |
break; |
| 1304 |
case 737: |
| 1305 |
result = common_encoding::cp737; |
| 1306 |
break; |
| 1307 |
case 775: |
| 1308 |
result = common_encoding::cp775; |
| 1309 |
break; |
| 1310 |
case 850: |
| 1311 |
result = common_encoding::cp850; |
| 1312 |
break; |
| 1313 |
case 852: |
| 1314 |
result = common_encoding::cp852; |
| 1315 |
break; |
| 1316 |
case 855: |
| 1317 |
result = common_encoding::cp855; |
| 1318 |
break; |
| 1319 |
case 857: |
| 1320 |
result = common_encoding::cp857; |
| 1321 |
break; |
| 1322 |
case 860: |
| 1323 |
result = common_encoding::cp860; |
| 1324 |
break; |
| 1325 |
case 861: |
| 1326 |
result = common_encoding::cp861; |
| 1327 |
break; |
| 1328 |
case 862: |
| 1329 |
result = common_encoding::cp862; |
| 1330 |
break; |
| 1331 |
case 863: |
| 1332 |
result = common_encoding::cp863; |
| 1333 |
break; |
| 1334 |
case 864: |
| 1335 |
result = common_encoding::cp864; |
| 1336 |
break; |
| 1337 |
case 865: |
| 1338 |
result = common_encoding::cp865; |
| 1339 |
break; |
| 1340 |
case 866: |
| 1341 |
result = common_encoding::cp866; |
| 1342 |
break; |
| 1343 |
case 869: |
| 1344 |
result = common_encoding::cp869; |
| 1345 |
break; |
| 1346 |
case 874: |
| 1347 |
result = common_encoding::cp874; |
| 1348 |
break; |
| 1349 |
case 1252: |
| 1350 |
result = common_encoding::windows1252; |
| 1351 |
break; |
| 1352 |
default: |
| 1353 |
result = std::nullopt; |
| 1354 |
break; |
| 1355 |
} |
| 1356 |
return result; |
| 1357 |
} |
| 1358 |
|
| 1359 |
inline common_encoding encoding_from_codepage(uint16 codepage) { |
| 1360 |
std::optional<common_encoding> optional_result = optional_encoding_from_codepage(codepage); |
| 1361 |
if (!optional_result) { |
| 1362 |
throw std::domain_error("unsupported encoding"); |
| 1363 |
} |
| 1364 |
return *optional_result; |
| 1365 |
} |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1372 |
|
| 1373 |
// Note: |
| 1374 |
// |
| 1375 |
// std::codecvt::out in LLVM libc++ does not advance in and out pointers when |
| 1376 |
// running into a non-convertible character. This can happen when no locale is |
| 1377 |
// set on FreeBSD or MacOSX. This behaviour violates the C++ standard. |
| 1378 |
// |
| 1379 |
// We apply the following (albeit costly, even on other platforms) work-around: |
| 1380 |
// If the conversion errors out and does not advance the pointers at all, we |
| 1381 |
// retry the conversion with a space character prepended to the string. If it |
| 1382 |
// still does error out, we retry the whole conversion character by character. |
| 1383 |
// This is costly even on other platforms in one single case: The first |
| 1384 |
// character is an invalid Unicode code point or otherwise not convertible. Any |
| 1385 |
// following non-convertible characters are not a problem. |
| 1386 |
|
| 1387 |
inline std::wstring decode_locale_impl(const std::string & str, const std::locale & locale, wchar_t replacement = L'\uFFFD', int retry = 0, bool * progress = nullptr) { |
| 1388 |
if (str.empty()) { |
| 1389 |
return std::wstring(); |
| 1390 |
} |
| 1391 |
std::vector<wchar_t> out; |
| 1392 |
using codecvt_type = std::codecvt<wchar_t, char, std::mbstate_t>; |
| 1393 |
std::mbstate_t state = std::mbstate_t(); |
| 1394 |
const codecvt_type & facet = std::use_facet<codecvt_type>(locale); |
| 1395 |
codecvt_type::result result = codecvt_type::partial; |
| 1396 |
const char * in_begin = str.data(); |
| 1397 |
const char * in_end = in_begin + str.size(); |
| 1398 |
out.resize((in_end - in_begin) * (mpt::saturate_cast<std::size_t>(facet.max_length()) + 1)); |
| 1399 |
wchar_t * out_begin = out.data(); |
| 1400 |
wchar_t * out_end = out.data() + out.size(); |
| 1401 |
const char * in_next = nullptr; |
| 1402 |
wchar_t * out_next = nullptr; |
| 1403 |
do { |
| 1404 |
if (retry == 2) { |
| 1405 |
for (;;) { |
| 1406 |
in_next = nullptr; |
| 1407 |
out_next = nullptr; |
| 1408 |
result = facet.in(state, in_begin, in_begin + 1, in_next, out_begin, out_end, out_next); |
| 1409 |
if (result == codecvt_type::partial && in_next == in_begin + 1) { |
| 1410 |
in_begin = in_next; |
| 1411 |
out_begin = out_next; |
| 1412 |
continue; |
| 1413 |
} else { |
| 1414 |
break; |
| 1415 |
} |
| 1416 |
} |
| 1417 |
} else { |
| 1418 |
in_next = nullptr; |
| 1419 |
out_next = nullptr; |
| 1420 |
result = facet.in(state, in_begin, in_end, in_next, out_begin, out_end, out_next); |
| 1421 |
} |
| 1422 |
if (result == codecvt_type::partial || (result == codecvt_type::error && out_next == out_end)) { |
| 1423 |
out.resize(out.size() * 2); |
| 1424 |
in_begin = in_next; |
| 1425 |
out_begin = out.data() + (out_next - out_begin); |
| 1426 |
out_end = out.data() + out.size(); |
| 1427 |
continue; |
| 1428 |
} |
| 1429 |
if (retry == 0) { |
| 1430 |
if (result == codecvt_type::error && in_next == in_begin && out_next == out_begin) { |
| 1431 |
bool made_progress = true; |
| 1432 |
decode_locale_impl(std::string(" ") + str, locale, replacement, 1, &made_progress); |
| 1433 |
if (!made_progress) { |
| 1434 |
return decode_locale_impl(str, locale, replacement, 2); |
| 1435 |
} |
| 1436 |
} |
| 1437 |
} else if (retry == 1) { |
| 1438 |
if (result == codecvt_type::error && in_next == in_begin && out_next == out_begin) { |
| 1439 |
*progress = false; |
| 1440 |
} else { |
| 1441 |
*progress = true; |
| 1442 |
} |
| 1443 |
return std::wstring(); |
| 1444 |
} |
| 1445 |
if (result == codecvt_type::error) { |
| 1446 |
++in_next; |
| 1447 |
*out_next = replacement; |
| 1448 |
++out_next; |
| 1449 |
} |
| 1450 |
in_begin = in_next; |
| 1451 |
out_begin = out_next; |
| 1452 |
} while ((result == codecvt_type::error && in_next < in_end && out_next < out_end) || (retry == 2 && in_next < in_end)); |
| 1453 |
return std::wstring(out.data(), out_next); |
| 1454 |
} |
| 1455 |
|
| 1456 |
template <typename Tsrcstring> |
| 1457 |
inline mpt::widestring decode_locale(const std::locale & locale, const Tsrcstring & src) { |
| 1458 |
if constexpr (std::is_same<Tsrcstring, std::string>::value) { |
| 1459 |
return decode_locale_impl(src, locale); |
| 1460 |
} else { |
| 1461 |
return decode_locale_impl(std::string(src.begin(), src.end()), locale); |
| 1462 |
} |
| 1463 |
} |
| 1464 |
|
| 1465 |
inline std::string encode_locale_impl(const std::wstring & str, const std::locale & locale, char replacement = '?', int retry = 0, bool * progress = nullptr) { |
| 1466 |
if (str.empty()) { |
| 1467 |
return std::string(); |
| 1468 |
} |
| 1469 |
std::vector<char> out; |
| 1470 |
using codecvt_type = std::codecvt<wchar_t, char, std::mbstate_t>; |
| 1471 |
std::mbstate_t state = std::mbstate_t(); |
| 1472 |
const codecvt_type & facet = std::use_facet<codecvt_type>(locale); |
| 1473 |
codecvt_type::result result = codecvt_type::partial; |
| 1474 |
const wchar_t * in_begin = str.data(); |
| 1475 |
const wchar_t * in_end = in_begin + str.size(); |
| 1476 |
out.resize((in_end - in_begin) * (mpt::saturate_cast<std::size_t>(facet.max_length()) + 1)); |
| 1477 |
char * out_begin = out.data(); |
| 1478 |
char * out_end = out.data() + out.size(); |
| 1479 |
const wchar_t * in_next = nullptr; |
| 1480 |
char * out_next = nullptr; |
| 1481 |
do { |
| 1482 |
if (retry == 2) { |
| 1483 |
for (;;) { |
| 1484 |
in_next = nullptr; |
| 1485 |
out_next = nullptr; |
| 1486 |
result = facet.out(state, in_begin, in_begin + 1, in_next, out_begin, out_end, out_next); |
| 1487 |
if (result == codecvt_type::partial && in_next == in_begin + 1) { |
| 1488 |
in_begin = in_next; |
| 1489 |
out_begin = out_next; |
| 1490 |
continue; |
| 1491 |
} else { |
| 1492 |
break; |
| 1493 |
} |
| 1494 |
} |
| 1495 |
} else { |
| 1496 |
in_next = nullptr; |
| 1497 |
out_next = nullptr; |
| 1498 |
result = facet.out(state, in_begin, in_end, in_next, out_begin, out_end, out_next); |
| 1499 |
} |
| 1500 |
if (result == codecvt_type::partial || (result == codecvt_type::error && out_next == out_end)) { |
| 1501 |
out.resize(out.size() * 2); |
| 1502 |
in_begin = in_next; |
| 1503 |
out_begin = out.data() + (out_next - out_begin); |
| 1504 |
out_end = out.data() + out.size(); |
| 1505 |
continue; |
| 1506 |
} |
| 1507 |
if (retry == 0) { |
| 1508 |
if (result == codecvt_type::error && in_next == in_begin && out_next == out_begin) { |
| 1509 |
bool made_progress = true; |
| 1510 |
encode_locale_impl(std::wstring(L" ") + str, locale, replacement, 1, &made_progress); |
| 1511 |
if (!made_progress) { |
| 1512 |
return encode_locale_impl(str, locale, replacement, 2); |
| 1513 |
} |
| 1514 |
} |
| 1515 |
} else if (retry == 1) { |
| 1516 |
if (result == codecvt_type::error && in_next == in_begin && out_next == out_begin) { |
| 1517 |
*progress = false; |
| 1518 |
} else { |
| 1519 |
*progress = true; |
| 1520 |
} |
| 1521 |
return std::string(); |
| 1522 |
} |
| 1523 |
if (result == codecvt_type::error) { |
| 1524 |
++in_next; |
| 1525 |
*out_next = replacement; |
| 1526 |
++out_next; |
| 1527 |
} |
| 1528 |
in_begin = in_next; |
| 1529 |
out_begin = out_next; |
| 1530 |
} while ((result == codecvt_type::error && in_next < in_end && out_next < out_end) || (retry == 2 && in_next < in_end)); |
| 1531 |
return std::string(out.data(), out_next); |
| 1532 |
} |
| 1533 |
|
| 1534 |
template <typename Tdststring> |
| 1535 |
inline Tdststring encode_locale(const std::locale & locale, const mpt::widestring & src) { |
| 1536 |
if constexpr (std::is_same<Tdststring, std::string>::value) { |
| 1537 |
return encode_locale_impl(src, locale); |
| 1538 |
} else { |
| 1539 |
const std::string tmp = encode_locale_impl(src, locale); |
| 1540 |
return Tdststring(tmp.begin(), tmp.end()); |
| 1541 |
} |
| 1542 |
} |
| 1543 |
|
| 1544 |
#endif // !MPT_COMPILER_QUIRK_NO_WCHAR |
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
#if MPT_OS_WINDOWS && !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1549 |
template <typename Tdststring> |
| 1550 |
inline Tdststring encode(UINT codepage, const mpt::widestring & src) { |
| 1551 |
static_assert(sizeof(typename Tdststring::value_type) == sizeof(char)); |
| 1552 |
static_assert(mpt::is_character<typename Tdststring::value_type>::value); |
| 1553 |
return encode_codepage<Tdststring>(codepage, src); |
| 1554 |
} |
| 1555 |
#endif // MPT_OS_WINDOWS && !MPT_COMPILER_QUIRK_NO_WCHAR |
| 1556 |
|
| 1557 |
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1558 |
template <typename Tdststring> |
| 1559 |
inline Tdststring encode(const std::locale & locale, const mpt::widestring & src) { |
| 1560 |
static_assert(sizeof(typename Tdststring::value_type) == sizeof(char)); |
| 1561 |
static_assert(mpt::is_character<typename Tdststring::value_type>::value); |
| 1562 |
return encode_locale<Tdststring>(src, locale); |
| 1563 |
} |
| 1564 |
#endif // !MPT_COMPILER_QUIRK_NO_WCHAR |
| 1565 |
|
| 1566 |
template <typename Tdststring> |
| 1567 |
inline Tdststring encode(const char32_t (&table)[256], const mpt::widestring & src) { |
| 1568 |
static_assert(sizeof(typename Tdststring::value_type) == sizeof(char)); |
| 1569 |
static_assert(mpt::is_character<typename Tdststring::value_type>::value); |
| 1570 |
return encode_8bit<Tdststring>(src, table); |
| 1571 |
} |
| 1572 |
|
| 1573 |
template <typename Tdststring> |
| 1574 |
inline Tdststring encode(common_encoding encoding, const mpt::widestring & src) { |
| 1575 |
static_assert(sizeof(typename Tdststring::value_type) == sizeof(char)); |
| 1576 |
static_assert(mpt::is_character<typename Tdststring::value_type>::value); |
| 1577 |
#if MPT_OS_WINDOWS && !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1578 |
if (windows_has_encoding(encoding)) { |
| 1579 |
return encode_codepage<Tdststring>(codepage_from_encoding(encoding), src); |
| 1580 |
} |
| 1581 |
#endif // MPT_OS_WINDOWS && !MPT_COMPILER_QUIRK_NO_WCHAR |
| 1582 |
switch (encoding) { |
| 1583 |
case common_encoding::utf8: |
| 1584 |
return encode_utf8<Tdststring>(src); |
| 1585 |
break; |
| 1586 |
case common_encoding::ascii: |
| 1587 |
return encode_ascii<Tdststring>(src); |
| 1588 |
break; |
| 1589 |
case common_encoding::iso8859_1: |
| 1590 |
return encode_iso8859_1<Tdststring>(src); |
| 1591 |
break; |
| 1592 |
case common_encoding::iso8859_15: |
| 1593 |
return encode_8bit<Tdststring>(src, CharsetTableISO8859_15); |
| 1594 |
break; |
| 1595 |
case common_encoding::cp437: |
| 1596 |
return encode_8bit<Tdststring>(src, CharsetTableCP437); |
| 1597 |
break; |
| 1598 |
case common_encoding::cp737: |
| 1599 |
return encode_8bit<Tdststring>(src, CharsetTableCP737); |
| 1600 |
break; |
| 1601 |
case common_encoding::cp775: |
| 1602 |
return encode_8bit<Tdststring>(src, CharsetTableCP775); |
| 1603 |
break; |
| 1604 |
case common_encoding::cp850: |
| 1605 |
return encode_8bit<Tdststring>(src, CharsetTableCP850); |
| 1606 |
break; |
| 1607 |
case common_encoding::cp852: |
| 1608 |
return encode_8bit<Tdststring>(src, CharsetTableCP852); |
| 1609 |
break; |
| 1610 |
case common_encoding::cp855: |
| 1611 |
return encode_8bit<Tdststring>(src, CharsetTableCP855); |
| 1612 |
break; |
| 1613 |
case common_encoding::cp857: |
| 1614 |
return encode_8bit<Tdststring>(src, CharsetTableCP857); |
| 1615 |
break; |
| 1616 |
case common_encoding::cp860: |
| 1617 |
return encode_8bit<Tdststring>(src, CharsetTableCP860); |
| 1618 |
break; |
| 1619 |
case common_encoding::cp861: |
| 1620 |
return encode_8bit<Tdststring>(src, CharsetTableCP861); |
| 1621 |
break; |
| 1622 |
case common_encoding::cp862: |
| 1623 |
return encode_8bit<Tdststring>(src, CharsetTableCP862); |
| 1624 |
break; |
| 1625 |
case common_encoding::cp863: |
| 1626 |
return encode_8bit<Tdststring>(src, CharsetTableCP863); |
| 1627 |
break; |
| 1628 |
case common_encoding::cp864: |
| 1629 |
return encode_8bit<Tdststring>(src, CharsetTableCP864); |
| 1630 |
break; |
| 1631 |
case common_encoding::cp865: |
| 1632 |
return encode_8bit<Tdststring>(src, CharsetTableCP865); |
| 1633 |
break; |
| 1634 |
case common_encoding::cp866: |
| 1635 |
return encode_8bit<Tdststring>(src, CharsetTableCP866); |
| 1636 |
break; |
| 1637 |
case common_encoding::cp869: |
| 1638 |
return encode_8bit<Tdststring>(src, CharsetTableCP869); |
| 1639 |
break; |
| 1640 |
case common_encoding::cp874: |
| 1641 |
return encode_8bit<Tdststring>(src, CharsetTableCP874); |
| 1642 |
break; |
| 1643 |
case common_encoding::windows1252: |
| 1644 |
return encode_8bit<Tdststring>(src, CharsetTableWindows1252); |
| 1645 |
break; |
| 1646 |
case common_encoding::amiga: |
| 1647 |
return encode_8bit<Tdststring>(src, CharsetTableAmiga); |
| 1648 |
break; |
| 1649 |
case common_encoding::riscos: |
| 1650 |
return encode_8bit<Tdststring>(src, CharsetTableRISC_OS); |
| 1651 |
break; |
| 1652 |
case common_encoding::atarist: |
| 1653 |
return encode_8bit<Tdststring>(src, CharsetTableAtariST); |
| 1654 |
break; |
| 1655 |
case common_encoding::iso8859_1_no_c1: |
| 1656 |
return encode_8bit_no_c1<Tdststring>(src, CharsetTableISO8859_1); |
| 1657 |
break; |
| 1658 |
case common_encoding::iso8859_15_no_c1: |
| 1659 |
return encode_8bit_no_c1<Tdststring>(src, CharsetTableISO8859_15); |
| 1660 |
break; |
| 1661 |
case common_encoding::amiga_no_c1: |
| 1662 |
return encode_8bit_no_c1<Tdststring>(src, CharsetTableAmiga); |
| 1663 |
break; |
| 1664 |
} |
| 1665 |
throw std::domain_error("unsupported encoding"); |
| 1666 |
} |
| 1667 |
|
| 1668 |
template <typename Tdststring> |
| 1669 |
inline Tdststring encode(logical_encoding encoding, const mpt::widestring & src) { |
| 1670 |
static_assert(sizeof(typename Tdststring::value_type) == sizeof(char)); |
| 1671 |
static_assert(mpt::is_character<typename Tdststring::value_type>::value); |
| 1672 |
#if MPT_OS_WINDOWS && !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1673 |
if (windows_has_encoding(encoding)) { |
| 1674 |
return encode_codepage<Tdststring>(codepage_from_encoding(encoding), src); |
| 1675 |
} |
| 1676 |
#elif MPT_OS_WINDOWS && defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1677 |
switch (encoding) { |
| 1678 |
case logical_encoding::locale: |
| 1679 |
return encode<Tdststring>(optional_encoding_from_codepage(GetACP()).value_or(common_encoding::windows1252), src); |
| 1680 |
break; |
| 1681 |
case logical_encoding::active_locale: |
| 1682 |
return encode<Tdststring>(optional_encoding_from_codepage(GetACP()).value_or(common_encoding::windows1252), src); |
| 1683 |
break; |
| 1684 |
} |
| 1685 |
throw std::domain_error("unsupported encoding"); |
| 1686 |
#endif // MPT_OS_WINDOWS && !MPT_COMPILER_QUIRK_NO_WCHAR |
| 1687 |
#if MPT_OS_DJGPP |
| 1688 |
switch (encoding) { |
| 1689 |
case logical_encoding::locale: |
| 1690 |
return encode<Tdststring>(djgpp_get_locale_encoding(), src); |
| 1691 |
break; |
| 1692 |
case logical_encoding::active_locale: |
| 1693 |
return encode<Tdststring>(djgpp_get_locale_encoding(), src); |
| 1694 |
break; |
| 1695 |
} |
| 1696 |
throw std::domain_error("unsupported encoding"); |
| 1697 |
#elif !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1698 |
switch (encoding) { |
| 1699 |
case logical_encoding::locale: |
| 1700 |
#if defined(MPT_LIBCXX_QUIRK_BROKEN_USER_LOCALE) |
| 1701 |
#if defined(MPT_LIBCXX_QUIRK_ASSUME_USER_LOCALE_UTF8) |
| 1702 |
return encode_utf8<Tdststring>(src); |
| 1703 |
#else |
| 1704 |
try { |
| 1705 |
return encode_locale<Tdststring>(std::locale(""), src); |
| 1706 |
} catch (mpt::out_of_memory e) { |
| 1707 |
mpt::rethrow_out_of_memory(e); |
| 1708 |
} catch (...) { |
| 1709 |
// nothing |
| 1710 |
} |
| 1711 |
try { |
| 1712 |
return encode_locale<Tdststring>(std::locale(), src); |
| 1713 |
} catch (mpt::out_of_memory e) { |
| 1714 |
mpt::rethrow_out_of_memory(e); |
| 1715 |
} catch (...) { |
| 1716 |
// nothing |
| 1717 |
} |
| 1718 |
try { |
| 1719 |
return encode_locale<Tdststring>(std::locale::classic(), src); |
| 1720 |
} catch (mpt::out_of_memory e) { |
| 1721 |
mpt::rethrow_out_of_memory(e); |
| 1722 |
} catch (...) { |
| 1723 |
// nothing |
| 1724 |
} |
| 1725 |
return encode_ascii<Tdststring>(src); |
| 1726 |
#endif |
| 1727 |
#else |
| 1728 |
return encode_locale<Tdststring>(std::locale(""), src); |
| 1729 |
#endif |
| 1730 |
break; |
| 1731 |
case logical_encoding::active_locale: |
| 1732 |
#if defined(MPT_LIBCXX_QUIRK_BROKEN_ACTIVE_LOCALE) |
| 1733 |
try { |
| 1734 |
return encode_locale<Tdststring>(std::locale(), src); |
| 1735 |
} catch (mpt::out_of_memory e) { |
| 1736 |
mpt::rethrow_out_of_memory(e); |
| 1737 |
} catch (...) { |
| 1738 |
// nothing |
| 1739 |
} |
| 1740 |
try { |
| 1741 |
return encode_locale<Tdststring>(std::locale(""), src); |
| 1742 |
} catch (mpt::out_of_memory e) { |
| 1743 |
mpt::rethrow_out_of_memory(e); |
| 1744 |
} catch (...) { |
| 1745 |
// nothing |
| 1746 |
} |
| 1747 |
try { |
| 1748 |
return encode_locale<Tdststring>(std::locale::classic(), src); |
| 1749 |
} catch (mpt::out_of_memory e) { |
| 1750 |
mpt::rethrow_out_of_memory(e); |
| 1751 |
} catch (...) { |
| 1752 |
// nothing |
| 1753 |
} |
| 1754 |
return encode_ascii<Tdststring>(src); |
| 1755 |
#else |
| 1756 |
return encode_locale<Tdststring>(std::locale(), src); |
| 1757 |
#endif |
| 1758 |
break; |
| 1759 |
} |
| 1760 |
throw std::domain_error("unsupported encoding"); |
| 1761 |
#else |
| 1762 |
throw std::domain_error("unsupported encoding"); |
| 1763 |
#endif |
| 1764 |
} |
| 1765 |
|
| 1766 |
template <typename Tdststring, typename Ttranscoder> |
| 1767 |
inline auto encode(Ttranscoder transcoder, const mpt::widestring & src) -> decltype(transcoder.template encode<Tdststring>(src)) { |
| 1768 |
static_assert(sizeof(typename Tdststring::value_type) == sizeof(char)); |
| 1769 |
static_assert(mpt::is_character<typename Tdststring::value_type>::value); |
| 1770 |
return transcoder.template encode<Tdststring>(src); |
| 1771 |
} |
| 1772 |
|
| 1773 |
#if MPT_OS_WINDOWS |
| 1774 |
template <typename Tsrcstring> |
| 1775 |
inline mpt::widestring decode(UINT codepage, const Tsrcstring & src) { |
| 1776 |
static_assert(sizeof(typename Tsrcstring::value_type) == sizeof(char)); |
| 1777 |
static_assert(mpt::is_character<typename Tsrcstring::value_type>::value); |
| 1778 |
return decode_codepage(codepage, src); |
| 1779 |
} |
| 1780 |
#endif // MPT_OS_WINDOWS |
| 1781 |
|
| 1782 |
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1783 |
template <typename Tsrcstring> |
| 1784 |
inline mpt::widestring decode(const std::locale & locale, const Tsrcstring & src) { |
| 1785 |
static_assert(sizeof(typename Tsrcstring::value_type) == sizeof(char)); |
| 1786 |
static_assert(mpt::is_character<typename Tsrcstring::value_type>::value); |
| 1787 |
return decode_locale(src, locale); |
| 1788 |
} |
| 1789 |
#endif // !MPT_COMPILER_QUIRK_NO_WCHAR |
| 1790 |
|
| 1791 |
template <typename Tsrcstring> |
| 1792 |
inline mpt::widestring decode(const char32_t (&table)[256], const Tsrcstring & src) { |
| 1793 |
static_assert(sizeof(typename Tsrcstring::value_type) == sizeof(char)); |
| 1794 |
static_assert(mpt::is_character<typename Tsrcstring::value_type>::value); |
| 1795 |
return decode_8bit(src, table); |
| 1796 |
} |
| 1797 |
|
| 1798 |
template <typename Tsrcstring> |
| 1799 |
inline mpt::widestring decode(common_encoding encoding, const Tsrcstring & src) { |
| 1800 |
static_assert(sizeof(typename Tsrcstring::value_type) == sizeof(char)); |
| 1801 |
static_assert(mpt::is_character<typename Tsrcstring::value_type>::value); |
| 1802 |
#if MPT_OS_WINDOWS && !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1803 |
if (windows_has_encoding(encoding)) { |
| 1804 |
return decode_codepage(codepage_from_encoding(encoding), src); |
| 1805 |
} |
| 1806 |
#endif // MPT_OS_WINDOWS && !MPT_COMPILER_QUIRK_NO_WCHAR |
| 1807 |
switch (encoding) { |
| 1808 |
case common_encoding::utf8: |
| 1809 |
return decode_utf8(src); |
| 1810 |
break; |
| 1811 |
case common_encoding::ascii: |
| 1812 |
return decode_ascii(src); |
| 1813 |
break; |
| 1814 |
case common_encoding::iso8859_1: |
| 1815 |
return decode_iso8859_1(src); |
| 1816 |
break; |
| 1817 |
case common_encoding::iso8859_15: |
| 1818 |
return decode_8bit(src, CharsetTableISO8859_15); |
| 1819 |
break; |
| 1820 |
case common_encoding::cp437: |
| 1821 |
return decode_8bit(src, CharsetTableCP437); |
| 1822 |
break; |
| 1823 |
case common_encoding::cp737: |
| 1824 |
return decode_8bit(src, CharsetTableCP737); |
| 1825 |
break; |
| 1826 |
case common_encoding::cp775: |
| 1827 |
return decode_8bit(src, CharsetTableCP775); |
| 1828 |
break; |
| 1829 |
case common_encoding::cp850: |
| 1830 |
return decode_8bit(src, CharsetTableCP850); |
| 1831 |
break; |
| 1832 |
case common_encoding::cp852: |
| 1833 |
return decode_8bit(src, CharsetTableCP852); |
| 1834 |
break; |
| 1835 |
case common_encoding::cp855: |
| 1836 |
return decode_8bit(src, CharsetTableCP855); |
| 1837 |
break; |
| 1838 |
case common_encoding::cp857: |
| 1839 |
return decode_8bit(src, CharsetTableCP857); |
| 1840 |
break; |
| 1841 |
case common_encoding::cp860: |
| 1842 |
return decode_8bit(src, CharsetTableCP860); |
| 1843 |
break; |
| 1844 |
case common_encoding::cp861: |
| 1845 |
return decode_8bit(src, CharsetTableCP861); |
| 1846 |
break; |
| 1847 |
case common_encoding::cp862: |
| 1848 |
return decode_8bit(src, CharsetTableCP862); |
| 1849 |
break; |
| 1850 |
case common_encoding::cp863: |
| 1851 |
return decode_8bit(src, CharsetTableCP863); |
| 1852 |
break; |
| 1853 |
case common_encoding::cp864: |
| 1854 |
return decode_8bit(src, CharsetTableCP864); |
| 1855 |
break; |
| 1856 |
case common_encoding::cp865: |
| 1857 |
return decode_8bit(src, CharsetTableCP865); |
| 1858 |
break; |
| 1859 |
case common_encoding::cp866: |
| 1860 |
return decode_8bit(src, CharsetTableCP866); |
| 1861 |
break; |
| 1862 |
case common_encoding::cp869: |
| 1863 |
return decode_8bit(src, CharsetTableCP869); |
| 1864 |
break; |
| 1865 |
case common_encoding::cp874: |
| 1866 |
return decode_8bit(src, CharsetTableCP874); |
| 1867 |
break; |
| 1868 |
case common_encoding::windows1252: |
| 1869 |
return decode_8bit(src, CharsetTableWindows1252); |
| 1870 |
break; |
| 1871 |
case common_encoding::amiga: |
| 1872 |
return decode_8bit(src, CharsetTableAmiga); |
| 1873 |
break; |
| 1874 |
case common_encoding::riscos: |
| 1875 |
return decode_8bit(src, CharsetTableRISC_OS); |
| 1876 |
break; |
| 1877 |
case common_encoding::atarist: |
| 1878 |
return decode_8bit(src, CharsetTableAtariST); |
| 1879 |
break; |
| 1880 |
case common_encoding::iso8859_1_no_c1: |
| 1881 |
return decode_8bit_no_c1(src, CharsetTableISO8859_1); |
| 1882 |
break; |
| 1883 |
case common_encoding::iso8859_15_no_c1: |
| 1884 |
return decode_8bit_no_c1(src, CharsetTableISO8859_15); |
| 1885 |
break; |
| 1886 |
case common_encoding::amiga_no_c1: |
| 1887 |
return decode_8bit_no_c1(src, CharsetTableAmiga); |
| 1888 |
break; |
| 1889 |
} |
| 1890 |
throw std::domain_error("unsupported encoding"); |
| 1891 |
} |
| 1892 |
|
| 1893 |
template <typename Tsrcstring> |
| 1894 |
inline mpt::widestring decode(logical_encoding encoding, const Tsrcstring & src) { |
| 1895 |
static_assert(sizeof(typename Tsrcstring::value_type) == sizeof(char)); |
| 1896 |
static_assert(mpt::is_character<typename Tsrcstring::value_type>::value); |
| 1897 |
#if MPT_OS_WINDOWS && !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1898 |
if (windows_has_encoding(encoding)) { |
| 1899 |
return decode_codepage(codepage_from_encoding(encoding), src); |
| 1900 |
} |
| 1901 |
#elif MPT_OS_WINDOWS && defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1902 |
switch (encoding) { |
| 1903 |
case logical_encoding::locale: |
| 1904 |
return decode(optional_encoding_from_codepage(GetACP()).value_or(common_encoding::windows1252), src); |
| 1905 |
break; |
| 1906 |
case logical_encoding::active_locale: |
| 1907 |
return decode(optional_encoding_from_codepage(GetACP()).value_or(common_encoding::windows1252), src); |
| 1908 |
break; |
| 1909 |
} |
| 1910 |
throw std::domain_error("unsupported encoding"); |
| 1911 |
#endif // MPT_OS_WINDOWS && !MPT_COMPILER_QUIRK_NO_WCHAR |
| 1912 |
#if MPT_OS_DJGPP |
| 1913 |
switch (encoding) { |
| 1914 |
case logical_encoding::locale: |
| 1915 |
return decode(djgpp_get_locale_encoding(), src); |
| 1916 |
break; |
| 1917 |
case logical_encoding::active_locale: |
| 1918 |
return decode(djgpp_get_locale_encoding(), src); |
| 1919 |
break; |
| 1920 |
} |
| 1921 |
throw std::domain_error("unsupported encoding"); |
| 1922 |
#elif !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 1923 |
switch (encoding) { |
| 1924 |
case logical_encoding::locale: |
| 1925 |
#if defined(MPT_LIBCXX_QUIRK_BROKEN_USER_LOCALE) |
| 1926 |
#if defined(MPT_LIBCXX_QUIRK_ASSUME_USER_LOCALE_UTF8) |
| 1927 |
return decode_utf8(src); |
| 1928 |
#else |
| 1929 |
try { |
| 1930 |
return decode_locale(std::locale(""), src); |
| 1931 |
} catch (mpt::out_of_memory e) { |
| 1932 |
mpt::rethrow_out_of_memory(e); |
| 1933 |
} catch (...) { |
| 1934 |
// nothing |
| 1935 |
} |
| 1936 |
try { |
| 1937 |
return decode_locale(std::locale(), src); |
| 1938 |
} catch (mpt::out_of_memory e) { |
| 1939 |
mpt::rethrow_out_of_memory(e); |
| 1940 |
} catch (...) { |
| 1941 |
// nothing |
| 1942 |
} |
| 1943 |
try { |
| 1944 |
return decode_locale(std::locale::classic(), src); |
| 1945 |
} catch (mpt::out_of_memory e) { |
| 1946 |
mpt::rethrow_out_of_memory(e); |
| 1947 |
} catch (...) { |
| 1948 |
// nothing |
| 1949 |
} |
| 1950 |
return decode_ascii(src); |
| 1951 |
#endif |
| 1952 |
#else |
| 1953 |
return decode_locale(std::locale(""), src); |
| 1954 |
#endif |
| 1955 |
break; |
| 1956 |
case logical_encoding::active_locale: |
| 1957 |
#if defined(MPT_LIBCXX_QUIRK_BROKEN_ACTIVE_LOCALE) |
| 1958 |
try { |
| 1959 |
return decode_locale(std::locale(), src); |
| 1960 |
} catch (mpt::out_of_memory e) { |
| 1961 |
mpt::rethrow_out_of_memory(e); |
| 1962 |
} catch (...) { |
| 1963 |
// nothing |
| 1964 |
} |
| 1965 |
try { |
| 1966 |
return decode_locale(std::locale(""), src); |
| 1967 |
} catch (mpt::out_of_memory e) { |
| 1968 |
mpt::rethrow_out_of_memory(e); |
| 1969 |
} catch (...) { |
| 1970 |
// nothing |
| 1971 |
} |
| 1972 |
try { |
| 1973 |
return decode_locale(std::locale::classic(), src); |
| 1974 |
} catch (mpt::out_of_memory e) { |
| 1975 |
mpt::rethrow_out_of_memory(e); |
| 1976 |
} catch (...) { |
| 1977 |
// nothing |
| 1978 |
} |
| 1979 |
return decode_ascii(src); |
| 1980 |
#else |
| 1981 |
return decode_locale(std::locale(), src); |
| 1982 |
#endif |
| 1983 |
break; |
| 1984 |
} |
| 1985 |
throw std::domain_error("unsupported encoding"); |
| 1986 |
#else |
| 1987 |
throw std::domain_error("unsupported encoding"); |
| 1988 |
#endif |
| 1989 |
} |
| 1990 |
|
| 1991 |
template <typename Tsrcstring, typename Ttranscoder> |
| 1992 |
inline auto decode(Ttranscoder transcoder, const Tsrcstring & src) -> decltype(transcoder.template decode<Tsrcstring>(src)) { |
| 1993 |
static_assert(sizeof(typename Tsrcstring::value_type) == sizeof(char)); |
| 1994 |
static_assert(mpt::is_character<typename Tsrcstring::value_type>::value); |
| 1995 |
return transcoder.template decode<Tsrcstring>(src); |
| 1996 |
} |
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
inline bool is_utf8(const std::string & str) { |
| 2001 |
return (str == encode<std::string>(common_encoding::utf8, decode<std::string>(common_encoding::utf8, str))); |
| 2002 |
} |
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
template <typename Tstring> |
| 2007 |
struct string_transcoder { |
| 2008 |
}; |
| 2009 |
|
| 2010 |
#if defined(MPT_COMPILER_QUIRK_NO_AUTO_TEMPLATE_ARGUMENT) |
| 2011 |
template <typename encoding_type, encoding_type encoding> |
| 2012 |
struct string_transcoder<std::basic_string<char, encoding_char_traits<encoding_type, encoding>>> { |
| 2013 |
using string_type = std::basic_string<char, encoding_char_traits<encoding_type, encoding>>; |
| 2014 |
static inline mpt::widestring decode(const string_type & src) { |
| 2015 |
return mpt::decode<string_type>(encoding, src); |
| 2016 |
} |
| 2017 |
static inline string_type encode(const mpt::widestring & src) { |
| 2018 |
return mpt::encode<string_type>(encoding, src); |
| 2019 |
} |
| 2020 |
}; |
| 2021 |
#else |
| 2022 |
template <auto encoding> |
| 2023 |
struct string_transcoder<std::basic_string<char, encoding_char_traits<encoding>>> { |
| 2024 |
using string_type = std::basic_string<char, encoding_char_traits<encoding>>; |
| 2025 |
static inline mpt::widestring decode(const string_type & src) { |
| 2026 |
return mpt::decode<string_type>(encoding, src); |
| 2027 |
} |
| 2028 |
static inline string_type encode(const mpt::widestring & src) { |
| 2029 |
return mpt::encode<string_type>(encoding, src); |
| 2030 |
} |
| 2031 |
}; |
| 2032 |
#endif |
| 2033 |
|
| 2034 |
#if !defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 2035 |
template <> |
| 2036 |
struct string_transcoder<std::wstring> { |
| 2037 |
using string_type = std::wstring; |
| 2038 |
static inline mpt::widestring decode(const string_type & src) { |
| 2039 |
return src; |
| 2040 |
} |
| 2041 |
static inline string_type encode(const mpt::widestring & src) { |
| 2042 |
return src; |
| 2043 |
} |
| 2044 |
}; |
| 2045 |
#endif // !MPT_COMPILER_QUIRK_NO_WCHAR |
| 2046 |
|
| 2047 |
#if MPT_CXX_AT_LEAST(20) |
| 2048 |
template <> |
| 2049 |
struct string_transcoder<std::u8string> { |
| 2050 |
using string_type = std::u8string; |
| 2051 |
static inline mpt::widestring decode(const string_type & src) { |
| 2052 |
return mpt::decode_utf8<string_type>(src); |
| 2053 |
} |
| 2054 |
static inline string_type encode(const mpt::widestring & src) { |
| 2055 |
return mpt::encode_utf8<string_type>(src); |
| 2056 |
} |
| 2057 |
}; |
| 2058 |
#endif // C++10 |
| 2059 |
|
| 2060 |
template <> |
| 2061 |
struct string_transcoder<std::u16string> { |
| 2062 |
using string_type = std::u16string; |
| 2063 |
static inline mpt::widestring decode(const string_type & src) { |
| 2064 |
if constexpr (sizeof(mpt::widechar) == sizeof(char16_t)) { |
| 2065 |
return mpt::widestring(src.begin(), src.end()); |
| 2066 |
} else { |
| 2067 |
return utf32_from_utf16<mpt::widestring, std::u16string>(src); |
| 2068 |
} |
| 2069 |
} |
| 2070 |
static inline string_type encode(const mpt::widestring & src) { |
| 2071 |
if constexpr (sizeof(mpt::widechar) == sizeof(char16_t)) { |
| 2072 |
return string_type(src.begin(), src.end()); |
| 2073 |
} else { |
| 2074 |
return utf16_from_utf32<std::u16string, mpt::widestring>(src); |
| 2075 |
} |
| 2076 |
} |
| 2077 |
}; |
| 2078 |
|
| 2079 |
#if defined(MPT_COMPILER_QUIRK_NO_WCHAR) |
| 2080 |
template <> |
| 2081 |
struct string_transcoder<std::u32string> { |
| 2082 |
using string_type = std::u32string; |
| 2083 |
static inline mpt::widestring decode(const string_type & src) { |
| 2084 |
return src; |
| 2085 |
} |
| 2086 |
static inline string_type encode(const mpt::widestring & src) { |
| 2087 |
return src; |
| 2088 |
} |
| 2089 |
}; |
| 2090 |
#else // !MPT_COMPILER_QUIRK_NO_WCHAR |
| 2091 |
template <> |
| 2092 |
struct string_transcoder<std::u32string> { |
| 2093 |
using string_type = std::u32string; |
| 2094 |
static inline mpt::widestring decode(const string_type & src) { |
| 2095 |
if constexpr (sizeof(mpt::widechar) == sizeof(char32_t)) { |
| 2096 |
return mpt::widestring(src.begin(), src.end()); |
| 2097 |
} else { |
| 2098 |
return utf16_from_utf32<mpt::widestring, std::u32string>(src); |
| 2099 |
} |
| 2100 |
} |
| 2101 |
static inline string_type encode(const mpt::widestring & src) { |
| 2102 |
if constexpr (sizeof(mpt::widechar) == sizeof(char32_t)) { |
| 2103 |
return string_type(src.begin(), src.end()); |
| 2104 |
} else { |
| 2105 |
return utf32_from_utf16<std::u32string, mpt::widestring>(src); |
| 2106 |
} |
| 2107 |
} |
| 2108 |
}; |
| 2109 |
#endif // MPT_COMPILER_QUIRK_NO_WCHAR |
| 2110 |
|
| 2111 |
#if MPT_DETECTED_MFC |
| 2112 |
|
| 2113 |
template <> |
| 2114 |
struct string_transcoder<CStringW> { |
| 2115 |
using string_type = CStringW; |
| 2116 |
static inline mpt::widestring decode(const string_type & src) { |
| 2117 |
return mpt::widestring(src.GetString()); |
| 2118 |
} |
| 2119 |
static inline string_type encode(const mpt::widestring & src) { |
| 2120 |
return src.c_str(); |
| 2121 |
} |
| 2122 |
}; |
| 2123 |
|
| 2124 |
template <> |
| 2125 |
struct string_transcoder<CStringA> { |
| 2126 |
using string_type = CStringA; |
| 2127 |
static inline mpt::widestring decode(const string_type & src) { |
| 2128 |
return mpt::decode<std::string>(mpt::logical_encoding::locale, std::string(src.GetString())); |
| 2129 |
} |
| 2130 |
static inline string_type encode(const mpt::widestring & src) { |
| 2131 |
return mpt::encode<std::string>(mpt::logical_encoding::locale, src).c_str(); |
| 2132 |
} |
| 2133 |
}; |
| 2134 |
|
| 2135 |
#endif // MPT_DETECTED_MFC |
| 2136 |
|
| 2137 |
template <typename Tdststring, typename Tsrcstring, std::enable_if_t<mpt::is_string_type<typename mpt::make_string_type<typename std::decay<Tsrcstring>::type>::type>::value, bool> = true> |
| 2138 |
inline Tdststring transcode(Tsrcstring && src) { |
| 2139 |
if constexpr (std::is_same<Tdststring, typename mpt::make_string_type<typename std::decay<Tsrcstring>::type>::type>::value) { |
| 2140 |
return mpt::as_string(std::forward<Tsrcstring>(src)); |
| 2141 |
} else { |
| 2142 |
return string_transcoder<Tdststring>::encode(string_transcoder<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>::decode(mpt::as_string(std::forward<Tsrcstring>(src)))); |
| 2143 |
} |
| 2144 |
} |
| 2145 |
|
| 2146 |
template <typename Tdststring, typename Tsrcstring, typename Tencoding, std::enable_if_t<std::is_same<Tdststring, std::string>::value, bool> = true, std::enable_if_t<mpt::is_string_type<typename mpt::make_string_type<typename std::decay<Tsrcstring>::type>::type>::value, bool> = true> |
| 2147 |
inline Tdststring transcode(Tencoding to, Tsrcstring && src) { |
| 2148 |
if constexpr (std::is_same<Tencoding, mpt::common_encoding>::value) { |
| 2149 |
if constexpr (std::is_same<decltype(mpt::as_string(std::forward<Tsrcstring>(src))), mpt::u8string>::value) { |
| 2150 |
if (to == mpt::common_encoding::utf8) { |
| 2151 |
auto src_ = mpt::as_string(std::forward<Tsrcstring>(src)); |
| 2152 |
Tdststring dst; |
| 2153 |
mpt::string_traits<Tdststring>::reserve(dst, mpt::string_traits<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>::length(src_)); |
| 2154 |
for (std::size_t i = 0; i < mpt::saturate_cast<std::size_t>(mpt::string_traits<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>::length(src_)); ++i) { |
| 2155 |
mpt::string_traits<Tdststring>::append(dst, static_cast<typename mpt::string_traits<Tdststring>::unsigned_char_type>(static_cast<typename mpt::string_traits<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>::unsigned_char_type>(src_[i]))); |
| 2156 |
} |
| 2157 |
return dst; |
| 2158 |
} |
| 2159 |
} |
| 2160 |
} |
| 2161 |
return mpt::encode<Tdststring>(to, string_transcoder<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>::decode(mpt::as_string(std::forward<Tsrcstring>(src)))); |
| 2162 |
} |
| 2163 |
|
| 2164 |
template <typename Tdststring, typename Tsrcstring, typename Tencoding, std::enable_if_t<std::is_same<typename mpt::make_string_type<typename std::decay<Tsrcstring>::type>::type, std::string>::value, bool> = true, std::enable_if_t<mpt::is_string_type<typename mpt::make_string_type<typename std::decay<Tsrcstring>::type>::type>::value, bool> = true> |
| 2165 |
inline Tdststring transcode(Tencoding from, Tsrcstring && src) { |
| 2166 |
if constexpr (std::is_same<Tencoding, mpt::common_encoding>::value) { |
| 2167 |
if constexpr (std::is_same<Tdststring, mpt::u8string>::value) { |
| 2168 |
if (from == mpt::common_encoding::utf8) { |
| 2169 |
auto src_ = mpt::as_string(std::forward<Tsrcstring>(src)); |
| 2170 |
Tdststring dst; |
| 2171 |
mpt::string_traits<Tdststring>::reserve(dst, mpt::string_traits<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>::length(src_)); |
| 2172 |
for (std::size_t i = 0; i < mpt::saturate_cast<std::size_t>(mpt::string_traits<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>::length(src_)); ++i) { |
| 2173 |
mpt::string_traits<Tdststring>::append(dst, static_cast<typename mpt::string_traits<Tdststring>::unsigned_char_type>(static_cast<typename mpt::string_traits<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>::unsigned_char_type>(src_[i]))); |
| 2174 |
} |
| 2175 |
return dst; |
| 2176 |
} |
| 2177 |
} |
| 2178 |
} |
| 2179 |
return string_transcoder<Tdststring>::encode(mpt::decode<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>(from, mpt::as_string(std::forward<Tsrcstring>(src)))); |
| 2180 |
} |
| 2181 |
|
| 2182 |
template <typename Tdststring, typename Tsrcstring, typename Tto, typename Tfrom, std::enable_if_t<mpt::is_string_type<typename mpt::make_string_type<typename std::decay<Tsrcstring>::type>::type>::value, bool> = true> |
| 2183 |
inline Tdststring transcode(Tto to, Tfrom from, Tsrcstring && src) { |
| 2184 |
if constexpr (std::is_same<Tto, Tfrom>::value) { |
| 2185 |
if constexpr (std::is_same<decltype(mpt::as_string(std::forward<Tsrcstring>(src))), Tdststring>::value) { |
| 2186 |
if (to == from) { |
| 2187 |
return mpt::as_string(std::forward<Tsrcstring>(src)); |
| 2188 |
} |
| 2189 |
} |
| 2190 |
} |
| 2191 |
return mpt::encode<Tdststring>(to, mpt::decode<decltype(mpt::as_string(std::forward<Tsrcstring>(src)))>(from, mpt::as_string(std::forward<Tsrcstring>(src)))); |
| 2192 |
} |
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
} // namespace MPT_INLINE_NS |
| 2197 |
} // namespace mpt |
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
#endif // MPT_STRING_TRANSCODE_TRANSCODE_HPP |