goscript 0.0.29 → 0.0.31

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 (106) hide show
  1. package/compiler/compiler.go +8 -1
  2. package/compiler/index.ts +1 -1
  3. package/compiler/stmt-assign.go +14 -0
  4. package/dist/compiler/index.js +1 -1
  5. package/dist/compiler/index.js.map +1 -1
  6. package/dist/gs/builtin/channel.d.ts +6 -6
  7. package/dist/gs/builtin/channel.js +3 -3
  8. package/dist/gs/builtin/channel.js.map +1 -1
  9. package/dist/gs/builtin/slice.js +3 -9
  10. package/dist/gs/builtin/slice.js.map +1 -1
  11. package/dist/gs/context/context.js +2 -2
  12. package/dist/gs/context/context.js.map +1 -1
  13. package/dist/gs/internal/oserror/errors.d.ts +1 -1
  14. package/dist/gs/internal/oserror/errors.js +6 -6
  15. package/dist/gs/internal/oserror/index.d.ts +1 -1
  16. package/dist/gs/internal/oserror/index.js +1 -1
  17. package/dist/gs/internal/oserror/index.js.map +1 -1
  18. package/dist/gs/io/fs/format.d.ts +1 -1
  19. package/dist/gs/io/fs/format.js +12 -12
  20. package/dist/gs/io/fs/format.js.map +1 -1
  21. package/dist/gs/io/fs/fs.d.ts +2 -2
  22. package/dist/gs/io/fs/fs.js +258 -36
  23. package/dist/gs/io/fs/fs.js.map +1 -1
  24. package/dist/gs/io/fs/glob.d.ts +2 -2
  25. package/dist/gs/io/fs/glob.js +40 -14
  26. package/dist/gs/io/fs/glob.js.map +1 -1
  27. package/dist/gs/io/fs/index.d.ts +8 -8
  28. package/dist/gs/io/fs/index.js +8 -8
  29. package/dist/gs/io/fs/readdir.d.ts +2 -2
  30. package/dist/gs/io/fs/readdir.js +78 -9
  31. package/dist/gs/io/fs/readdir.js.map +1 -1
  32. package/dist/gs/io/fs/readfile.d.ts +2 -2
  33. package/dist/gs/io/fs/readfile.js +31 -13
  34. package/dist/gs/io/fs/readfile.js.map +1 -1
  35. package/dist/gs/io/fs/stat.d.ts +2 -2
  36. package/dist/gs/io/fs/stat.js +25 -2
  37. package/dist/gs/io/fs/stat.js.map +1 -1
  38. package/dist/gs/io/fs/sub.d.ts +2 -2
  39. package/dist/gs/io/fs/sub.js +264 -28
  40. package/dist/gs/io/fs/sub.js.map +1 -1
  41. package/dist/gs/io/fs/walk.d.ts +2 -2
  42. package/dist/gs/io/fs/walk.js +7 -7
  43. package/dist/gs/io/fs/walk.js.map +1 -1
  44. package/dist/gs/iter/iter.js +1 -1
  45. package/dist/gs/iter/iter.js.map +1 -1
  46. package/dist/gs/path/index.d.ts +2 -2
  47. package/dist/gs/path/index.js +2 -2
  48. package/dist/gs/path/match.d.ts +1 -1
  49. package/dist/gs/path/match.js +39 -33
  50. package/dist/gs/path/match.js.map +1 -1
  51. package/dist/gs/path/path.js +53 -24
  52. package/dist/gs/path/path.js.map +1 -1
  53. package/dist/gs/runtime/runtime.d.ts +3 -3
  54. package/dist/gs/runtime/runtime.js +3 -3
  55. package/dist/gs/runtime/runtime.js.map +1 -1
  56. package/dist/gs/strings/builder.d.ts +1 -1
  57. package/dist/gs/strings/builder.js +1 -1
  58. package/dist/gs/strings/builder.js.map +1 -1
  59. package/dist/gs/strings/clone.js.map +1 -1
  60. package/dist/gs/strings/compare.js.map +1 -1
  61. package/dist/gs/strings/replace.js +4 -2
  62. package/dist/gs/strings/replace.js.map +1 -1
  63. package/dist/gs/strings/strings.js +0 -12
  64. package/dist/gs/strings/strings.js.map +1 -1
  65. package/dist/gs/sync/sync.d.ts +5 -5
  66. package/dist/gs/sync/sync.js +5 -5
  67. package/dist/gs/sync/sync.js.map +1 -1
  68. package/dist/gs/time/time.d.ts +2 -2
  69. package/dist/gs/time/time.js +62 -16
  70. package/dist/gs/time/time.js.map +1 -1
  71. package/dist/gs/unsafe/unsafe.d.ts +8 -8
  72. package/dist/gs/unsafe/unsafe.js +8 -8
  73. package/dist/gs/unsafe/unsafe.js.map +1 -1
  74. package/gs/builtin/builtin.ts +1 -1
  75. package/gs/builtin/channel.ts +6 -6
  76. package/gs/builtin/slice.ts +3 -9
  77. package/gs/context/context.ts +2 -2
  78. package/gs/internal/oserror/errors.ts +7 -8
  79. package/gs/internal/oserror/index.ts +7 -1
  80. package/gs/io/fs/format.ts +39 -40
  81. package/gs/io/fs/fs.ts +446 -222
  82. package/gs/io/fs/glob.ts +164 -131
  83. package/gs/io/fs/index.ts +8 -8
  84. package/gs/io/fs/readdir.ts +188 -106
  85. package/gs/io/fs/readfile.ts +79 -58
  86. package/gs/io/fs/stat.ts +49 -25
  87. package/gs/io/fs/sub.ts +422 -181
  88. package/gs/io/fs/walk.ts +67 -63
  89. package/gs/iter/iter.ts +1 -1
  90. package/gs/path/index.ts +2 -2
  91. package/gs/path/match.ts +263 -250
  92. package/gs/path/path.ts +259 -232
  93. package/gs/runtime/runtime.ts +4 -4
  94. package/gs/strings/builder.test.ts +0 -1
  95. package/gs/strings/builder.ts +1 -1
  96. package/gs/strings/clone.ts +0 -2
  97. package/gs/strings/compare.ts +0 -2
  98. package/gs/strings/iter.test.ts +0 -1
  99. package/gs/strings/replace.test.ts +3 -4
  100. package/gs/strings/replace.ts +4 -7
  101. package/gs/strings/strings.test.ts +6 -6
  102. package/gs/strings/strings.ts +0 -14
  103. package/gs/sync/sync.ts +5 -5
  104. package/gs/time/time.ts +86 -29
  105. package/gs/unsafe/unsafe.ts +8 -8
  106. package/package.json +1 -1
package/gs/path/match.ts CHANGED
@@ -1,10 +1,10 @@
1
- import * as $ from "@goscript/builtin/builtin.js";
1
+ import * as $ from '@goscript/builtin/builtin.js'
2
2
 
3
- import * as errors from "@goscript/errors/index.js"
3
+ import * as errors from '@goscript/errors/index.js'
4
4
 
5
- import * as utf8 from "@goscript/unicode/utf8/index.js"
5
+ import * as utf8 from '@goscript/unicode/utf8/index.js'
6
6
 
7
- export let ErrBadPattern: $.GoError = errors.New("syntax error in pattern")
7
+ export let ErrBadPattern: $.GoError = errors.New('syntax error in pattern')
8
8
 
9
9
  // Match reports whether name matches the shell pattern.
10
10
  // The pattern syntax is:
@@ -28,280 +28,293 @@ export let ErrBadPattern: $.GoError = errors.New("syntax error in pattern")
28
28
  // The only possible returned error is [ErrBadPattern], when pattern
29
29
  // is malformed.
30
30
  export function Match(pattern: string, name: string): [boolean, $.GoError] {
31
- let matched: boolean = false
32
- let err: $.GoError = null
33
- {
31
+ {
32
+ // Trailing * matches rest of string unless it has a /.
34
33
 
35
- // Trailing * matches rest of string unless it has a /.
34
+ // Look for match at current position.
36
35
 
37
- // Look for match at current position.
36
+ // if we're the last chunk, make sure we've exhausted the name
37
+ // otherwise we'll give a false result even if we could still match
38
+ // using the star
38
39
 
39
- // if we're the last chunk, make sure we've exhausted the name
40
- // otherwise we'll give a false result even if we could still match
41
- // using the star
40
+ // Look for match skipping i+1 bytes.
41
+ // Cannot skip /.
42
42
 
43
- // Look for match skipping i+1 bytes.
44
- // Cannot skip /.
43
+ // if we're the last chunk, make sure we exhausted the name
45
44
 
46
- // if we're the last chunk, make sure we exhausted the name
45
+ // Before returning false with no error,
46
+ // check that the remainder of the pattern is syntactically valid.
47
+ Pattern: for (; $.len(pattern) > 0; ) {
48
+ let star: boolean = false
49
+ let chunk: string = ''
50
+ let rest: string = ''
51
+ let scanResult = scanChunk(pattern)
52
+ star = scanResult[0]
53
+ chunk = scanResult[1]
54
+ rest = scanResult[2]
55
+ pattern = rest
47
56
 
48
- // Before returning false with no error,
49
- // check that the remainder of the pattern is syntactically valid.
50
- Pattern: for (; $.len(pattern) > 0; ) {
51
- let star: boolean = false
52
- let chunk: string = ""
53
- let rest: string = ""
54
- let scanResult = scanChunk(pattern)
55
- star = scanResult[0]
56
- chunk = scanResult[1]
57
- rest = scanResult[2]
58
- pattern = rest
57
+ // Trailing * matches rest of string unless it has a /.
58
+ if (star && chunk == '') {
59
+ // Trailing * matches rest of string unless it has a /.
60
+ return [name.indexOf('/') < 0, null]
61
+ }
62
+ // Look for match at current position.
63
+ let [t, ok, err] = matchChunk(chunk, name)
64
+ // if we're the last chunk, make sure we've exhausted the name
65
+ // otherwise we'll give a false result even if we could still match
66
+ // using the star
67
+ if (ok && ($.len(t) == 0 || $.len(pattern) > 0)) {
68
+ name = t
69
+ continue
70
+ }
71
+ if (err != null) {
72
+ return [false, err]
73
+ }
59
74
 
60
- // Trailing * matches rest of string unless it has a /.
61
- if (star && chunk == "") {
62
- // Trailing * matches rest of string unless it has a /.
63
- return [name.indexOf("/") < 0, null]
64
- }
65
- // Look for match at current position.
66
- let [t, ok, err] = matchChunk(chunk, name)
67
- // if we're the last chunk, make sure we've exhausted the name
68
- // otherwise we'll give a false result even if we could still match
69
- // using the star
70
- if (ok && ($.len(t) == 0 || $.len(pattern) > 0)) {
71
- name = t
72
- continue
73
- }
74
- if (err != null) {
75
- return [false, err]
76
- }
75
+ // Look for match skipping i+1 bytes.
76
+ // Cannot skip /.
77
77
 
78
- // Look for match skipping i+1 bytes.
79
- // Cannot skip /.
78
+ // if we're the last chunk, make sure we exhausted the name
79
+ if (star) {
80
+ // Look for match skipping i+1 bytes.
81
+ // Cannot skip /.
80
82
 
81
- // if we're the last chunk, make sure we exhausted the name
82
- if (star) {
83
- // Look for match skipping i+1 bytes.
84
- // Cannot skip /.
83
+ // if we're the last chunk, make sure we exhausted the name
84
+ for (let i = 0; i < $.len(name) && $.indexString(name, i) != 47; i++) {
85
+ let [t, ok, err] = matchChunk(
86
+ chunk,
87
+ $.sliceString(name, i, undefined),
88
+ )
85
89
 
86
- // if we're the last chunk, make sure we exhausted the name
87
- for (let i = 0; i < $.len(name) && $.indexString(name, i) != 47; i++) {
88
- let [t, ok, err] = matchChunk(chunk, $.sliceString(name, i, undefined))
89
-
90
- // if we're the last chunk, make sure we exhausted the name
91
- if (ok) {
92
- // if we're the last chunk, make sure we exhausted the name
93
- if ($.len(pattern) == 0 && $.len(t) > 0) {
94
- continue
95
- }
96
- name = t
97
- continue Pattern
98
- }
99
- if (err != null) {
100
- return [false, err]
101
- }
102
- }
103
- }
104
- // Before returning false with no error,
105
- // check that the remainder of the pattern is syntactically valid.
106
- for (; $.len(pattern) > 0; ) {
107
- let star2: boolean = false
108
- let chunk2: string = ""
109
- let rest2: string = ""
110
- let scanResult2 = scanChunk(pattern)
111
- star2 = scanResult2[0]
112
- chunk2 = scanResult2[1]
113
- rest2 = scanResult2[2]
114
- pattern = rest2
115
- {
116
- let [, , err] = matchChunk(chunk2, "")
117
- if (err != null) {
118
- return [false, err]
119
- }
120
- }
121
- }
122
- return [false, null]
123
- }
124
- return [$.len(name) == 0, null]
125
- }
90
+ // if we're the last chunk, make sure we exhausted the name
91
+ if (ok) {
92
+ // if we're the last chunk, make sure we exhausted the name
93
+ if ($.len(pattern) == 0 && $.len(t) > 0) {
94
+ continue
95
+ }
96
+ name = t
97
+ continue Pattern
98
+ }
99
+ if (err != null) {
100
+ return [false, err]
101
+ }
102
+ }
103
+ }
104
+ // Before returning false with no error,
105
+ // check that the remainder of the pattern is syntactically valid.
106
+ for (; $.len(pattern) > 0; ) {
107
+ // let star2: boolean = false
108
+ let chunk2: string = ''
109
+ let rest2: string = ''
110
+ let scanResult2 = scanChunk(pattern)
111
+ // star2 = scanResult2[0]
112
+ chunk2 = scanResult2[1]
113
+ rest2 = scanResult2[2]
114
+ pattern = rest2
115
+ {
116
+ let [, , err] = matchChunk(chunk2, '')
117
+ if (err != null) {
118
+ return [false, err]
119
+ }
120
+ }
121
+ }
122
+ return [false, null]
123
+ }
124
+ return [$.len(name) == 0, null]
125
+ }
126
126
  }
127
127
 
128
128
  // scanChunk gets the next segment of pattern, which is a non-star string
129
129
  // possibly preceded by a star.
130
130
  export function scanChunk(pattern: string): [boolean, string, string] {
131
- let star: boolean = false
132
- let chunk: string = ""
133
- let rest: string = ""
134
- {
135
- for (; $.len(pattern) > 0 && $.indexString(pattern, 0) == 42; ) {
136
- pattern = $.sliceString(pattern, 1, undefined)
137
- star = true
138
- }
139
- let inrange = false
140
- let i: number = 0
141
-
142
- // error check handled in matchChunk: bad pattern.
143
- Scan: for (i = 0; i < $.len(pattern); i++) {
131
+ let star: boolean = false
132
+ {
133
+ for (; $.len(pattern) > 0 && $.indexString(pattern, 0) == 42; ) {
134
+ pattern = $.sliceString(pattern, 1, undefined)
135
+ star = true
136
+ }
137
+ let inrange = false
138
+ let i: number = 0
144
139
 
145
- // error check handled in matchChunk: bad pattern.
146
- switch ($.indexString(pattern, i)) {
147
- case 92:
148
- if (i + 1 < $.len(pattern)) {
149
- i++
150
- }
151
- break
152
- case 91:
153
- inrange = true
154
- break
155
- case 93:
156
- inrange = false
157
- break
158
- case 42:
159
- if (!inrange) {
160
- break Scan
161
- }
162
- break
163
- }
164
- }
165
- return [star, $.sliceString(pattern, 0, i), $.sliceString(pattern, i, undefined)]
166
- }
140
+ // error check handled in matchChunk: bad pattern.
141
+ Scan: for (i = 0; i < $.len(pattern); i++) {
142
+ // error check handled in matchChunk: bad pattern.
143
+ switch ($.indexString(pattern, i)) {
144
+ case 92:
145
+ if (i + 1 < $.len(pattern)) {
146
+ i++
147
+ }
148
+ break
149
+ case 91:
150
+ inrange = true
151
+ break
152
+ case 93:
153
+ inrange = false
154
+ break
155
+ case 42:
156
+ if (!inrange) {
157
+ break Scan
158
+ }
159
+ break
160
+ }
161
+ }
162
+ return [
163
+ star,
164
+ $.sliceString(pattern, 0, i),
165
+ $.sliceString(pattern, i, undefined),
166
+ ]
167
+ }
167
168
  }
168
169
 
169
170
  // matchChunk checks whether chunk matches the beginning of s.
170
171
  // If so, it returns the remainder of s (after the match).
171
172
  // Chunk is all single-character operators: literals, char classes, and ?.
172
- export function matchChunk(chunk: string, s: string): [string, boolean, $.GoError] {
173
- let rest: string = ""
174
- let ok: boolean = false
175
- let err: $.GoError = null
176
- {
177
- // failed records whether the match has failed.
178
- // After the match fails, the loop continues on processing chunk,
179
- // checking that the pattern is well-formed but no longer reading s.
180
- let failed = false
173
+ export function matchChunk(
174
+ chunk: string,
175
+ s: string,
176
+ ): [string, boolean, $.GoError] {
177
+ let err: $.GoError = null
178
+ {
179
+ // failed records whether the match has failed.
180
+ // After the match fails, the loop continues on processing chunk,
181
+ // checking that the pattern is well-formed but no longer reading s.
182
+ let failed = false
181
183
 
182
- // character class
184
+ // character class
183
185
 
184
- // possibly negated
186
+ // possibly negated
185
187
 
186
- // parse all ranges
187
- for (; $.len(chunk) > 0; ) {
188
- if (!failed && $.len(s) == 0) {
189
- failed = true
190
- }
188
+ // parse all ranges
189
+ for (; $.len(chunk) > 0; ) {
190
+ if (!failed && $.len(s) == 0) {
191
+ failed = true
192
+ }
191
193
 
192
- // character class
194
+ // character class
193
195
 
194
- // possibly negated
196
+ // possibly negated
195
197
 
196
- // parse all ranges
197
- switch ($.indexString(chunk, 0)) {
198
- case 91:
199
- let r: number = 0
200
- if (!failed) {
201
- let n: number = 0
202
- let decoded = utf8.DecodeRuneInString(s)
203
- r = decoded[0]
204
- n = decoded[1]
205
- s = $.sliceString(s, n, undefined)
206
- }
207
- chunk = $.sliceString(chunk, 1, undefined)
208
- let negated = false
209
- if ($.len(chunk) > 0 && $.indexString(chunk, 0) == 94) {
210
- negated = true
211
- chunk = $.sliceString(chunk, 1, undefined)
212
- }
213
- let match = false
214
- let nrange = 0
215
- for (; ; ) {
216
- if ($.len(chunk) > 0 && $.indexString(chunk, 0) == 93 && nrange > 0) {
217
- chunk = $.sliceString(chunk, 1, undefined)
218
- break
219
- }
220
- let lo: number = 0
221
- let hi: number = 0
222
- {
223
- let escResult = getEsc(chunk)
224
- lo = escResult[0]
225
- chunk = escResult[1]
226
- err = escResult[2]
227
- if (err != null) {
228
- return ["", false, err]
229
- }
230
- }
231
- hi = lo
232
- if ($.indexString(chunk, 0) == 45) {
233
- {
234
- let escResult2 = getEsc($.sliceString(chunk, 1, undefined))
235
- hi = escResult2[0]
236
- chunk = escResult2[1]
237
- err = escResult2[2]
238
- if (err != null) {
239
- return ["", false, err]
240
- }
241
- }
242
- }
243
- if (lo <= r && r <= hi) {
244
- match = true
245
- }
246
- nrange++
247
- }
248
- if (match == negated) {
249
- failed = true
250
- }
251
- break
252
- case 63:
253
- if (!failed) {
254
- if ($.indexString(s, 0) == 47) {
255
- failed = true
256
- }
257
- let [, n] = utf8.DecodeRuneInString(s)
258
- s = $.sliceString(s, n, undefined)
259
- }
260
- chunk = $.sliceString(chunk, 1, undefined)
261
- break
262
- case 92:
263
- chunk = $.sliceString(chunk, 1, undefined)
264
- if ($.len(chunk) == 0) {
265
- return ["", false, ErrBadPattern]
266
- }
267
- // unhandled branch statement token: fallthrough
268
- break
269
- default:
270
- if (!failed) {
271
- if ($.indexString(chunk, 0) != $.indexString(s, 0)) {
272
- failed = true
273
- }
274
- s = $.sliceString(s, 1, undefined)
275
- }
276
- chunk = $.sliceString(chunk, 1, undefined)
277
- break
278
- }
279
- }
280
- if (failed) {
281
- return ["", false, null]
282
- }
283
- return [s, true, null]
284
- }
198
+ // parse all ranges
199
+ switch ($.indexString(chunk, 0)) {
200
+ case 91: {
201
+ let r: number = 0
202
+ if (!failed) {
203
+ let n: number = 0
204
+ let decoded = utf8.DecodeRuneInString(s)
205
+ r = decoded[0]
206
+ n = decoded[1]
207
+ s = $.sliceString(s, n, undefined)
208
+ }
209
+ chunk = $.sliceString(chunk, 1, undefined)
210
+ let negated = false
211
+ if ($.len(chunk) > 0 && $.indexString(chunk, 0) == 94) {
212
+ negated = true
213
+ chunk = $.sliceString(chunk, 1, undefined)
214
+ }
215
+ let match = false
216
+ let nrange = 0
217
+ for (;;) {
218
+ if (
219
+ $.len(chunk) > 0 &&
220
+ $.indexString(chunk, 0) == 93 &&
221
+ nrange > 0
222
+ ) {
223
+ chunk = $.sliceString(chunk, 1, undefined)
224
+ break
225
+ }
226
+ let lo: number = 0
227
+ let hi: number = 0
228
+ {
229
+ let escResult = getEsc(chunk)
230
+ lo = escResult[0]
231
+ chunk = escResult[1]
232
+ err = escResult[2]
233
+ if (err != null) {
234
+ return ['', false, err]
235
+ }
236
+ }
237
+ hi = lo
238
+ if ($.indexString(chunk, 0) == 45) {
239
+ {
240
+ let escResult2 = getEsc($.sliceString(chunk, 1, undefined))
241
+ hi = escResult2[0]
242
+ chunk = escResult2[1]
243
+ err = escResult2[2]
244
+ if (err != null) {
245
+ return ['', false, err]
246
+ }
247
+ }
248
+ }
249
+ if (lo <= r && r <= hi) {
250
+ match = true
251
+ }
252
+ nrange++
253
+ }
254
+ if (match == negated) {
255
+ failed = true
256
+ }
257
+ break
258
+ }
259
+ case 63: {
260
+ if (!failed) {
261
+ if ($.indexString(s, 0) == 47) {
262
+ failed = true
263
+ }
264
+ let [, n] = utf8.DecodeRuneInString(s)
265
+ s = $.sliceString(s, n, undefined)
266
+ }
267
+ chunk = $.sliceString(chunk, 1, undefined)
268
+ break
269
+ }
270
+ case 92: {
271
+ chunk = $.sliceString(chunk, 1, undefined)
272
+ if ($.len(chunk) == 0) {
273
+ return ['', false, ErrBadPattern]
274
+ }
275
+ // unhandled branch statement token: fallthrough
276
+ break
277
+ }
278
+ default: {
279
+ if (!failed) {
280
+ if ($.indexString(chunk, 0) != $.indexString(s, 0)) {
281
+ failed = true
282
+ }
283
+ s = $.sliceString(s, 1, undefined)
284
+ }
285
+ chunk = $.sliceString(chunk, 1, undefined)
286
+ break
287
+ }
288
+ }
289
+ }
290
+ if (failed) {
291
+ return ['', false, null]
292
+ }
293
+ return [s, true, null]
294
+ }
285
295
  }
286
296
 
287
297
  export function getEsc(chunk: string): [number, string, $.GoError] {
288
- if ($.len(chunk) == 0 || $.indexString(chunk, 0) == 45 || $.indexString(chunk, 0) == 93) {
289
- return [0, "", ErrBadPattern]
290
- }
291
- if ($.indexString(chunk, 0) == 92) {
292
- chunk = $.sliceString(chunk, 1, undefined)
293
- if ($.len(chunk) == 0) {
294
- return [0, "", ErrBadPattern]
295
- }
296
- }
297
- let [r, n] = utf8.DecodeRuneInString(chunk)
298
- if (r == utf8.RuneError && n == 1) {
299
- return [0, "", ErrBadPattern]
300
- }
301
- chunk = $.sliceString(chunk, n, undefined)
302
- if ($.len(chunk) == 0 || $.indexString(chunk, 0) != 45 || $.len(chunk) == 1) {
303
- return [r, chunk, null]
304
- }
305
- return [r, chunk, null]
298
+ if (
299
+ $.len(chunk) == 0 ||
300
+ $.indexString(chunk, 0) == 45 ||
301
+ $.indexString(chunk, 0) == 93
302
+ ) {
303
+ return [0, '', ErrBadPattern]
304
+ }
305
+ if ($.indexString(chunk, 0) == 92) {
306
+ chunk = $.sliceString(chunk, 1, undefined)
307
+ if ($.len(chunk) == 0) {
308
+ return [0, '', ErrBadPattern]
309
+ }
310
+ }
311
+ let [r, n] = utf8.DecodeRuneInString(chunk)
312
+ if (r == utf8.RuneError && n == 1) {
313
+ return [0, '', ErrBadPattern]
314
+ }
315
+ chunk = $.sliceString(chunk, n, undefined)
316
+ if ($.len(chunk) == 0 || $.indexString(chunk, 0) != 45 || $.len(chunk) == 1) {
317
+ return [r, chunk, null]
318
+ }
319
+ return [r, chunk, null]
306
320
  }
307
-