Repository navigation
Expand file tree
/
Copy pathRuneLocale.cpp
More file actions
187 lines (157 loc) · 7.3 KB
/
Copy pathRuneLocale.cpp
File metadata and controls
187 lines (157 loc) · 7.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "prx/libc/include/general/VabiMacros.hpp"
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <iterator>
#include <stdexcept>
#include <string>
namespace GuestRune {
struct Range {
std::int32_t count;
void* entries;
};
struct Locale {
char magic[8];
char encoding[32];
void* getRune;
void* putRune;
std::int32_t invalidRune;
std::uint64_t types[256];
std::int32_t lower[256];
std::int32_t upper[256];
Range typeRanges;
Range lowerRanges;
Range upperRanges;
void* variable;
std::int32_t variableLength;
};
static_assert(offsetof(Locale, invalidRune) == 56);
static_assert(offsetof(Locale, types) == 64);
static_assert(offsetof(Locale, lower) == 2112);
static_assert(offsetof(Locale, upper) == 3136);
static_assert(offsetof(Locale, typeRanges) == 4160);
static_assert(offsetof(Locale, variable) == 4208);
static_assert(sizeof(Locale) == 4224);
constexpr std::uint64_t Alpha = 0x100;
constexpr std::uint64_t Control = 0x200;
constexpr std::uint64_t Digit = 0x400;
constexpr std::uint64_t Graph = 0x800;
constexpr std::uint64_t Lower = 0x1000;
constexpr std::uint64_t Punct = 0x2000;
constexpr std::uint64_t Space = 0x4000;
constexpr std::uint64_t Upper = 0x8000;
constexpr std::uint64_t Hex = 0x10000;
constexpr std::uint64_t Blank = 0x20000;
constexpr std::uint64_t Print = 0x40000;
constexpr std::uint64_t Number = 0x400000;
constexpr std::uint64_t Type(int c) {
if (c == '\t') return Control | Space | Blank;
if (c >= '\n' && c <= '\r') return Control | Space;
if (c < ' ' || c == 0x7f) return Control;
if (c == ' ') return Space | Blank | Print;
if (c >= '0' && c <= '9') return Digit | Print | Graph | Hex | Number | static_cast<std::uint64_t>(c - '0');
if (c >= 'A' && c <= 'F') return Upper | Hex | Print | Graph | Alpha | static_cast<std::uint64_t>(c - 'A' + 10);
if (c >= 'a' && c <= 'f') return Lower | Hex | Print | Graph | Alpha | static_cast<std::uint64_t>(c - 'a' + 10);
if (c >= 'A' && c <= 'Z') return Upper | Print | Graph | Alpha;
if (c >= 'a' && c <= 'z') return Lower | Print | Graph | Alpha;
if (c < 0x7f) return Punct | Print | Graph;
return 0;
}
constexpr Locale MakeDefault() {
Locale locale{{'R', 'u', 'n', 'e', 'M', 'a', 'g', 'i'}, "NONE", nullptr, nullptr, 0xfffd, {}, {}, {}, {}, {}, {}, nullptr, 0};
for (int c = 0; c < 256; ++c) {
locale.types[c] = Type(c);
locale.lower[c] = c >= 'A' && c <= 'Z' ? c + ('a' - 'A') : c;
locale.upper[c] = c >= 'a' && c <= 'z' ? c - ('a' - 'A') : c;
}
return locale;
}
}
extern "C" {
extern const GuestRune::Locale _DefaultRuneLocale_nid_postfix;
const GuestRune::Locale _DefaultRuneLocale_nid_postfix = GuestRune::MakeDefault();
const GuestRune::Locale* _CurrentRuneLocale_nid_postfix = &_DefaultRuneLocale_nid_postfix;
int __mb_sb_limit_nid_postfix = 256;
}
namespace GuestRune {
constexpr std::uint32_t Weof = 0xffffffff;
int Is(std::uint32_t c, std::uint64_t mask) {
return c < 256 && (_CurrentRuneLocale_nid_postfix->types[c] & mask) != 0;
}
}
extern "C" {
int APS5_VABI iswalnum_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Alpha | GuestRune::Number); }
int APS5_VABI iswalpha_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Alpha); }
int APS5_VABI iswblank_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Blank); }
int APS5_VABI iswcntrl_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Control); }
int APS5_VABI iswdigit_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Digit); }
int APS5_VABI iswgraph_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Graph); }
int APS5_VABI iswlower_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Lower); }
int APS5_VABI iswprint_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Print); }
int APS5_VABI iswpunct_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Punct); }
int APS5_VABI iswspace_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Space); }
int APS5_VABI iswupper_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Upper); }
int APS5_VABI iswxdigit_nid_postfix(std::uint32_t c) { return GuestRune::Is(c, GuestRune::Hex); }
int APS5_VABI iswctype_nid_postfix(std::uint32_t c, std::uint64_t mask) { return GuestRune::Is(c, mask); }
int APS5_VABI _Iswctype_nid_postfix(std::uint32_t c, std::uint64_t type) {
static constexpr std::uint64_t masks[] = {
GuestRune::Alpha | GuestRune::Number, GuestRune::Alpha, GuestRune::Control, GuestRune::Digit,
GuestRune::Graph, GuestRune::Lower, GuestRune::Print, GuestRune::Punct,
GuestRune::Space, GuestRune::Upper, GuestRune::Hex, GuestRune::Blank,
};
if (type == 0 || type > std::size(masks)) throw std::invalid_argument("_Iswctype: unknown class " + std::to_string(type));
return GuestRune::Is(c, masks[type - 1]);
}
std::uint64_t APS5_VABI wctype_nid_postfix(const char* property) {
static constexpr struct {
const char* name;
std::uint64_t mask;
} properties[] = {
{"alnum", GuestRune::Alpha | GuestRune::Number}, {"alpha", GuestRune::Alpha}, {"blank", GuestRune::Blank},
{"cntrl", GuestRune::Control}, {"digit", GuestRune::Digit}, {"graph", GuestRune::Graph},
{"lower", GuestRune::Lower}, {"print", GuestRune::Print}, {"punct", GuestRune::Punct},
{"space", GuestRune::Space}, {"upper", GuestRune::Upper}, {"xdigit", GuestRune::Hex},
{"ideogram", 0x80000}, {"special", 0x100000}, {"phonogram", 0x200000},
{"number", GuestRune::Number}, {"rune", 0xffffff00},
};
for (const auto& entry : properties) {
if (std::strcmp(property, entry.name) == 0) return entry.mask;
}
return 0;
}
std::uint32_t APS5_VABI towlower_nid_postfix(std::uint32_t c) {
return c < 256 ? static_cast<std::uint32_t>(_CurrentRuneLocale_nid_postfix->lower[c]) : c;
}
std::uint32_t APS5_VABI towupper_nid_postfix(std::uint32_t c) {
return c < 256 ? static_cast<std::uint32_t>(_CurrentRuneLocale_nid_postfix->upper[c]) : c;
}
std::uint32_t APS5_VABI btowc_nid_postfix(int c) {
return c == -1 ? GuestRune::Weof : static_cast<unsigned char>(c);
}
int APS5_VABI wctob_nid_postfix(std::uint32_t c) {
return c < 256 ? static_cast<int>(c) : -1;
}
std::uint32_t APS5_VABI _Towctrans_nid_postfix(std::uint32_t c, std::uint64_t desc);
const short* APS5_VABI _Getptolower_nid_postfix();
const short* APS5_VABI _Getptoupper_nid_postfix();
std::uint64_t APS5_VABI wctrans_nid_postfix(const char* property) {
if (std::strcmp(property, "tolower") == 0) return 1;
if (std::strcmp(property, "toupper") == 0) return 2;
return 0;
}
std::uint32_t APS5_VABI towctrans_nid_postfix(std::uint32_t c, std::uint64_t desc) {
return desc == 1 || desc == 2 ? _Towctrans_nid_postfix(c, desc) : c;
}
std::uint32_t APS5_VABI _Towlower_nid_postfix(std::uint32_t c, const void*) {
return _Towctrans_nid_postfix(c, 1);
}
std::uint32_t APS5_VABI _Towupper_nid_postfix(std::uint32_t c, const void*) {
return _Towctrans_nid_postfix(c, 2);
}
int APS5_VABI _Tolower_nid_postfix(int c, const void*) {
return static_cast<unsigned>(c) <= 0x7f ? _Getptolower_nid_postfix()[c] : c;
}
int APS5_VABI _Toupper_nid_postfix(int c, const void*) {
return static_cast<unsigned>(c) <= 0x7f ? _Getptoupper_nid_postfix()[c] : c;
}
}