goscript 0.2.5 → 0.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmd/goscript/cmd-compile.go +7 -0
- package/cmd/goscript/cmd_compile_test.go +83 -0
- package/compiler/compile-request.go +3 -0
- package/compiler/compiler-cache.go +828 -0
- package/compiler/compiler-cache_test.go +705 -0
- package/compiler/config.go +2 -0
- package/compiler/index.test.ts +26 -1
- package/compiler/index.ts +5 -0
- package/compiler/lowered-program.go +31 -20
- package/compiler/lowering.go +349 -93
- package/compiler/lowering_bench_test.go +1 -0
- package/compiler/override-facts.go +309 -8
- package/compiler/override-parity-verifier.go +45 -1
- package/compiler/override-parity-verifier_test.go +100 -0
- package/compiler/override-registry_test.go +1 -0
- package/compiler/package-graph.go +40 -12
- package/compiler/package-graph_test.go +29 -0
- package/compiler/runtime-contract.go +8 -0
- package/compiler/service.go +98 -11
- package/compiler/skeleton_test.go +110 -14
- package/compiler/typescript-emitter.go +120 -23
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/index.js +3 -0
- package/dist/compiler/index.js.map +1 -1
- package/dist/gs/builtin/builtin.d.ts +24 -33
- package/dist/gs/builtin/builtin.js +54 -61
- package/dist/gs/builtin/builtin.js.map +1 -1
- package/dist/gs/builtin/hostio.d.ts +1 -0
- package/dist/gs/builtin/hostio.js +1 -1
- package/dist/gs/builtin/hostio.js.map +1 -1
- package/dist/gs/builtin/index.d.ts +1 -0
- package/dist/gs/builtin/index.js +1 -0
- package/dist/gs/builtin/index.js.map +1 -1
- package/dist/gs/builtin/panic.d.ts +18 -0
- package/dist/gs/builtin/panic.js +98 -0
- package/dist/gs/builtin/panic.js.map +1 -0
- package/dist/gs/builtin/slice.d.ts +10 -0
- package/dist/gs/builtin/slice.js +110 -53
- package/dist/gs/builtin/slice.js.map +1 -1
- package/dist/gs/builtin/type.js +15 -3
- package/dist/gs/builtin/type.js.map +1 -1
- package/dist/gs/builtin/varRef.d.ts +1 -1
- package/dist/gs/builtin/varRef.js +3 -2
- package/dist/gs/builtin/varRef.js.map +1 -1
- package/dist/gs/bytes/bytes.gs.js +51 -38
- package/dist/gs/bytes/bytes.gs.js.map +1 -1
- package/dist/gs/bytes/reader.gs.d.ts +1 -1
- package/dist/gs/bytes/reader.gs.js +6 -7
- package/dist/gs/bytes/reader.gs.js.map +1 -1
- package/dist/gs/cmp/index.d.ts +1 -1
- package/dist/gs/cmp/index.js +43 -10
- package/dist/gs/cmp/index.js.map +1 -1
- package/dist/gs/context/context.d.ts +2 -2
- package/dist/gs/context/context.js +1 -1
- package/dist/gs/context/context.js.map +1 -1
- package/dist/gs/embed/index.js +1 -1
- package/dist/gs/embed/index.js.map +1 -1
- package/dist/gs/encoding/binary/index.js +201 -8
- package/dist/gs/encoding/binary/index.js.map +1 -1
- package/dist/gs/encoding/json/index.d.ts +5 -0
- package/dist/gs/encoding/json/index.js +388 -25
- package/dist/gs/encoding/json/index.js.map +1 -1
- package/dist/gs/errors/errors.js +17 -24
- package/dist/gs/errors/errors.js.map +1 -1
- package/dist/gs/fmt/fmt.js +129 -35
- package/dist/gs/fmt/fmt.js.map +1 -1
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.js +1 -1
- package/dist/gs/golang.org/x/crypto/cryptobyte/index.js.map +1 -1
- package/dist/gs/internal/bytealg/index.js +43 -8
- package/dist/gs/internal/bytealg/index.js.map +1 -1
- package/dist/gs/internal/byteorder/index.d.ts +2 -2
- package/dist/gs/internal/byteorder/index.js +2 -2
- package/dist/gs/internal/byteorder/index.js.map +1 -1
- package/dist/gs/io/fs/format.js +2 -2
- package/dist/gs/io/fs/format.js.map +1 -1
- package/dist/gs/io/fs/fs.d.ts +1 -1
- package/dist/gs/io/fs/fs.js +1 -1
- package/dist/gs/io/fs/fs.js.map +1 -1
- package/dist/gs/io/io.d.ts +21 -21
- package/dist/gs/io/io.js +49 -50
- package/dist/gs/io/io.js.map +1 -1
- package/dist/gs/math/bits/index.js +26 -8
- package/dist/gs/math/bits/index.js.map +1 -1
- package/dist/gs/math/copysign.gs.js +10 -17
- package/dist/gs/math/copysign.gs.js.map +1 -1
- package/dist/gs/math/pow.gs.js +5 -0
- package/dist/gs/math/pow.gs.js.map +1 -1
- package/dist/gs/math/signbit.gs.js +6 -2
- package/dist/gs/math/signbit.gs.js.map +1 -1
- package/dist/gs/mime/index.js +1 -0
- package/dist/gs/mime/index.js.map +1 -1
- package/dist/gs/net/http/index.d.ts +6 -6
- package/dist/gs/net/http/index.js +507 -43
- package/dist/gs/net/http/index.js.map +1 -1
- package/dist/gs/os/stat.gs.d.ts +2 -2
- package/dist/gs/os/types.gs.d.ts +1 -1
- package/dist/gs/os/types.gs.js +1 -1
- package/dist/gs/os/types.gs.js.map +1 -1
- package/dist/gs/os/types_js.gs.d.ts +1 -1
- package/dist/gs/os/types_js.gs.js +7 -7
- package/dist/gs/os/types_js.gs.js.map +1 -1
- package/dist/gs/os/types_unix.gs.d.ts +1 -1
- package/dist/gs/os/types_unix.gs.js +1 -1
- package/dist/gs/os/types_unix.gs.js.map +1 -1
- package/dist/gs/os/zero_copy_posix.gs.d.ts +1 -1
- package/dist/gs/os/zero_copy_posix.gs.js +1 -1
- package/dist/gs/os/zero_copy_posix.gs.js.map +1 -1
- package/dist/gs/path/filepath/match.js +8 -4
- package/dist/gs/path/filepath/match.js.map +1 -1
- package/dist/gs/path/filepath/path.js +216 -42
- package/dist/gs/path/filepath/path.js.map +1 -1
- package/dist/gs/path/match.js +6 -3
- package/dist/gs/path/match.js.map +1 -1
- package/dist/gs/reflect/type.d.ts +5 -4
- package/dist/gs/reflect/type.js +29 -11
- package/dist/gs/reflect/type.js.map +1 -1
- package/dist/gs/slices/slices.js +11 -11
- package/dist/gs/slices/slices.js.map +1 -1
- package/dist/gs/strconv/atof.gs.js +156 -43
- package/dist/gs/strconv/atof.gs.js.map +1 -1
- package/dist/gs/strconv/atoi.gs.d.ts +3 -2
- package/dist/gs/strconv/atoi.gs.js +86 -67
- package/dist/gs/strconv/atoi.gs.js.map +1 -1
- package/dist/gs/strconv/ftoa.gs.js +73 -3
- package/dist/gs/strconv/ftoa.gs.js.map +1 -1
- package/dist/gs/strconv/itoa.gs.d.ts +4 -4
- package/dist/gs/strconv/itoa.gs.js +5 -4
- package/dist/gs/strconv/itoa.gs.js.map +1 -1
- package/dist/gs/strconv/quote.gs.d.ts +1 -1
- package/dist/gs/strconv/quote.gs.js +311 -103
- package/dist/gs/strconv/quote.gs.js.map +1 -1
- package/dist/gs/strings/reader.d.ts +1 -1
- package/dist/gs/strings/reader.js +8 -8
- package/dist/gs/strings/reader.js.map +1 -1
- package/dist/gs/strings/strings.js +87 -61
- package/dist/gs/strings/strings.js.map +1 -1
- package/dist/gs/sync/atomic/doc_64.gs.d.ts +14 -14
- package/dist/gs/sync/atomic/doc_64.gs.js +10 -10
- package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -1
- package/dist/gs/sync/atomic/type.gs.d.ts +22 -22
- package/dist/gs/sync/atomic/type.gs.js +4 -4
- package/dist/gs/sync/atomic/type.gs.js.map +1 -1
- package/dist/gs/sync/sync.js +50 -12
- package/dist/gs/sync/sync.js.map +1 -1
- package/dist/gs/syscall/fs.d.ts +6 -6
- package/dist/gs/syscall/fs.js +1 -1
- package/dist/gs/syscall/fs.js.map +1 -1
- package/dist/gs/time/time.d.ts +18 -18
- package/dist/gs/time/time.js +58 -55
- package/dist/gs/time/time.js.map +1 -1
- package/dist/gs/unicode/tables.d.ts +11 -0
- package/dist/gs/unicode/tables.js +635 -0
- package/dist/gs/unicode/tables.js.map +1 -0
- package/dist/gs/unicode/unicode.d.ts +58 -38
- package/dist/gs/unicode/unicode.js +362 -278
- package/dist/gs/unicode/unicode.js.map +1 -1
- package/go.sum +13 -0
- package/gs/builtin/builtin.ts +83 -93
- package/gs/builtin/hostio.ts +1 -1
- package/gs/builtin/index.ts +1 -0
- package/gs/builtin/panic.test.ts +189 -0
- package/gs/builtin/panic.ts +107 -0
- package/gs/builtin/runtime-contract.test.ts +5 -5
- package/gs/builtin/slice.test.ts +23 -0
- package/gs/builtin/slice.ts +133 -95
- package/gs/builtin/type.ts +16 -3
- package/gs/builtin/varRef.ts +4 -2
- package/gs/builtin/wide-int.test.ts +41 -0
- package/gs/bytes/bytes.gs.ts +54 -41
- package/gs/bytes/bytes.test.ts +18 -1
- package/gs/bytes/reader.gs.ts +7 -8
- package/gs/cmp/index.test.ts +55 -0
- package/gs/cmp/index.ts +45 -9
- package/gs/context/context.ts +3 -3
- package/gs/embed/index.ts +2 -2
- package/gs/encoding/binary/index.test.ts +104 -0
- package/gs/encoding/binary/index.ts +259 -11
- package/gs/encoding/json/index.test.ts +107 -0
- package/gs/encoding/json/index.ts +400 -29
- package/gs/errors/errors.test.ts +44 -1
- package/gs/errors/errors.ts +15 -31
- package/gs/fmt/fmt.test.ts +70 -2
- package/gs/fmt/fmt.ts +128 -34
- package/gs/golang.org/x/crypto/cryptobyte/index.ts +1 -1
- package/gs/internal/bytealg/index.test.ts +26 -1
- package/gs/internal/bytealg/index.ts +44 -8
- package/gs/internal/byteorder/index.ts +6 -4
- package/gs/io/fs/format.ts +2 -2
- package/gs/io/fs/fs.ts +2 -2
- package/gs/io/fs/stat.test.ts +2 -2
- package/gs/io/fs/sub.test.ts +2 -2
- package/gs/io/fs/walk.test.ts +2 -2
- package/gs/io/io.test.ts +47 -5
- package/gs/io/io.ts +73 -73
- package/gs/io/limit.test.ts +103 -0
- package/gs/math/bits/index.test.ts +128 -0
- package/gs/math/bits/index.ts +26 -8
- package/gs/math/copysign.gs.test.ts +3 -1
- package/gs/math/copysign.gs.ts +10 -22
- package/gs/math/pow.gs.test.ts +4 -5
- package/gs/math/pow.gs.ts +5 -0
- package/gs/math/signbit.gs.test.ts +2 -1
- package/gs/math/signbit.gs.ts +6 -3
- package/gs/mime/index.ts +1 -0
- package/gs/net/http/index.test.ts +683 -2
- package/gs/net/http/index.ts +598 -57
- package/gs/net/http/meta.json +3 -0
- package/gs/os/stat.gs.ts +2 -2
- package/gs/os/types.gs.ts +2 -2
- package/gs/os/types_js.gs.ts +9 -9
- package/gs/os/types_unix.gs.ts +2 -2
- package/gs/os/zero_copy_posix.gs.ts +2 -2
- package/gs/path/filepath/match.test.ts +16 -0
- package/gs/path/filepath/match.ts +8 -4
- package/gs/path/filepath/path.test.ts +91 -9
- package/gs/path/filepath/path.ts +223 -49
- package/gs/path/match.test.ts +32 -0
- package/gs/path/match.ts +6 -3
- package/gs/reflect/deepequal.test.ts +1 -1
- package/gs/reflect/field.test.ts +1 -1
- package/gs/reflect/function-types.test.ts +6 -6
- package/gs/reflect/sliceat.test.ts +13 -13
- package/gs/reflect/structof.test.ts +4 -4
- package/gs/reflect/type.ts +34 -14
- package/gs/reflect/typefor.test.ts +5 -5
- package/gs/runtime/pprof/index.test.ts +20 -0
- package/gs/runtime/trace/index.test.ts +3 -0
- package/gs/slices/slices.test.ts +31 -0
- package/gs/slices/slices.ts +11 -11
- package/gs/strconv/append.test.ts +99 -0
- package/gs/strconv/atof.gs.ts +156 -42
- package/gs/strconv/atof.test.ts +45 -0
- package/gs/strconv/atoi.gs.ts +87 -69
- package/gs/strconv/atoi.test.ts +49 -0
- package/gs/strconv/ftoa.gs.ts +85 -10
- package/gs/strconv/ftoa.test.ts +43 -0
- package/gs/strconv/itoa.gs.ts +10 -9
- package/gs/strconv/quote.gs.ts +335 -108
- package/gs/strconv/quote.test.ts +111 -0
- package/gs/strings/reader.test.ts +10 -10
- package/gs/strings/reader.ts +9 -9
- package/gs/strings/strings.test.ts +18 -5
- package/gs/strings/strings.ts +81 -68
- package/gs/sync/atomic/doc_64.gs.ts +24 -24
- package/gs/sync/atomic/doc_64.test.ts +5 -5
- package/gs/sync/atomic/type.gs.ts +28 -28
- package/gs/sync/sync.test.ts +109 -1
- package/gs/sync/sync.ts +46 -12
- package/gs/syscall/fs.ts +8 -8
- package/gs/syscall/net.test.ts +1 -1
- package/gs/time/parse.test.ts +45 -0
- package/gs/time/time.test.ts +46 -23
- package/gs/time/time.ts +69 -66
- package/gs/unicode/gen.go +198 -0
- package/gs/unicode/tables.ts +646 -0
- package/gs/unicode/unicode.test.ts +69 -0
- package/gs/unicode/unicode.ts +396 -312
- package/package.json +2 -2
- package/dist/gs/github.com/aperturerobotics/util/conc/index.d.ts +0 -20
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js +0 -134
- package/dist/gs/github.com/aperturerobotics/util/conc/index.js.map +0 -1
- package/gs/github.com/aperturerobotics/util/conc/index.test.ts +0 -30
- package/gs/github.com/aperturerobotics/util/conc/index.ts +0 -172
- package/gs/github.com/aperturerobotics/util/conc/meta.json +0 -9
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { categoryData, scriptData, propertyData, foldCategoryData, foldScriptData, caseRangeData, turkishCaseData, asciiFold, caseOrbitData, latin1Props, } from './tables.js';
|
|
1
2
|
// Package unicode provides data and functions to test some properties of Unicode code points.
|
|
2
3
|
// Constants
|
|
3
4
|
export const MaxRune = 0x10ffff;
|
|
@@ -10,7 +11,10 @@ export const UpperCase = 0;
|
|
|
10
11
|
export const LowerCase = 1;
|
|
11
12
|
export const TitleCase = 2;
|
|
12
13
|
export const MaxCase = 3;
|
|
14
|
+
// UpperLower is the delta sentinel marking an upper/lower alternating CaseRange.
|
|
13
15
|
export const UpperLower = MaxRune + 1;
|
|
16
|
+
// linearMax is the maximum size table for linear search for non-Latin1 rune.
|
|
17
|
+
const linearMax = 18;
|
|
14
18
|
export class Range16 {
|
|
15
19
|
Lo;
|
|
16
20
|
Hi;
|
|
@@ -93,309 +97,389 @@ export class CaseRange {
|
|
|
93
97
|
return new CaseRange(this.Lo, this.Hi, [...this.Delta]);
|
|
94
98
|
}
|
|
95
99
|
}
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return
|
|
117
|
-
|
|
100
|
+
// SpecialCase represents language-specific case mappings such as Turkish.
|
|
101
|
+
// It carries the language's CaseRange overrides and falls back to the package
|
|
102
|
+
// case mappings when a rune is not covered, matching Go's SpecialCase methods.
|
|
103
|
+
export class SpecialCase {
|
|
104
|
+
ranges;
|
|
105
|
+
constructor(ranges = []) {
|
|
106
|
+
this.ranges = ranges;
|
|
107
|
+
}
|
|
108
|
+
ToUpper(r) {
|
|
109
|
+
let [r1, hadMapping] = to(UpperCase, r, this.ranges);
|
|
110
|
+
if (r1 === r && !hadMapping) {
|
|
111
|
+
r1 = ToUpper(r);
|
|
112
|
+
}
|
|
113
|
+
return r1;
|
|
114
|
+
}
|
|
115
|
+
ToTitle(r) {
|
|
116
|
+
let [r1, hadMapping] = to(TitleCase, r, this.ranges);
|
|
117
|
+
if (r1 === r && !hadMapping) {
|
|
118
|
+
r1 = ToTitle(r);
|
|
119
|
+
}
|
|
120
|
+
return r1;
|
|
121
|
+
}
|
|
122
|
+
ToLower(r) {
|
|
123
|
+
let [r1, hadMapping] = to(LowerCase, r, this.ranges);
|
|
124
|
+
if (r1 === r && !hadMapping) {
|
|
125
|
+
r1 = ToLower(r);
|
|
126
|
+
}
|
|
127
|
+
return r1;
|
|
128
|
+
}
|
|
118
129
|
}
|
|
119
|
-
//
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return false;
|
|
123
|
-
const char = String.fromCodePoint(r);
|
|
124
|
-
return /\p{L}/u.test(char);
|
|
130
|
+
// Table construction from the generated pure-numeric tables.
|
|
131
|
+
function buildRangeTable(d) {
|
|
132
|
+
return new RangeTable(d[0].map((t) => new Range16(t[0], t[1], t[2])), d[1].map((t) => new Range32(t[0], t[1], t[2])), d[2]);
|
|
125
133
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return
|
|
134
|
+
function buildTableMap(data) {
|
|
135
|
+
const out = new Map();
|
|
136
|
+
for (const key of Object.keys(data)) {
|
|
137
|
+
out.set(key, buildRangeTable(data[key]));
|
|
138
|
+
}
|
|
139
|
+
return out;
|
|
132
140
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (r < 0 || r > MaxRune)
|
|
136
|
-
return false;
|
|
137
|
-
const char = String.fromCodePoint(r);
|
|
138
|
-
return /\p{M}/u.test(char);
|
|
141
|
+
function buildCaseRanges(data) {
|
|
142
|
+
return data.map((d) => new CaseRange(d[0], d[1], [d[2], d[3], d[4]]));
|
|
139
143
|
}
|
|
140
|
-
//
|
|
141
|
-
export
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
144
|
+
// Categories is the set of Unicode general category tables keyed by name.
|
|
145
|
+
export const Categories = buildTableMap(categoryData);
|
|
146
|
+
export const Scripts = buildTableMap(scriptData);
|
|
147
|
+
export const Properties = buildTableMap(propertyData);
|
|
148
|
+
export const FoldCategory = buildTableMap(foldCategoryData);
|
|
149
|
+
export const FoldScript = buildTableMap(foldScriptData);
|
|
150
|
+
// CategoryAliases maps alternate category names to their canonical names.
|
|
151
|
+
export const CategoryAliases = new Map([
|
|
152
|
+
['Other', 'C'],
|
|
153
|
+
['cntrl', 'Cc'],
|
|
154
|
+
['Letter', 'L'],
|
|
155
|
+
['Mark', 'M'],
|
|
156
|
+
['Number', 'N'],
|
|
157
|
+
['Punctuation', 'P'],
|
|
158
|
+
['Symbol', 'S'],
|
|
159
|
+
['Separator', 'Z'],
|
|
160
|
+
['digit', 'Nd'],
|
|
161
|
+
]);
|
|
162
|
+
// Named general category tables.
|
|
163
|
+
export const C = Categories.get('C');
|
|
164
|
+
export const Cc = Categories.get('Cc');
|
|
165
|
+
export const Cf = Categories.get('Cf');
|
|
166
|
+
export const Cn = Categories.get('Cn');
|
|
167
|
+
export const Co = Categories.get('Co');
|
|
168
|
+
export const Cs = Categories.get('Cs');
|
|
169
|
+
export const L = Categories.get('L');
|
|
170
|
+
export const LC = Categories.get('LC');
|
|
171
|
+
export const Ll = Categories.get('Ll');
|
|
172
|
+
export const Lm = Categories.get('Lm');
|
|
173
|
+
export const Lo = Categories.get('Lo');
|
|
174
|
+
export const Lt = Categories.get('Lt');
|
|
175
|
+
export const Lu = Categories.get('Lu');
|
|
176
|
+
export const M = Categories.get('M');
|
|
177
|
+
export const Mc = Categories.get('Mc');
|
|
178
|
+
export const Me = Categories.get('Me');
|
|
179
|
+
export const Mn = Categories.get('Mn');
|
|
180
|
+
export const N = Categories.get('N');
|
|
181
|
+
export const Nd = Categories.get('Nd');
|
|
182
|
+
export const Nl = Categories.get('Nl');
|
|
183
|
+
export const No = Categories.get('No');
|
|
184
|
+
export const P = Categories.get('P');
|
|
185
|
+
export const Pc = Categories.get('Pc');
|
|
186
|
+
export const Pd = Categories.get('Pd');
|
|
187
|
+
export const Pe = Categories.get('Pe');
|
|
188
|
+
export const Pf = Categories.get('Pf');
|
|
189
|
+
export const Pi = Categories.get('Pi');
|
|
190
|
+
export const Po = Categories.get('Po');
|
|
191
|
+
export const Ps = Categories.get('Ps');
|
|
192
|
+
export const S = Categories.get('S');
|
|
193
|
+
export const Sc = Categories.get('Sc');
|
|
194
|
+
export const Sk = Categories.get('Sk');
|
|
195
|
+
export const Sm = Categories.get('Sm');
|
|
196
|
+
export const So = Categories.get('So');
|
|
197
|
+
export const Z = Categories.get('Z');
|
|
198
|
+
export const Zl = Categories.get('Zl');
|
|
199
|
+
export const Zp = Categories.get('Zp');
|
|
200
|
+
export const Zs = Categories.get('Zs');
|
|
201
|
+
// Friendly category aliases matching Go's exported names.
|
|
202
|
+
export const Letter = L;
|
|
203
|
+
export const Mark = M;
|
|
204
|
+
export const Number = N;
|
|
205
|
+
export const Other = C;
|
|
206
|
+
export const Punct = P;
|
|
207
|
+
export const Space = Z;
|
|
208
|
+
export const Symbol = S;
|
|
209
|
+
export const Digit = Nd;
|
|
210
|
+
export const Lower = Ll;
|
|
211
|
+
export const Title = Lt;
|
|
212
|
+
export const Upper = Lu;
|
|
213
|
+
// White_Space is the Unicode property table used for non-Latin1 IsSpace.
|
|
214
|
+
export const White_Space = Properties.get('White_Space');
|
|
215
|
+
// GraphicRanges defines the set of graphic characters according to Unicode.
|
|
216
|
+
export const GraphicRanges = [L, M, N, P, S, Zs];
|
|
217
|
+
// PrintRanges defines the set of printable characters according to Go.
|
|
218
|
+
export const PrintRanges = [L, M, N, P, S];
|
|
219
|
+
// CaseRanges is the table of Unicode case mappings.
|
|
220
|
+
export const CaseRanges = buildCaseRanges(caseRangeData);
|
|
221
|
+
// TurkishCase / AzeriCase are the Turkish (and Azeri) special case mappings.
|
|
222
|
+
export const TurkishCase = new SpecialCase(buildCaseRanges(turkishCaseData));
|
|
223
|
+
export const AzeriCase = TurkishCase;
|
|
224
|
+
// caseOrbit maps a rune to the next rune in its simple-fold orbit when that next
|
|
225
|
+
// rune differs from the plain case toggle. SimpleFold consults it above ASCII.
|
|
226
|
+
const caseOrbit = new Map(caseOrbitData);
|
|
227
|
+
// searchRanges reports whether r is contained in the sorted range list, using a
|
|
228
|
+
// linear scan for short tables or Latin1 runes and a binary search otherwise.
|
|
229
|
+
function searchRanges(ranges, r) {
|
|
230
|
+
if (ranges.length <= linearMax || r <= MaxLatin1) {
|
|
231
|
+
for (const range of ranges) {
|
|
232
|
+
if (r < range.Lo) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
if (r <= range.Hi) {
|
|
236
|
+
return range.Stride === 1 || (r - range.Lo) % range.Stride === 0;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
150
239
|
return false;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
240
|
+
}
|
|
241
|
+
let lo = 0;
|
|
242
|
+
let hi = ranges.length;
|
|
243
|
+
while (lo < hi) {
|
|
244
|
+
const m = lo + ((hi - lo) >> 1);
|
|
245
|
+
const range = ranges[m];
|
|
246
|
+
if (range.Lo <= r && r <= range.Hi) {
|
|
247
|
+
return range.Stride === 1 || (r - range.Lo) % range.Stride === 0;
|
|
248
|
+
}
|
|
249
|
+
if (r < range.Lo) {
|
|
250
|
+
hi = m;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
lo = m + 1;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return false;
|
|
154
257
|
}
|
|
155
|
-
//
|
|
156
|
-
export function
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
258
|
+
// Is reports whether the rune is in the specified table of ranges.
|
|
259
|
+
export function Is(rangeTab, r) {
|
|
260
|
+
const r16 = rangeTab.R16;
|
|
261
|
+
// Compare as unsigned to correctly reject negative runes.
|
|
262
|
+
if (r16.length > 0 && (r >>> 0) <= (r16[r16.length - 1].Hi >>> 0)) {
|
|
263
|
+
return searchRanges(r16, r & 0xffff);
|
|
264
|
+
}
|
|
265
|
+
const r32 = rangeTab.R32;
|
|
266
|
+
if (r32.length > 0 && r >= r32[0].Lo) {
|
|
267
|
+
return searchRanges(r32, r);
|
|
268
|
+
}
|
|
269
|
+
return false;
|
|
161
270
|
}
|
|
162
|
-
//
|
|
163
|
-
export function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
271
|
+
// In reports whether the rune is a member of one of the ranges.
|
|
272
|
+
export function In(r, ...ranges) {
|
|
273
|
+
for (const rangeTab of ranges) {
|
|
274
|
+
if (Is(rangeTab, r)) {
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return false;
|
|
168
279
|
}
|
|
169
|
-
//
|
|
170
|
-
export function
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
280
|
+
// IsOneOf reports whether the rune is a member of one of the ranges.
|
|
281
|
+
export function IsOneOf(ranges, r) {
|
|
282
|
+
for (const rangeTab of ranges) {
|
|
283
|
+
if (Is(rangeTab, r)) {
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return false;
|
|
175
288
|
}
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
289
|
+
// to maps the rune using the specified case and case-range table, returning the
|
|
290
|
+
// mapped rune and whether a mapping was found.
|
|
291
|
+
function to(_case, r, caseRange) {
|
|
292
|
+
if (_case < 0 || _case >= MaxCase) {
|
|
293
|
+
return [ReplacementChar, false];
|
|
294
|
+
}
|
|
295
|
+
let lo = 0;
|
|
296
|
+
let hi = caseRange.length;
|
|
297
|
+
while (lo < hi) {
|
|
298
|
+
const m = lo + ((hi - lo) >> 1);
|
|
299
|
+
const cr = caseRange[m];
|
|
300
|
+
if (cr.Lo <= r && r <= cr.Hi) {
|
|
301
|
+
const delta = cr.Delta[_case];
|
|
302
|
+
if (delta > MaxRune) {
|
|
303
|
+
// In an upper/lower alternating sequence the even offsets from the start
|
|
304
|
+
// are upper case and the odd offsets lower; clearing or setting the low
|
|
305
|
+
// bit of the offset selects the right case.
|
|
306
|
+
return [cr.Lo + (((r - cr.Lo) & ~1) | (_case & 1)), true];
|
|
307
|
+
}
|
|
308
|
+
return [r + delta, true];
|
|
309
|
+
}
|
|
310
|
+
if (r < cr.Lo) {
|
|
311
|
+
hi = m;
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
lo = m + 1;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return [r, false];
|
|
182
318
|
}
|
|
183
|
-
//
|
|
184
|
-
export function
|
|
185
|
-
|
|
186
|
-
return false;
|
|
187
|
-
const char = String.fromCodePoint(r);
|
|
188
|
-
return /\p{Lu}/u.test(char);
|
|
319
|
+
// To maps the rune to the specified case: UpperCase, LowerCase, or TitleCase.
|
|
320
|
+
export function To(_case, r) {
|
|
321
|
+
return to(_case, r, CaseRanges)[0];
|
|
189
322
|
}
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
323
|
+
// ToUpper maps the rune to upper case.
|
|
324
|
+
export function ToUpper(r) {
|
|
325
|
+
if (r <= MaxASCII) {
|
|
326
|
+
if (r >= 0x61 && r <= 0x7a) {
|
|
327
|
+
r -= 0x20;
|
|
328
|
+
}
|
|
194
329
|
return r;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return lower.codePointAt(0) || r;
|
|
330
|
+
}
|
|
331
|
+
return To(UpperCase, r);
|
|
198
332
|
}
|
|
199
|
-
//
|
|
200
|
-
export function
|
|
201
|
-
if (r
|
|
333
|
+
// ToLower maps the rune to lower case.
|
|
334
|
+
export function ToLower(r) {
|
|
335
|
+
if (r <= MaxASCII) {
|
|
336
|
+
if (r >= 0x41 && r <= 0x5a) {
|
|
337
|
+
r += 0x20;
|
|
338
|
+
}
|
|
202
339
|
return r;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return upper.codePointAt(0) || r;
|
|
340
|
+
}
|
|
341
|
+
return To(LowerCase, r);
|
|
206
342
|
}
|
|
207
|
-
// ToTitle
|
|
343
|
+
// ToTitle maps the rune to title case.
|
|
208
344
|
export function ToTitle(r) {
|
|
209
|
-
|
|
210
|
-
|
|
345
|
+
if (r <= MaxASCII) {
|
|
346
|
+
if (r >= 0x61 && r <= 0x7a) {
|
|
347
|
+
r -= 0x20;
|
|
348
|
+
}
|
|
349
|
+
return r;
|
|
350
|
+
}
|
|
351
|
+
return To(TitleCase, r);
|
|
211
352
|
}
|
|
212
|
-
//
|
|
213
|
-
|
|
214
|
-
switch (_case) {
|
|
215
|
-
case UpperCase:
|
|
216
|
-
return ToUpper(r);
|
|
217
|
-
case LowerCase:
|
|
218
|
-
return ToLower(r);
|
|
219
|
-
case TitleCase:
|
|
220
|
-
return ToTitle(r);
|
|
221
|
-
default:
|
|
222
|
-
return r;
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
// SimpleFold returns the next rune in the simple case folding sequence
|
|
353
|
+
// SimpleFold iterates over the Unicode code points equivalent under simple case
|
|
354
|
+
// folding, returning the next rune in the fold orbit.
|
|
226
355
|
export function SimpleFold(r) {
|
|
227
|
-
if (r < 0 || r > MaxRune)
|
|
356
|
+
if (r < 0 || r > MaxRune) {
|
|
228
357
|
return r;
|
|
229
|
-
// Simple implementation - just toggle between upper and lower case
|
|
230
|
-
if (IsUpper(r)) {
|
|
231
|
-
return ToLower(r);
|
|
232
358
|
}
|
|
233
|
-
|
|
234
|
-
return
|
|
359
|
+
if (r < asciiFold.length) {
|
|
360
|
+
return asciiFold[r];
|
|
235
361
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
export function Is(rangeTab, r) {
|
|
240
|
-
if (r < 0 || r > MaxRune)
|
|
241
|
-
return false;
|
|
242
|
-
// Check 16-bit ranges
|
|
243
|
-
for (const range of rangeTab.R16) {
|
|
244
|
-
if (r < range.Lo)
|
|
245
|
-
break;
|
|
246
|
-
if (r <= range.Hi) {
|
|
247
|
-
return range.Stride === 1 || (r - range.Lo) % range.Stride === 0;
|
|
248
|
-
}
|
|
362
|
+
const orbit = caseOrbit.get(r);
|
|
363
|
+
if (orbit !== undefined) {
|
|
364
|
+
return orbit;
|
|
249
365
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
break;
|
|
254
|
-
if (r <= range.Hi) {
|
|
255
|
-
return range.Stride === 1 || (r - range.Lo) % range.Stride === 0;
|
|
256
|
-
}
|
|
366
|
+
const l = ToLower(r);
|
|
367
|
+
if (l !== r) {
|
|
368
|
+
return l;
|
|
257
369
|
}
|
|
258
|
-
return
|
|
370
|
+
return ToUpper(r);
|
|
259
371
|
}
|
|
260
|
-
//
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
372
|
+
// Latin1 property bits, kept in sync with the l1* constants in gen.go. The
|
|
373
|
+
// latin1Props table records Go's predicate results for U+0000..U+00FF so the
|
|
374
|
+
// Latin1 fast paths stay byte-faithful without re-deriving Go's property masks.
|
|
375
|
+
const L1_CONTROL = 1 << 0;
|
|
376
|
+
const L1_LETTER = 1 << 1;
|
|
377
|
+
const L1_UPPER = 1 << 2;
|
|
378
|
+
const L1_LOWER = 1 << 3;
|
|
379
|
+
const L1_TITLE = 1 << 4;
|
|
380
|
+
const L1_NUMBER = 1 << 5;
|
|
381
|
+
const L1_DIGIT = 1 << 6;
|
|
382
|
+
const L1_MARK = 1 << 7;
|
|
383
|
+
const L1_PUNCT = 1 << 8;
|
|
384
|
+
const L1_SYMBOL = 1 << 9;
|
|
385
|
+
const L1_SPACE = 1 << 10;
|
|
386
|
+
const L1_GRAPHIC = 1 << 11;
|
|
387
|
+
const L1_PRINT = 1 << 12;
|
|
388
|
+
function isLatin1(r) {
|
|
389
|
+
return r >= 0 && r <= MaxLatin1;
|
|
390
|
+
}
|
|
391
|
+
// IsControl reports whether the rune is a control character. Such characters do
|
|
392
|
+
// not appear above Latin1.
|
|
393
|
+
export function IsControl(r) {
|
|
394
|
+
if (isLatin1(r)) {
|
|
395
|
+
return (latin1Props[r] & L1_CONTROL) !== 0;
|
|
266
396
|
}
|
|
267
397
|
return false;
|
|
268
398
|
}
|
|
269
|
-
//
|
|
270
|
-
export function
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
[]);
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
export
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
//
|
|
298
|
-
export
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
export const FoldScript = new Map();
|
|
356
|
-
// Graphic ranges
|
|
357
|
-
export const GraphicRanges = [Letter, Mark, Number, Punct, Symbol];
|
|
358
|
-
// Print ranges
|
|
359
|
-
export const PrintRanges = [Letter, Mark, Number, Punct, Symbol, Space];
|
|
360
|
-
// Case ranges (simplified)
|
|
361
|
-
export const CaseRanges = [];
|
|
362
|
-
// Special cases
|
|
363
|
-
export const TurkishCase = [];
|
|
364
|
-
export const AzeriCase = TurkishCase;
|
|
365
|
-
// Predefined character categories (simplified implementations)
|
|
366
|
-
export const Cc = new RangeTable([new Range16(0x0000, 0x001f, 1), new Range16(0x007f, 0x009f, 1)], []);
|
|
367
|
-
export const Cf = new RangeTable([], []);
|
|
368
|
-
export const Cn = new RangeTable([], []);
|
|
369
|
-
export const Co = new RangeTable([], []);
|
|
370
|
-
export const Cs = new RangeTable([new Range16(0xd800, 0xdfff, 1)], []);
|
|
371
|
-
export const Lm = new RangeTable([], []);
|
|
372
|
-
export const Lo = new RangeTable([], []);
|
|
373
|
-
export const Mc = new RangeTable([], []);
|
|
374
|
-
export const Me = new RangeTable([], []);
|
|
375
|
-
export const Mn = new RangeTable([], []);
|
|
376
|
-
export const Nl = new RangeTable([], []);
|
|
377
|
-
export const No = new RangeTable([], []);
|
|
378
|
-
export const Pc = new RangeTable([new Range16(0x005f, 0x005f, 1)], []); // underscore
|
|
379
|
-
export const Pd = new RangeTable([new Range16(0x002d, 0x002d, 1)], []); // hyphen
|
|
380
|
-
export const Pe = new RangeTable([
|
|
381
|
-
new Range16(0x0029, 0x0029, 1),
|
|
382
|
-
new Range16(0x005d, 0x005d, 1),
|
|
383
|
-
new Range16(0x007d, 0x007d, 1),
|
|
384
|
-
], []);
|
|
385
|
-
export const Pf = new RangeTable([], []);
|
|
386
|
-
export const Pi = new RangeTable([], []);
|
|
387
|
-
export const Po = new RangeTable([new Range16(0x0021, 0x0023, 1), new Range16(0x0025, 0x0027, 1)], []);
|
|
388
|
-
export const Ps = new RangeTable([
|
|
389
|
-
new Range16(0x0028, 0x0028, 1),
|
|
390
|
-
new Range16(0x005b, 0x005b, 1),
|
|
391
|
-
new Range16(0x007b, 0x007b, 1),
|
|
392
|
-
], []);
|
|
393
|
-
export const Sc = new RangeTable([new Range16(0x0024, 0x0024, 1)], []); // dollar sign
|
|
394
|
-
export const Sk = new RangeTable([new Range16(0x005e, 0x005e, 1), new Range16(0x0060, 0x0060, 1)], []);
|
|
395
|
-
export const Sm = new RangeTable([new Range16(0x002b, 0x002b, 1), new Range16(0x003c, 0x003e, 1)], []);
|
|
396
|
-
export const So = new RangeTable([], []);
|
|
397
|
-
export const Zl = new RangeTable([], []);
|
|
398
|
-
export const Zp = new RangeTable([], []);
|
|
399
|
-
export const Zs = new RangeTable([new Range16(0x0020, 0x0020, 1)], []); // space
|
|
400
|
-
Categories.set('Cn', Cn);
|
|
399
|
+
// IsDigit reports whether the rune is a decimal digit.
|
|
400
|
+
export function IsDigit(r) {
|
|
401
|
+
if (isLatin1(r)) {
|
|
402
|
+
return (latin1Props[r] & L1_DIGIT) !== 0;
|
|
403
|
+
}
|
|
404
|
+
return Is(Digit, r);
|
|
405
|
+
}
|
|
406
|
+
// IsLetter reports whether the rune is a letter (category L).
|
|
407
|
+
export function IsLetter(r) {
|
|
408
|
+
if (isLatin1(r)) {
|
|
409
|
+
return (latin1Props[r] & L1_LETTER) !== 0;
|
|
410
|
+
}
|
|
411
|
+
return Is(Letter, r);
|
|
412
|
+
}
|
|
413
|
+
// IsNumber reports whether the rune is a number (category N).
|
|
414
|
+
export function IsNumber(r) {
|
|
415
|
+
if (isLatin1(r)) {
|
|
416
|
+
return (latin1Props[r] & L1_NUMBER) !== 0;
|
|
417
|
+
}
|
|
418
|
+
return Is(Number, r);
|
|
419
|
+
}
|
|
420
|
+
// IsMark reports whether the rune is a mark character (category M).
|
|
421
|
+
export function IsMark(r) {
|
|
422
|
+
if (isLatin1(r)) {
|
|
423
|
+
return (latin1Props[r] & L1_MARK) !== 0;
|
|
424
|
+
}
|
|
425
|
+
return Is(Mark, r);
|
|
426
|
+
}
|
|
427
|
+
// IsSpace reports whether the rune is a space character as defined by Unicode.
|
|
428
|
+
export function IsSpace(r) {
|
|
429
|
+
if (isLatin1(r)) {
|
|
430
|
+
return (latin1Props[r] & L1_SPACE) !== 0;
|
|
431
|
+
}
|
|
432
|
+
return Is(White_Space, r);
|
|
433
|
+
}
|
|
434
|
+
// IsPunct reports whether the rune is a punctuation character (category P).
|
|
435
|
+
export function IsPunct(r) {
|
|
436
|
+
if (isLatin1(r)) {
|
|
437
|
+
return (latin1Props[r] & L1_PUNCT) !== 0;
|
|
438
|
+
}
|
|
439
|
+
return Is(Punct, r);
|
|
440
|
+
}
|
|
441
|
+
// IsSymbol reports whether the rune is a symbolic character (category S).
|
|
442
|
+
export function IsSymbol(r) {
|
|
443
|
+
if (isLatin1(r)) {
|
|
444
|
+
return (latin1Props[r] & L1_SYMBOL) !== 0;
|
|
445
|
+
}
|
|
446
|
+
return Is(Symbol, r);
|
|
447
|
+
}
|
|
448
|
+
// IsUpper reports whether the rune is an upper case letter.
|
|
449
|
+
export function IsUpper(r) {
|
|
450
|
+
if (isLatin1(r)) {
|
|
451
|
+
return (latin1Props[r] & L1_UPPER) !== 0;
|
|
452
|
+
}
|
|
453
|
+
return Is(Upper, r);
|
|
454
|
+
}
|
|
455
|
+
// IsLower reports whether the rune is a lower case letter.
|
|
456
|
+
export function IsLower(r) {
|
|
457
|
+
if (isLatin1(r)) {
|
|
458
|
+
return (latin1Props[r] & L1_LOWER) !== 0;
|
|
459
|
+
}
|
|
460
|
+
return Is(Lower, r);
|
|
461
|
+
}
|
|
462
|
+
// IsTitle reports whether the rune is a title case letter.
|
|
463
|
+
export function IsTitle(r) {
|
|
464
|
+
if (isLatin1(r)) {
|
|
465
|
+
return (latin1Props[r] & L1_TITLE) !== 0;
|
|
466
|
+
}
|
|
467
|
+
return Is(Title, r);
|
|
468
|
+
}
|
|
469
|
+
// IsGraphic reports whether the rune is defined as a Graphic by Unicode: letters,
|
|
470
|
+
// marks, numbers, punctuation, symbols, and spaces (categories L, M, N, P, S, Zs).
|
|
471
|
+
export function IsGraphic(r) {
|
|
472
|
+
if (isLatin1(r)) {
|
|
473
|
+
return (latin1Props[r] & L1_GRAPHIC) !== 0;
|
|
474
|
+
}
|
|
475
|
+
return In(r, ...GraphicRanges);
|
|
476
|
+
}
|
|
477
|
+
// IsPrint reports whether the rune is defined as printable by Go: the Graphic
|
|
478
|
+
// characters minus the non-ASCII spaces (so only ASCII space is printable).
|
|
479
|
+
export function IsPrint(r) {
|
|
480
|
+
if (isLatin1(r)) {
|
|
481
|
+
return (latin1Props[r] & L1_PRINT) !== 0;
|
|
482
|
+
}
|
|
483
|
+
return In(r, ...PrintRanges);
|
|
484
|
+
}
|
|
401
485
|
//# sourceMappingURL=unicode.js.map
|