summaryrefslogtreecommitdiff
path: root/src/GenCatData.zig
diff options
context:
space:
mode:
authorGravatar Jose Colon Rodriguez2024-03-27 15:46:16 -0400
committerGravatar Jose Colon Rodriguez2024-03-27 15:46:16 -0400
commitf2783bf9f06e4a10138eef2c9e8ac59267983cde (patch)
tree3ac2138f05550d955555f781f94c5a8524db2463 /src/GenCatData.zig
parentExport CaseData (diff)
downloadzg-f2783bf9f06e4a10138eef2c9e8ac59267983cde.tar.gz
zg-f2783bf9f06e4a10138eef2c9e8ac59267983cde.tar.xz
zg-f2783bf9f06e4a10138eef2c9e8ac59267983cde.zip
Friendly general category methods
Diffstat (limited to 'src/GenCatData.zig')
-rw-r--r--src/GenCatData.zig146
1 files changed, 116 insertions, 30 deletions
diff --git a/src/GenCatData.zig b/src/GenCatData.zig
index 5496e4e..b45135b 100644
--- a/src/GenCatData.zig
+++ b/src/GenCatData.zig
@@ -5,36 +5,36 @@ const mem = std.mem;
5 5
6/// General Category 6/// General Category
7pub const Gc = enum { 7pub const Gc = enum {
8 Cc, 8 Cc, // Other, Control
9 Cf, 9 Cf, // Other, Format
10 Cn, 10 Cn, // Other, Unassigned
11 Co, 11 Co, // Other, Private Use
12 Cs, 12 Cs, // Other, Surrogate
13 Ll, 13 Ll, // Letter, Lowercase
14 Lm, 14 Lm, // Letter, Modifier
15 Lo, 15 Lo, // Letter, Other
16 Lt, 16 Lu, // Letter, Uppercase
17 Lu, 17 Lt, // Letter, Titlecase
18 Mc, 18 Mc, // Mark, Spacing Combining
19 Me, 19 Me, // Mark, Enclosing
20 Mn, 20 Mn, // Mark, Non-Spacing
21 Nd, 21 Nd, // Number, Decimal Digit
22 Nl, 22 Nl, // Number, Letter
23 No, 23 No, // Number, Other
24 Pc, 24 Pc, // Punctuation, Connector
25 Pd, 25 Pd, // Punctuation, Dash
26 Pe, 26 Pe, // Punctuation, Close
27 Pf, 27 Pf, // Punctuation, Final quote (may behave like Ps or Pe depending on usage)
28 Pi, 28 Pi, // Punctuation, Initial quote (may behave like Ps or Pe depending on usage)
29 Po, 29 Po, // Punctuation, Other
30 Ps, 30 Ps, // Punctuation, Open
31 Sc, 31 Sc, // Symbol, Currency
32 Sk, 32 Sk, // Symbol, Modifier
33 Sm, 33 Sm, // Symbol, Math
34 So, 34 So, // Symbol, Other
35 Zl, 35 Zl, // Separator, Line
36 Zp, 36 Zp, // Separator, Paragraph
37 Zs, 37 Zs, // Separator, Space
38}; 38};
39 39
40allocator: mem.Allocator, 40allocator: mem.Allocator,
@@ -81,3 +81,89 @@ pub fn deinit(self: *Self) void {
81pub inline fn gc(self: Self, cp: u21) Gc { 81pub inline fn gc(self: Self, cp: u21) Gc {
82 return @enumFromInt(self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]]); 82 return @enumFromInt(self.s3[self.s2[self.s1[cp >> 8] + (cp & 0xff)]]);
83} 83}
84
85/// True if `cp` has an C general category.
86pub fn isControl(self: Self, cp: u21) bool {
87 return switch (self.gc(cp)) {
88 .Cc,
89 .Cf,
90 .Cn,
91 .Co,
92 .Cs,
93 => true,
94 else => false,
95 };
96}
97
98/// True if `cp` has an L general category.
99pub fn isLetter(self: Self, cp: u21) bool {
100 return switch (self.gc(cp)) {
101 .Ll,
102 .Lm,
103 .Lo,
104 .Lu,
105 .Lt,
106 => true,
107 else => false,
108 };
109}
110
111/// True if `cp` has an M general category.
112pub fn isMark(self: Self, cp: u21) bool {
113 return switch (self.gc(cp)) {
114 .Mc,
115 .Me,
116 .Mn,
117 => true,
118 else => false,
119 };
120}
121
122/// True if `cp` has an N general category.
123pub fn isNumber(self: Self, cp: u21) bool {
124 return switch (self.gc(cp)) {
125 .Nd,
126 .Nl,
127 .No,
128 => true,
129 else => false,
130 };
131}
132
133/// True if `cp` has an P general category.
134pub fn isPunctuation(self: Self, cp: u21) bool {
135 return switch (self.gc(cp)) {
136 .Pc,
137 .Pd,
138 .Pe,
139 .Pf,
140 .Pi,
141 .Po,
142 .Ps,
143 => true,
144 else => false,
145 };
146}
147
148/// True if `cp` has an S general category.
149pub fn isSymbol(self: Self, cp: u21) bool {
150 return switch (self.gc(cp)) {
151 .Sc,
152 .Sk,
153 .Sm,
154 .So,
155 => true,
156 else => false,
157 };
158}
159
160/// True if `cp` has an Z general category.
161pub fn isSeparator(self: Self, cp: u21) bool {
162 return switch (self.gc(cp)) {
163 .Zl,
164 .Zp,
165 .Zs,
166 => true,
167 else => false,
168 };
169}