goscript 0.2.6 → 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.
Files changed (264) hide show
  1. package/cmd/goscript/cmd-compile.go +7 -0
  2. package/cmd/goscript/cmd_compile_test.go +83 -0
  3. package/compiler/compile-request.go +3 -0
  4. package/compiler/compiler-cache.go +828 -0
  5. package/compiler/compiler-cache_test.go +705 -0
  6. package/compiler/config.go +2 -0
  7. package/compiler/index.test.ts +26 -1
  8. package/compiler/index.ts +5 -0
  9. package/compiler/lowered-program.go +31 -20
  10. package/compiler/lowering.go +349 -93
  11. package/compiler/lowering_bench_test.go +1 -0
  12. package/compiler/override-facts.go +309 -8
  13. package/compiler/override-parity-verifier.go +45 -1
  14. package/compiler/override-parity-verifier_test.go +100 -0
  15. package/compiler/override-registry_test.go +1 -0
  16. package/compiler/package-graph.go +40 -12
  17. package/compiler/package-graph_test.go +29 -0
  18. package/compiler/runtime-contract.go +8 -0
  19. package/compiler/service.go +98 -11
  20. package/compiler/skeleton_test.go +110 -14
  21. package/compiler/typescript-emitter.go +120 -23
  22. package/dist/compiler/index.d.ts +2 -0
  23. package/dist/compiler/index.js +3 -0
  24. package/dist/compiler/index.js.map +1 -1
  25. package/dist/gs/builtin/builtin.d.ts +24 -33
  26. package/dist/gs/builtin/builtin.js +54 -61
  27. package/dist/gs/builtin/builtin.js.map +1 -1
  28. package/dist/gs/builtin/hostio.d.ts +1 -0
  29. package/dist/gs/builtin/hostio.js +1 -1
  30. package/dist/gs/builtin/hostio.js.map +1 -1
  31. package/dist/gs/builtin/index.d.ts +1 -0
  32. package/dist/gs/builtin/index.js +1 -0
  33. package/dist/gs/builtin/index.js.map +1 -1
  34. package/dist/gs/builtin/panic.d.ts +18 -0
  35. package/dist/gs/builtin/panic.js +98 -0
  36. package/dist/gs/builtin/panic.js.map +1 -0
  37. package/dist/gs/builtin/slice.d.ts +10 -0
  38. package/dist/gs/builtin/slice.js +110 -53
  39. package/dist/gs/builtin/slice.js.map +1 -1
  40. package/dist/gs/builtin/type.js +15 -3
  41. package/dist/gs/builtin/type.js.map +1 -1
  42. package/dist/gs/builtin/varRef.d.ts +1 -1
  43. package/dist/gs/builtin/varRef.js +3 -2
  44. package/dist/gs/builtin/varRef.js.map +1 -1
  45. package/dist/gs/bytes/bytes.gs.js +51 -38
  46. package/dist/gs/bytes/bytes.gs.js.map +1 -1
  47. package/dist/gs/bytes/reader.gs.d.ts +1 -1
  48. package/dist/gs/bytes/reader.gs.js +6 -7
  49. package/dist/gs/bytes/reader.gs.js.map +1 -1
  50. package/dist/gs/cmp/index.d.ts +1 -1
  51. package/dist/gs/cmp/index.js +43 -10
  52. package/dist/gs/cmp/index.js.map +1 -1
  53. package/dist/gs/context/context.d.ts +2 -2
  54. package/dist/gs/context/context.js +1 -1
  55. package/dist/gs/context/context.js.map +1 -1
  56. package/dist/gs/embed/index.js +1 -1
  57. package/dist/gs/embed/index.js.map +1 -1
  58. package/dist/gs/encoding/binary/index.js +201 -8
  59. package/dist/gs/encoding/binary/index.js.map +1 -1
  60. package/dist/gs/encoding/json/index.d.ts +5 -0
  61. package/dist/gs/encoding/json/index.js +388 -25
  62. package/dist/gs/encoding/json/index.js.map +1 -1
  63. package/dist/gs/errors/errors.js +17 -24
  64. package/dist/gs/errors/errors.js.map +1 -1
  65. package/dist/gs/fmt/fmt.js +129 -35
  66. package/dist/gs/fmt/fmt.js.map +1 -1
  67. package/dist/gs/golang.org/x/crypto/cryptobyte/index.js +1 -1
  68. package/dist/gs/golang.org/x/crypto/cryptobyte/index.js.map +1 -1
  69. package/dist/gs/internal/bytealg/index.js +43 -8
  70. package/dist/gs/internal/bytealg/index.js.map +1 -1
  71. package/dist/gs/internal/byteorder/index.d.ts +2 -2
  72. package/dist/gs/internal/byteorder/index.js +2 -2
  73. package/dist/gs/internal/byteorder/index.js.map +1 -1
  74. package/dist/gs/io/fs/format.js +2 -2
  75. package/dist/gs/io/fs/format.js.map +1 -1
  76. package/dist/gs/io/fs/fs.d.ts +1 -1
  77. package/dist/gs/io/fs/fs.js +1 -1
  78. package/dist/gs/io/fs/fs.js.map +1 -1
  79. package/dist/gs/io/io.d.ts +21 -21
  80. package/dist/gs/io/io.js +49 -50
  81. package/dist/gs/io/io.js.map +1 -1
  82. package/dist/gs/math/bits/index.js +26 -8
  83. package/dist/gs/math/bits/index.js.map +1 -1
  84. package/dist/gs/math/copysign.gs.js +10 -17
  85. package/dist/gs/math/copysign.gs.js.map +1 -1
  86. package/dist/gs/math/pow.gs.js +5 -0
  87. package/dist/gs/math/pow.gs.js.map +1 -1
  88. package/dist/gs/math/signbit.gs.js +6 -2
  89. package/dist/gs/math/signbit.gs.js.map +1 -1
  90. package/dist/gs/mime/index.js +1 -0
  91. package/dist/gs/mime/index.js.map +1 -1
  92. package/dist/gs/net/http/index.d.ts +6 -6
  93. package/dist/gs/net/http/index.js +507 -43
  94. package/dist/gs/net/http/index.js.map +1 -1
  95. package/dist/gs/os/stat.gs.d.ts +2 -2
  96. package/dist/gs/os/types.gs.d.ts +1 -1
  97. package/dist/gs/os/types.gs.js +1 -1
  98. package/dist/gs/os/types.gs.js.map +1 -1
  99. package/dist/gs/os/types_js.gs.d.ts +1 -1
  100. package/dist/gs/os/types_js.gs.js +7 -7
  101. package/dist/gs/os/types_js.gs.js.map +1 -1
  102. package/dist/gs/os/types_unix.gs.d.ts +1 -1
  103. package/dist/gs/os/types_unix.gs.js +1 -1
  104. package/dist/gs/os/types_unix.gs.js.map +1 -1
  105. package/dist/gs/os/zero_copy_posix.gs.d.ts +1 -1
  106. package/dist/gs/os/zero_copy_posix.gs.js +1 -1
  107. package/dist/gs/os/zero_copy_posix.gs.js.map +1 -1
  108. package/dist/gs/path/filepath/match.js +8 -4
  109. package/dist/gs/path/filepath/match.js.map +1 -1
  110. package/dist/gs/path/filepath/path.js +216 -42
  111. package/dist/gs/path/filepath/path.js.map +1 -1
  112. package/dist/gs/path/match.js +6 -3
  113. package/dist/gs/path/match.js.map +1 -1
  114. package/dist/gs/reflect/type.d.ts +5 -4
  115. package/dist/gs/reflect/type.js +29 -11
  116. package/dist/gs/reflect/type.js.map +1 -1
  117. package/dist/gs/slices/slices.js +11 -11
  118. package/dist/gs/slices/slices.js.map +1 -1
  119. package/dist/gs/strconv/atof.gs.js +156 -43
  120. package/dist/gs/strconv/atof.gs.js.map +1 -1
  121. package/dist/gs/strconv/atoi.gs.d.ts +3 -2
  122. package/dist/gs/strconv/atoi.gs.js +86 -67
  123. package/dist/gs/strconv/atoi.gs.js.map +1 -1
  124. package/dist/gs/strconv/ftoa.gs.js +73 -3
  125. package/dist/gs/strconv/ftoa.gs.js.map +1 -1
  126. package/dist/gs/strconv/itoa.gs.d.ts +4 -4
  127. package/dist/gs/strconv/itoa.gs.js +5 -4
  128. package/dist/gs/strconv/itoa.gs.js.map +1 -1
  129. package/dist/gs/strconv/quote.gs.d.ts +1 -1
  130. package/dist/gs/strconv/quote.gs.js +311 -103
  131. package/dist/gs/strconv/quote.gs.js.map +1 -1
  132. package/dist/gs/strings/reader.d.ts +1 -1
  133. package/dist/gs/strings/reader.js +8 -8
  134. package/dist/gs/strings/reader.js.map +1 -1
  135. package/dist/gs/strings/strings.js +87 -61
  136. package/dist/gs/strings/strings.js.map +1 -1
  137. package/dist/gs/sync/atomic/doc_64.gs.d.ts +14 -14
  138. package/dist/gs/sync/atomic/doc_64.gs.js +10 -10
  139. package/dist/gs/sync/atomic/doc_64.gs.js.map +1 -1
  140. package/dist/gs/sync/atomic/type.gs.d.ts +22 -22
  141. package/dist/gs/sync/atomic/type.gs.js +4 -4
  142. package/dist/gs/sync/atomic/type.gs.js.map +1 -1
  143. package/dist/gs/sync/sync.js +50 -12
  144. package/dist/gs/sync/sync.js.map +1 -1
  145. package/dist/gs/syscall/fs.d.ts +6 -6
  146. package/dist/gs/syscall/fs.js +1 -1
  147. package/dist/gs/syscall/fs.js.map +1 -1
  148. package/dist/gs/time/time.d.ts +18 -18
  149. package/dist/gs/time/time.js +58 -55
  150. package/dist/gs/time/time.js.map +1 -1
  151. package/dist/gs/unicode/tables.d.ts +11 -0
  152. package/dist/gs/unicode/tables.js +635 -0
  153. package/dist/gs/unicode/tables.js.map +1 -0
  154. package/dist/gs/unicode/unicode.d.ts +58 -38
  155. package/dist/gs/unicode/unicode.js +362 -278
  156. package/dist/gs/unicode/unicode.js.map +1 -1
  157. package/go.sum +13 -0
  158. package/gs/builtin/builtin.ts +83 -93
  159. package/gs/builtin/hostio.ts +1 -1
  160. package/gs/builtin/index.ts +1 -0
  161. package/gs/builtin/panic.test.ts +189 -0
  162. package/gs/builtin/panic.ts +107 -0
  163. package/gs/builtin/runtime-contract.test.ts +5 -5
  164. package/gs/builtin/slice.test.ts +23 -0
  165. package/gs/builtin/slice.ts +133 -95
  166. package/gs/builtin/type.ts +16 -3
  167. package/gs/builtin/varRef.ts +4 -2
  168. package/gs/builtin/wide-int.test.ts +41 -0
  169. package/gs/bytes/bytes.gs.ts +54 -41
  170. package/gs/bytes/bytes.test.ts +18 -1
  171. package/gs/bytes/reader.gs.ts +7 -8
  172. package/gs/cmp/index.test.ts +55 -0
  173. package/gs/cmp/index.ts +45 -9
  174. package/gs/context/context.ts +3 -3
  175. package/gs/embed/index.ts +2 -2
  176. package/gs/encoding/binary/index.test.ts +104 -0
  177. package/gs/encoding/binary/index.ts +259 -11
  178. package/gs/encoding/json/index.test.ts +107 -0
  179. package/gs/encoding/json/index.ts +400 -29
  180. package/gs/errors/errors.test.ts +44 -1
  181. package/gs/errors/errors.ts +15 -31
  182. package/gs/fmt/fmt.test.ts +70 -2
  183. package/gs/fmt/fmt.ts +128 -34
  184. package/gs/golang.org/x/crypto/cryptobyte/index.ts +1 -1
  185. package/gs/internal/bytealg/index.test.ts +26 -1
  186. package/gs/internal/bytealg/index.ts +44 -8
  187. package/gs/internal/byteorder/index.ts +6 -4
  188. package/gs/io/fs/format.ts +2 -2
  189. package/gs/io/fs/fs.ts +2 -2
  190. package/gs/io/fs/stat.test.ts +2 -2
  191. package/gs/io/fs/sub.test.ts +2 -2
  192. package/gs/io/fs/walk.test.ts +2 -2
  193. package/gs/io/io.test.ts +47 -5
  194. package/gs/io/io.ts +73 -73
  195. package/gs/io/limit.test.ts +103 -0
  196. package/gs/math/bits/index.test.ts +128 -0
  197. package/gs/math/bits/index.ts +26 -8
  198. package/gs/math/copysign.gs.test.ts +3 -1
  199. package/gs/math/copysign.gs.ts +10 -22
  200. package/gs/math/pow.gs.test.ts +4 -5
  201. package/gs/math/pow.gs.ts +5 -0
  202. package/gs/math/signbit.gs.test.ts +2 -1
  203. package/gs/math/signbit.gs.ts +6 -3
  204. package/gs/mime/index.ts +1 -0
  205. package/gs/net/http/index.test.ts +683 -2
  206. package/gs/net/http/index.ts +598 -57
  207. package/gs/net/http/meta.json +3 -0
  208. package/gs/os/stat.gs.ts +2 -2
  209. package/gs/os/types.gs.ts +2 -2
  210. package/gs/os/types_js.gs.ts +9 -9
  211. package/gs/os/types_unix.gs.ts +2 -2
  212. package/gs/os/zero_copy_posix.gs.ts +2 -2
  213. package/gs/path/filepath/match.test.ts +16 -0
  214. package/gs/path/filepath/match.ts +8 -4
  215. package/gs/path/filepath/path.test.ts +91 -9
  216. package/gs/path/filepath/path.ts +223 -49
  217. package/gs/path/match.test.ts +32 -0
  218. package/gs/path/match.ts +6 -3
  219. package/gs/reflect/deepequal.test.ts +1 -1
  220. package/gs/reflect/field.test.ts +1 -1
  221. package/gs/reflect/function-types.test.ts +6 -6
  222. package/gs/reflect/sliceat.test.ts +13 -13
  223. package/gs/reflect/structof.test.ts +4 -4
  224. package/gs/reflect/type.ts +34 -14
  225. package/gs/reflect/typefor.test.ts +5 -5
  226. package/gs/runtime/pprof/index.test.ts +20 -0
  227. package/gs/runtime/trace/index.test.ts +3 -0
  228. package/gs/slices/slices.test.ts +31 -0
  229. package/gs/slices/slices.ts +11 -11
  230. package/gs/strconv/append.test.ts +99 -0
  231. package/gs/strconv/atof.gs.ts +156 -42
  232. package/gs/strconv/atof.test.ts +45 -0
  233. package/gs/strconv/atoi.gs.ts +87 -69
  234. package/gs/strconv/atoi.test.ts +49 -0
  235. package/gs/strconv/ftoa.gs.ts +85 -10
  236. package/gs/strconv/ftoa.test.ts +43 -0
  237. package/gs/strconv/itoa.gs.ts +10 -9
  238. package/gs/strconv/quote.gs.ts +335 -108
  239. package/gs/strconv/quote.test.ts +111 -0
  240. package/gs/strings/reader.test.ts +10 -10
  241. package/gs/strings/reader.ts +9 -9
  242. package/gs/strings/strings.test.ts +18 -5
  243. package/gs/strings/strings.ts +81 -68
  244. package/gs/sync/atomic/doc_64.gs.ts +24 -24
  245. package/gs/sync/atomic/doc_64.test.ts +5 -5
  246. package/gs/sync/atomic/type.gs.ts +28 -28
  247. package/gs/sync/sync.test.ts +109 -1
  248. package/gs/sync/sync.ts +46 -12
  249. package/gs/syscall/fs.ts +8 -8
  250. package/gs/syscall/net.test.ts +1 -1
  251. package/gs/time/parse.test.ts +45 -0
  252. package/gs/time/time.test.ts +46 -23
  253. package/gs/time/time.ts +69 -66
  254. package/gs/unicode/gen.go +198 -0
  255. package/gs/unicode/tables.ts +646 -0
  256. package/gs/unicode/unicode.test.ts +69 -0
  257. package/gs/unicode/unicode.ts +396 -312
  258. package/package.json +1 -1
  259. package/dist/gs/github.com/aperturerobotics/util/conc/index.d.ts +0 -20
  260. package/dist/gs/github.com/aperturerobotics/util/conc/index.js +0 -134
  261. package/dist/gs/github.com/aperturerobotics/util/conc/index.js.map +0 -1
  262. package/gs/github.com/aperturerobotics/util/conc/index.test.ts +0 -30
  263. package/gs/github.com/aperturerobotics/util/conc/index.ts +0 -172
  264. 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
- // Basic character classification functions using JavaScript's built-in Unicode support
97
- // IsControl reports whether the rune is a control character
98
- export function IsControl(r) {
99
- // Control characters are in categories Cc, Cf, Co, Cs
100
- if (r < 0 || r > MaxRune)
101
- return false;
102
- const char = String.fromCodePoint(r);
103
- // Use regex to match control characters
104
- return /[\p{Cc}\p{Cf}\p{Co}\p{Cs}]/u.test(char);
105
- }
106
- // IsDigit reports whether the rune is a decimal digit
107
- export function IsDigit(r) {
108
- if (r < 0 || r > MaxRune)
109
- return false;
110
- const char = String.fromCodePoint(r);
111
- return /\p{Nd}/u.test(char);
112
- }
113
- // IsGraphic reports whether the rune is defined as a Graphic by Unicode
114
- export function IsGraphic(r) {
115
- if (r < 0 || r > MaxRune)
116
- return false;
117
- return IsLetter(r) || IsMark(r) || IsNumber(r) || IsPunct(r) || IsSymbol(r);
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
- // IsLetter reports whether the rune is a letter (category L)
120
- export function IsLetter(r) {
121
- if (r < 0 || r > MaxRune)
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
- // IsLower reports whether the rune is a lower case letter
127
- export function IsLower(r) {
128
- if (r < 0 || r > MaxRune)
129
- return false;
130
- const char = String.fromCodePoint(r);
131
- return /\p{Ll}/u.test(char);
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
- // IsMark reports whether the rune is a mark character (category M)
134
- export function IsMark(r) {
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
- // IsNumber reports whether the rune is a number (category N)
141
- export function IsNumber(r) {
142
- if (r < 0 || r > MaxRune)
143
- return false;
144
- const char = String.fromCodePoint(r);
145
- return /\p{N}/u.test(char);
146
- }
147
- // IsPrint reports whether the rune is defined as printable by Go
148
- export function IsPrint(r) {
149
- if (r < 0 || r > MaxRune)
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
- if (IsGraphic(r))
152
- return true;
153
- return r === 0x20; // space character
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
- // IsPunct reports whether the rune is a punctuation character (category P)
156
- export function IsPunct(r) {
157
- if (r < 0 || r > MaxRune)
158
- return false;
159
- const char = String.fromCodePoint(r);
160
- return /\p{P}/u.test(char);
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
- // IsSpace reports whether the rune is a space character
163
- export function IsSpace(r) {
164
- if (r < 0 || r > MaxRune)
165
- return false;
166
- const char = String.fromCodePoint(r);
167
- return /\s/u.test(char) || /\p{Z}/u.test(char);
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
- // IsSymbol reports whether the rune is a symbol character (category S)
170
- export function IsSymbol(r) {
171
- if (r < 0 || r > MaxRune)
172
- return false;
173
- const char = String.fromCodePoint(r);
174
- return /\p{S}/u.test(char);
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
- // IsTitle reports whether the rune is a title case letter
177
- export function IsTitle(r) {
178
- if (r < 0 || r > MaxRune)
179
- return false;
180
- const char = String.fromCodePoint(r);
181
- return /\p{Lt}/u.test(char);
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
- // IsUpper reports whether the rune is an upper case letter
184
- export function IsUpper(r) {
185
- if (r < 0 || r > MaxRune)
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
- // Case conversion functions
191
- // ToLower returns the lowercase mapping of the rune
192
- export function ToLower(r) {
193
- if (r < 0 || r > MaxRune)
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
- const char = String.fromCodePoint(r);
196
- const lower = char.toLowerCase();
197
- return lower.codePointAt(0) || r;
330
+ }
331
+ return To(UpperCase, r);
198
332
  }
199
- // ToUpper returns the uppercase mapping of the rune
200
- export function ToUpper(r) {
201
- if (r < 0 || r > MaxRune)
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
- const char = String.fromCodePoint(r);
204
- const upper = char.toUpperCase();
205
- return upper.codePointAt(0) || r;
340
+ }
341
+ return To(LowerCase, r);
206
342
  }
207
- // ToTitle returns the title case mapping of the rune
343
+ // ToTitle maps the rune to title case.
208
344
  export function ToTitle(r) {
209
- // For most characters, title case is the same as uppercase
210
- return ToUpper(r);
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
- // To returns the case mapping of the rune
213
- export function To(_case, r) {
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
- else if (IsLower(r)) {
234
- return ToUpper(r);
359
+ if (r < asciiFold.length) {
360
+ return asciiFold[r];
235
361
  }
236
- return r;
237
- }
238
- // Is reports whether the rune is in the specified table of ranges
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
- // Check 32-bit ranges
251
- for (const range of rangeTab.R32) {
252
- if (r < range.Lo)
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 false;
370
+ return ToUpper(r);
259
371
  }
260
- // In reports whether the rune is a member of one of the ranges
261
- export function In(r, ...ranges) {
262
- for (const rangeTab of ranges) {
263
- if (Is(rangeTab, r)) {
264
- return true;
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
- // IsOneOf reports whether the rune is a member of one of the ranges
270
- export function IsOneOf(ranges, r) {
271
- return In(r, ...ranges);
272
- }
273
- // Predefined range tables for common character categories
274
- // These are simplified versions - in a full implementation, these would contain
275
- // the complete Unicode range data
276
- export const Letter = new RangeTable([new Range16(0x0041, 0x005a, 1), new Range16(0x0061, 0x007a, 1)], // Basic Latin letters
277
- []);
278
- export const Digit = new RangeTable([new Range16(0x0030, 0x0039, 1)], // ASCII digits
279
- []);
280
- export const Space = new RangeTable([new Range16(0x0009, 0x000d, 1), new Range16(0x0020, 0x0020, 1)], // Basic whitespace
281
- []);
282
- export const Upper = new RangeTable([new Range16(0x0041, 0x005a, 1)], // ASCII uppercase
283
- []);
284
- export const Lower = new RangeTable([new Range16(0x0061, 0x007a, 1)], // ASCII lowercase
285
- []);
286
- export const Title = new RangeTable([], []);
287
- export const Punct = new RangeTable([
288
- new Range16(0x0021, 0x002f, 1), // !"#$%&'()*+,-./
289
- new Range16(0x003a, 0x0040, 1), // :;<=>?@
290
- new Range16(0x005b, 0x0060, 1), // [\]^_`
291
- new Range16(0x007b, 0x007e, 1), // {|}~
292
- ], []);
293
- export const Symbol = new RangeTable([], []);
294
- export const Mark = new RangeTable([], []);
295
- export const Number = new RangeTable([new Range16(0x0030, 0x0039, 1)], // ASCII digits
296
- []);
297
- // Categories map
298
- export const Categories = new Map([
299
- ['L', Letter],
300
- ['Ll', Lower],
301
- ['Lu', Upper],
302
- ['Lt', Title],
303
- ['M', Mark],
304
- ['N', Number],
305
- ['Nd', Digit],
306
- ['P', Punct],
307
- ['S', Symbol],
308
- ['Z', Space],
309
- ]);
310
- export const CategoryAliases = new Map([
311
- ['C', 'C'],
312
- ['Cc', 'Cc'],
313
- ['cntrl', 'Cc'],
314
- ['Cf', 'Cf'],
315
- ['Co', 'Co'],
316
- ['Cs', 'Cs'],
317
- ['L', 'L'],
318
- ['LC', 'LC'],
319
- ['Ll', 'Ll'],
320
- ['Lm', 'Lm'],
321
- ['Lo', 'Lo'],
322
- ['Lt', 'Lt'],
323
- ['Lu', 'Lu'],
324
- ['M', 'M'],
325
- ['Mc', 'Mc'],
326
- ['Me', 'Me'],
327
- ['Mn', 'Mn'],
328
- ['N', 'N'],
329
- ['Nd', 'Nd'],
330
- ['digit', 'Nd'],
331
- ['Nl', 'Nl'],
332
- ['No', 'No'],
333
- ['P', 'P'],
334
- ['Pc', 'Pc'],
335
- ['Pd', 'Pd'],
336
- ['Pe', 'Pe'],
337
- ['Pf', 'Pf'],
338
- ['Pi', 'Pi'],
339
- ['Po', 'Po'],
340
- ['Ps', 'Ps'],
341
- ['S', 'S'],
342
- ['Sc', 'Sc'],
343
- ['Sk', 'Sk'],
344
- ['Sm', 'Sm'],
345
- ['So', 'So'],
346
- ['Z', 'Z'],
347
- ['Zl', 'Zl'],
348
- ['Zp', 'Zp'],
349
- ['Zs', 'Zs'],
350
- ]);
351
- // Scripts and Properties maps (simplified)
352
- export const Scripts = new Map();
353
- export const Properties = new Map();
354
- export const FoldCategory = new Map();
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