gofront 1.8.0 → 1.9.1
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/README.md +3 -3
- package/package.json +6 -5
- package/src/backend/js/expressions.js +1157 -408
- package/src/backend/js/index.js +327 -153
- package/src/backend/js/natives.js +383 -0
- package/src/backend/js/runtime.js +559 -2552
- package/src/backend/js/statements.js +670 -158
- package/src/backend/js/stdlib/index.js +45 -93
- package/src/backend/js/templ.js +32 -45
- package/src/backend/js/type-info.js +298 -19
- package/src/backend/shared/fixed-float.js +20 -0
- package/src/backend/shared/fmt-types.js +91 -170
- package/src/backend/shared/host-unicode.js +36 -0
- package/src/backend/wasm/boundary.js +490 -965
- package/src/backend/wasm/emit-builtins.js +884 -256
- package/src/backend/wasm/emit-exprs.js +185 -77
- package/src/backend/wasm/emit-maps.js +17 -367
- package/src/backend/wasm/emit-shared.js +4 -1
- package/src/backend/wasm/emit-stmts.js +524 -240
- package/src/backend/wasm/emit.js +176 -38
- package/src/backend/wasm/globals.js +48 -8
- package/src/backend/wasm/glue.js +2 -4
- package/src/backend/wasm/index.js +44 -530
- package/src/backend/wasm/method-expr.js +12 -1
- package/src/backend/wasm/module-emitter.js +299 -770
- package/src/backend/wasm/monomorph.js +139 -8
- package/src/backend/wasm/natives.js +600 -0
- package/src/backend/wasm/prescan.js +5 -153
- package/src/backend/wasm/prune-funcs.js +89 -0
- package/src/backend/wasm/stdlib/index.js +2 -32
- package/src/backend/wasm/types.js +97 -20
- package/src/backend/wasm/variadic.js +9 -4
- package/src/cli/cli-core.js +5 -1
- package/src/cli/test-runner.js +115 -342
- package/src/compiler.js +113 -130
- package/src/lexer/lexer.js +106 -11
- package/src/lexer/templ-lexer.js +61 -18
- package/src/lexer/tokens.js +1 -0
- package/src/link/stdlib.js +355 -132
- package/src/link/type-names.js +204 -0
- package/src/link/wasm.js +30 -6
- package/src/lower/bounds.js +153 -0
- package/src/lower/captures.js +92 -33
- package/src/lower/embedding.js +62 -5
- package/src/lower/errors-as.js +196 -0
- package/src/lower/fmt-formatters.js +929 -0
- package/src/lower/functions.js +225 -7
- package/src/lower/gen-types.js +293 -0
- package/src/lower/index.js +14 -2
- package/src/lower/json-codecs.js +334 -245
- package/src/lower/ownership.js +25 -7
- package/src/lower/reachability.js +69 -51
- package/src/lower/walk.js +12 -0
- package/src/parser/declarations.js +30 -5
- package/src/parser/expressions.js +111 -57
- package/src/parser/statements.js +108 -0
- package/src/parser/templ.js +44 -5
- package/src/parser/types.js +12 -0
- package/src/resolver.js +1 -2
- package/src/typechecker/assignability.js +214 -19
- package/src/typechecker/const-fold.js +70 -27
- package/src/typechecker/constants.js +156 -8
- package/src/typechecker/expressions.js +490 -108
- package/src/typechecker/index.js +346 -42
- package/src/typechecker/init-order.js +136 -40
- package/src/typechecker/operand-text.js +41 -0
- package/src/typechecker/resolve.js +490 -65
- package/src/typechecker/statements.js +288 -27
- package/src/typechecker/stdlib/excluded.js +9 -5
- package/src/typechecker/stdlib/index.js +25 -9
- package/src/typechecker/termination.js +10 -1
- package/src/typechecker/types.js +287 -575
- package/stdlib/bytes/buffer.go +479 -0
- package/stdlib/bytes/bytes.go +1010 -0
- package/stdlib/bytes/reader.go +161 -0
- package/stdlib/context/context.go +115 -0
- package/stdlib/crypto/rand/rand.go +34 -0
- package/stdlib/crypto/sha256/sha256.go +249 -0
- package/stdlib/encoding/base64/base64.go +331 -0
- package/stdlib/encoding/binary/binary.go +332 -0
- package/stdlib/encoding/hex/hex.go +140 -0
- package/stdlib/encoding/json/json.go +62 -0
- package/stdlib/errors/errors.go +174 -0
- package/stdlib/fmt/errors.go +110 -0
- package/stdlib/fmt/format.go +732 -0
- package/stdlib/fmt/print.go +1232 -0
- package/stdlib/gom/gom.go +293 -0
- package/stdlib/html/html.go +251 -0
- package/stdlib/internal/fmtrt/fmtrt.go +163 -0
- package/stdlib/internal/jsonrt/dec.go +171 -38
- package/stdlib/internal/jsonrt/enc.go +186 -36
- package/stdlib/internal/jsonrt/scanner.go +17 -8
- package/stdlib/io/io.go +157 -1
- package/stdlib/maps/maps.go +131 -0
- package/stdlib/math/bits/bits.go +507 -0
- package/stdlib/math/extra.go +16 -14
- package/stdlib/math/math.go +439 -0
- package/stdlib/math/rand/rand.go +297 -0
- package/stdlib/os/os.go +93 -0
- package/stdlib/path/filepath/filepath.go +47 -0
- package/stdlib/path/path.go +394 -0
- package/stdlib/regexp/regexp.go +231 -0
- package/stdlib/slices/slices.go +526 -0
- package/stdlib/slices/sort.go +209 -0
- package/stdlib/slices/zsort_cmp.go +480 -0
- package/stdlib/slices/zsort_ordered.go +482 -0
- package/stdlib/sort/sort.go +391 -452
- package/stdlib/sort/zsort_func.go +480 -0
- package/stdlib/sort/zsort_iface.go +480 -0
- package/stdlib/strconv/float.go +1699 -0
- package/stdlib/strconv/isprint.go +752 -0
- package/stdlib/strconv/quote.go +235 -50
- package/stdlib/strconv/strconv.go +616 -0
- package/stdlib/strings/builder.go +95 -0
- package/stdlib/strings/reader.go +163 -0
- package/stdlib/strings/replacer.go +102 -0
- package/stdlib/strings/strings.go +807 -0
- package/stdlib/sync/sync.go +268 -0
- package/stdlib/testing/async_js.go +61 -0
- package/stdlib/testing/benchmark.go +297 -0
- package/stdlib/testing/testing.go +523 -0
- package/stdlib/time/duration.go +233 -0
- package/stdlib/time/format.go +745 -0
- package/stdlib/time/parse.go +790 -0
- package/stdlib/time/sleep_js.go +63 -0
- package/stdlib/time/time.go +834 -0
- package/stdlib/unicode/unicode.go +141 -3
- package/stdlib/unicode/utf8/utf8.go +464 -0
- package/src/backend/js/fmt-runtime.js +0 -573
- package/src/backend/js/stdlib/base64.js +0 -12
- package/src/backend/js/stdlib/binary.js +0 -102
- package/src/backend/js/stdlib/bits.js +0 -119
- package/src/backend/js/stdlib/builder.js +0 -98
- package/src/backend/js/stdlib/bytes.js +0 -368
- package/src/backend/js/stdlib/errors.js +0 -45
- package/src/backend/js/stdlib/fmt.js +0 -517
- package/src/backend/js/stdlib/gom.js +0 -155
- package/src/backend/js/stdlib/hex.js +0 -17
- package/src/backend/js/stdlib/html.js +0 -20
- package/src/backend/js/stdlib/io.js +0 -137
- package/src/backend/js/stdlib/json.js +0 -1167
- package/src/backend/js/stdlib/maps.js +0 -37
- package/src/backend/js/stdlib/math.js +0 -85
- package/src/backend/js/stdlib/os.js +0 -13
- package/src/backend/js/stdlib/path.js +0 -48
- package/src/backend/js/stdlib/rand.js +0 -32
- package/src/backend/js/stdlib/regexp.js +0 -54
- package/src/backend/js/stdlib/sha256.js +0 -12
- package/src/backend/js/stdlib/shared.js +0 -17
- package/src/backend/js/stdlib/simd.js +0 -34
- package/src/backend/js/stdlib/slices.js +0 -107
- package/src/backend/js/stdlib/sort.js +0 -30
- package/src/backend/js/stdlib/strconv.js +0 -79
- package/src/backend/js/stdlib/strings.js +0 -301
- package/src/backend/js/stdlib/sync.js +0 -13
- package/src/backend/js/stdlib/testing.js +0 -41
- package/src/backend/js/stdlib/time.js +0 -152
- package/src/backend/js/stdlib/unicode.js +0 -25
- package/src/backend/js/stdlib/utf8.js +0 -26
- package/src/backend/wasm/stdlib/bytes.js +0 -6716
- package/src/backend/wasm/stdlib/core.js +0 -10278
- package/src/backend/wasm/stdlib/io.js +0 -3578
- package/src/backend/wasm/stdlib/packages.js +0 -2402
- package/src/backend/wasm/stdlib/pure.js +0 -720
- package/src/backend/wasm/stdlib/time.js +0 -2229
- package/src/typechecker/stdlib/core.js +0 -1079
- package/src/typechecker/stdlib/extended.js +0 -1210
- package/stdlib/bytes/iter.go +0 -192
- package/stdlib/bytes/search.go +0 -240
- package/stdlib/bytes/split.go +0 -218
- package/stdlib/errors/overlay.go +0 -12
- package/stdlib/maps/iter.go +0 -65
- package/stdlib/slices/extra.go +0 -73
- package/stdlib/slices/iter.go +0 -113
- package/stdlib/strings/extra.go +0 -35
- package/stdlib/strings/iter.go +0 -122
- package/stdlib/sync/extra.go +0 -105
- package/stdlib/unicode/utf8/bytes.go +0 -239
package/stdlib/bytes/iter.go
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
//go:build gofront
|
|
2
|
-
|
|
3
|
-
//gofront:target both
|
|
4
|
-
|
|
5
|
-
// Overlay on the emitter-backed bytes package: the sequence members of
|
|
6
|
-
// Go 1.24 are written in Go over iter.Seq and merged into the bytes
|
|
7
|
-
// namespace. Like Go's, the slices they yield alias the input and have their
|
|
8
|
-
// capacity clipped, so appending to one does not write into the original.
|
|
9
|
-
package bytes
|
|
10
|
-
|
|
11
|
-
import (
|
|
12
|
-
"iter"
|
|
13
|
-
"unicode"
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
const (
|
|
17
|
-
runeError = 0xFFFD
|
|
18
|
-
runeSelf = 0x80
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
// decodeRune unpacks the first UTF-8 encoding in p and returns the rune and
|
|
22
|
-
// its width in bytes, as utf8.DecodeRune does: an invalid or incomplete
|
|
23
|
-
// encoding is (RuneError, 1) and p must not be empty.
|
|
24
|
-
func decodeRune(p []byte) (rune, int) {
|
|
25
|
-
b0 := int(p[0])
|
|
26
|
-
if b0 < runeSelf {
|
|
27
|
-
return rune(b0), 1
|
|
28
|
-
}
|
|
29
|
-
n, lo, mask := 0, 0, 0
|
|
30
|
-
if b0 >= 0xC2 && b0 <= 0xDF {
|
|
31
|
-
n, lo, mask = 2, 0x80, 0x1F
|
|
32
|
-
} else if b0 >= 0xE0 && b0 <= 0xEF {
|
|
33
|
-
n, lo, mask = 3, 0x800, 0x0F
|
|
34
|
-
} else if b0 >= 0xF0 && b0 <= 0xF4 {
|
|
35
|
-
n, lo, mask = 4, 0x10000, 0x07
|
|
36
|
-
} else {
|
|
37
|
-
return runeError, 1
|
|
38
|
-
}
|
|
39
|
-
if len(p) < n {
|
|
40
|
-
return runeError, 1
|
|
41
|
-
}
|
|
42
|
-
r := b0 & mask
|
|
43
|
-
for i := 1; i < n; i++ {
|
|
44
|
-
b := int(p[i])
|
|
45
|
-
if b&0xC0 != 0x80 {
|
|
46
|
-
return runeError, 1
|
|
47
|
-
}
|
|
48
|
-
r = r<<6 | b&0x3F
|
|
49
|
-
}
|
|
50
|
-
if r < lo || r > 0x10FFFF || (r >= 0xD800 && r <= 0xDFFF) {
|
|
51
|
-
return runeError, 1
|
|
52
|
-
}
|
|
53
|
-
return rune(r), n
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// index returns the byte offset of the first instance of sep in s, or -1.
|
|
57
|
-
// It compares bytes: the emitter's bytes.Index goes through a decoded JS
|
|
58
|
-
// string on the JS backend and so counts characters, not bytes, once s holds
|
|
59
|
-
// multi-byte text. sep must not be empty.
|
|
60
|
-
func index(s, sep []byte) int {
|
|
61
|
-
first := sep[0]
|
|
62
|
-
for i := 0; i+len(sep) <= len(s); i++ {
|
|
63
|
-
if s[i] != first {
|
|
64
|
-
continue
|
|
65
|
-
}
|
|
66
|
-
j := 1
|
|
67
|
-
for j < len(sep) && s[i+j] == sep[j] {
|
|
68
|
-
j++
|
|
69
|
-
}
|
|
70
|
-
if j == len(sep) {
|
|
71
|
-
return i
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return -1
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// isSpace is unicode.IsSpace as a func(rune) bool (the checker types the
|
|
78
|
-
// unicode predicates over int).
|
|
79
|
-
func isSpace(r rune) bool {
|
|
80
|
-
return unicode.IsSpace(int(r))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Lines returns an iterator over the newline-terminated lines in the byte slice s.
|
|
84
|
-
// The lines yielded by the iterator include their terminating newlines.
|
|
85
|
-
// If s is empty, the iterator yields no lines at all.
|
|
86
|
-
// If s does not end in a newline, the final yielded line will not end in a newline.
|
|
87
|
-
// The iterator yields slices of the original slice s.
|
|
88
|
-
func Lines(s []byte) iter.Seq[[]byte] {
|
|
89
|
-
return func(yield func([]byte) bool) {
|
|
90
|
-
for len(s) > 0 {
|
|
91
|
-
var line []byte
|
|
92
|
-
if i := IndexByte(s, '\n'); i >= 0 {
|
|
93
|
-
line, s = s[:i+1:i+1], s[i+1:]
|
|
94
|
-
} else {
|
|
95
|
-
line, s = s[:len(s):len(s)], nil
|
|
96
|
-
}
|
|
97
|
-
if !yield(line) {
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// explodeSeq returns an iterator over the UTF-8 encodings of the runes in s.
|
|
105
|
-
func explodeSeq(s []byte) iter.Seq[[]byte] {
|
|
106
|
-
return func(yield func([]byte) bool) {
|
|
107
|
-
for len(s) > 0 {
|
|
108
|
-
_, size := decodeRune(s)
|
|
109
|
-
if !yield(s[:size:size]) {
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
s = s[size:]
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// splitSeq is SplitSeq or SplitAfterSeq, configured by how many
|
|
118
|
-
// bytes of sep to include in the results (none or all).
|
|
119
|
-
func splitSeq(s, sep []byte, sepSave int) iter.Seq[[]byte] {
|
|
120
|
-
if len(sep) == 0 {
|
|
121
|
-
return explodeSeq(s)
|
|
122
|
-
}
|
|
123
|
-
return func(yield func([]byte) bool) {
|
|
124
|
-
for {
|
|
125
|
-
i := index(s, sep)
|
|
126
|
-
if i < 0 {
|
|
127
|
-
break
|
|
128
|
-
}
|
|
129
|
-
frag := s[:i+sepSave]
|
|
130
|
-
if !yield(frag[:len(frag):len(frag)]) {
|
|
131
|
-
return
|
|
132
|
-
}
|
|
133
|
-
s = s[i+len(sep):]
|
|
134
|
-
}
|
|
135
|
-
yield(s[:len(s):len(s)])
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// SplitSeq returns an iterator over subslices of s split around sep.
|
|
140
|
-
// The iterator yields the same subslices that would be returned by Split(s, sep),
|
|
141
|
-
// but without constructing the slice.
|
|
142
|
-
// It returns a single-use iterator.
|
|
143
|
-
func SplitSeq(s, sep []byte) iter.Seq[[]byte] {
|
|
144
|
-
return splitSeq(s, sep, 0)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// SplitAfterSeq returns an iterator over subslices of s split after each instance of sep.
|
|
148
|
-
// The iterator yields the same subslices that would be returned by SplitAfter(s, sep),
|
|
149
|
-
// but without constructing the slice.
|
|
150
|
-
// It returns a single-use iterator.
|
|
151
|
-
func SplitAfterSeq(s, sep []byte) iter.Seq[[]byte] {
|
|
152
|
-
return splitSeq(s, sep, len(sep))
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// FieldsSeq returns an iterator over subslices of s split around runs of
|
|
156
|
-
// whitespace characters, as defined by unicode.IsSpace.
|
|
157
|
-
// The iterator yields the same subslices that would be returned by Fields(s),
|
|
158
|
-
// but without constructing the slice.
|
|
159
|
-
func FieldsSeq(s []byte) iter.Seq[[]byte] {
|
|
160
|
-
return FieldsFuncSeq(s, isSpace)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// FieldsFuncSeq returns an iterator over subslices of s split around runs of
|
|
164
|
-
// Unicode code points satisfying f(c).
|
|
165
|
-
// The iterator yields the same subslices that would be returned by FieldsFunc(s),
|
|
166
|
-
// but without constructing the slice.
|
|
167
|
-
func FieldsFuncSeq(s []byte, f func(rune) bool) iter.Seq[[]byte] {
|
|
168
|
-
return func(yield func([]byte) bool) {
|
|
169
|
-
start := -1
|
|
170
|
-
for i := 0; i < len(s); {
|
|
171
|
-
size := 1
|
|
172
|
-
r := rune(s[i])
|
|
173
|
-
if r >= runeSelf {
|
|
174
|
-
r, size = decodeRune(s[i:])
|
|
175
|
-
}
|
|
176
|
-
if f(r) {
|
|
177
|
-
if start >= 0 {
|
|
178
|
-
if !yield(s[start:i:i]) {
|
|
179
|
-
return
|
|
180
|
-
}
|
|
181
|
-
start = -1
|
|
182
|
-
}
|
|
183
|
-
} else if start < 0 {
|
|
184
|
-
start = i
|
|
185
|
-
}
|
|
186
|
-
i += size
|
|
187
|
-
}
|
|
188
|
-
if start >= 0 {
|
|
189
|
-
yield(s[start:len(s):len(s)])
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
package/stdlib/bytes/search.go
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
//go:build gofront
|
|
2
|
-
|
|
3
|
-
//gofront:target both
|
|
4
|
-
|
|
5
|
-
// Overlay on the emitter-backed bytes package: search and comparison members
|
|
6
|
-
// written in Go and merged into the bytes namespace. They work on byte
|
|
7
|
-
// offsets and decode UTF-8 as Go does, so an invalid sequence reads as
|
|
8
|
-
// (RuneError, 1).
|
|
9
|
-
package bytes
|
|
10
|
-
|
|
11
|
-
import "unicode"
|
|
12
|
-
|
|
13
|
-
// decodeLastRune unpacks the last UTF-8 encoding in p and returns the rune and
|
|
14
|
-
// its width in bytes, as utf8.DecodeLastRune does: an invalid or incomplete
|
|
15
|
-
// encoding is (RuneError, 1) and p must not be empty.
|
|
16
|
-
func decodeLastRune(p []byte) (rune, int) {
|
|
17
|
-
end := len(p)
|
|
18
|
-
r := rune(p[end-1])
|
|
19
|
-
if r < runeSelf {
|
|
20
|
-
return r, 1
|
|
21
|
-
}
|
|
22
|
-
start := end - 1
|
|
23
|
-
lim := end - 4
|
|
24
|
-
if lim < 0 {
|
|
25
|
-
lim = 0
|
|
26
|
-
}
|
|
27
|
-
for start--; start >= lim; start-- {
|
|
28
|
-
if p[start]&0xC0 != 0x80 {
|
|
29
|
-
break
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if start < 0 {
|
|
33
|
-
start = 0
|
|
34
|
-
}
|
|
35
|
-
r, size := decodeRune(p[start:end])
|
|
36
|
-
if start+size != end {
|
|
37
|
-
return runeError, 1
|
|
38
|
-
}
|
|
39
|
-
return r, size
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Compare returns an integer comparing two byte slices lexicographically.
|
|
43
|
-
// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
|
|
44
|
-
// A nil argument is equivalent to an empty slice.
|
|
45
|
-
func Compare(a, b []byte) int {
|
|
46
|
-
n := len(a)
|
|
47
|
-
if len(b) < n {
|
|
48
|
-
n = len(b)
|
|
49
|
-
}
|
|
50
|
-
for i := 0; i < n; i++ {
|
|
51
|
-
if a[i] != b[i] {
|
|
52
|
-
if a[i] < b[i] {
|
|
53
|
-
return -1
|
|
54
|
-
}
|
|
55
|
-
return 1
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if len(a) < len(b) {
|
|
59
|
-
return -1
|
|
60
|
-
}
|
|
61
|
-
if len(a) > len(b) {
|
|
62
|
-
return 1
|
|
63
|
-
}
|
|
64
|
-
return 0
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// EqualFold reports whether s and t, interpreted as UTF-8 strings,
|
|
68
|
-
// are equal under simple Unicode case-folding, which is a more general
|
|
69
|
-
// form of case-insensitivity.
|
|
70
|
-
func EqualFold(s, t []byte) bool {
|
|
71
|
-
for len(s) != 0 && len(t) != 0 {
|
|
72
|
-
var sr, tr rune
|
|
73
|
-
if s[0] < runeSelf {
|
|
74
|
-
sr, s = rune(s[0]), s[1:]
|
|
75
|
-
} else {
|
|
76
|
-
r, size := decodeRune(s)
|
|
77
|
-
sr, s = r, s[size:]
|
|
78
|
-
}
|
|
79
|
-
if t[0] < runeSelf {
|
|
80
|
-
tr, t = rune(t[0]), t[1:]
|
|
81
|
-
} else {
|
|
82
|
-
r, size := decodeRune(t)
|
|
83
|
-
tr, t = r, t[size:]
|
|
84
|
-
}
|
|
85
|
-
if tr == sr {
|
|
86
|
-
continue
|
|
87
|
-
}
|
|
88
|
-
if tr < sr {
|
|
89
|
-
tr, sr = sr, tr
|
|
90
|
-
}
|
|
91
|
-
if tr < runeSelf {
|
|
92
|
-
if 'A' <= sr && sr <= 'Z' && tr == sr+'a'-'A' {
|
|
93
|
-
continue
|
|
94
|
-
}
|
|
95
|
-
return false
|
|
96
|
-
}
|
|
97
|
-
r := unicode.SimpleFold(sr)
|
|
98
|
-
for r != sr && r < tr {
|
|
99
|
-
r = unicode.SimpleFold(r)
|
|
100
|
-
}
|
|
101
|
-
if r == tr {
|
|
102
|
-
continue
|
|
103
|
-
}
|
|
104
|
-
return false
|
|
105
|
-
}
|
|
106
|
-
return len(s) == len(t)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// IndexRune interprets s as a sequence of UTF-8-encoded code points.
|
|
110
|
-
// It returns the byte index of the first occurrence in s of the given rune.
|
|
111
|
-
// It returns -1 if rune is not present in s.
|
|
112
|
-
// If r is utf8.RuneError, it returns the first instance of any
|
|
113
|
-
// invalid UTF-8 byte sequence.
|
|
114
|
-
func IndexRune(s []byte, r rune) int {
|
|
115
|
-
if r < 0 || r > 0x10FFFF || (r >= 0xD800 && r <= 0xDFFF) {
|
|
116
|
-
return -1
|
|
117
|
-
}
|
|
118
|
-
if r < runeSelf {
|
|
119
|
-
return IndexByte(s, int(r))
|
|
120
|
-
}
|
|
121
|
-
for i := 0; i < len(s); {
|
|
122
|
-
c, size := decodeRune(s[i:])
|
|
123
|
-
if c == r {
|
|
124
|
-
return i
|
|
125
|
-
}
|
|
126
|
-
i += size
|
|
127
|
-
}
|
|
128
|
-
return -1
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// containsRuneIn reports whether chars contains r, treating an invalid sequence
|
|
132
|
-
// in chars as utf8.RuneError.
|
|
133
|
-
func containsRuneIn(chars string, r rune) bool {
|
|
134
|
-
for _, c := range chars {
|
|
135
|
-
if c == r {
|
|
136
|
-
return true
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return false
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// IndexAny interprets s as a sequence of UTF-8-encoded Unicode code points.
|
|
143
|
-
// It returns the byte index of the first occurrence in s of any of the Unicode
|
|
144
|
-
// code points in chars. It returns -1 if chars is empty or if there is no code
|
|
145
|
-
// point in common.
|
|
146
|
-
func IndexAny(s []byte, chars string) int {
|
|
147
|
-
if len(chars) == 0 {
|
|
148
|
-
return -1
|
|
149
|
-
}
|
|
150
|
-
for i := 0; i < len(s); {
|
|
151
|
-
r, size := decodeRune(s[i:])
|
|
152
|
-
if containsRuneIn(chars, r) {
|
|
153
|
-
return i
|
|
154
|
-
}
|
|
155
|
-
i += size
|
|
156
|
-
}
|
|
157
|
-
return -1
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// LastIndexAny interprets s as a sequence of UTF-8-encoded Unicode code
|
|
161
|
-
// points. It returns the byte index of the last occurrence in s of any of
|
|
162
|
-
// the Unicode code points in chars. It returns -1 if chars is empty or if
|
|
163
|
-
// there is no code point in common.
|
|
164
|
-
func LastIndexAny(s []byte, chars string) int {
|
|
165
|
-
if len(chars) == 0 {
|
|
166
|
-
return -1
|
|
167
|
-
}
|
|
168
|
-
for i := len(s); i > 0; {
|
|
169
|
-
r, size := decodeLastRune(s[:i])
|
|
170
|
-
i -= size
|
|
171
|
-
if containsRuneIn(chars, r) {
|
|
172
|
-
return i
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return -1
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
func indexFunc(s []byte, f func(rune) bool, truth bool) int {
|
|
179
|
-
for i := 0; i < len(s); {
|
|
180
|
-
r, size := decodeRune(s[i:])
|
|
181
|
-
if f(r) == truth {
|
|
182
|
-
return i
|
|
183
|
-
}
|
|
184
|
-
i += size
|
|
185
|
-
}
|
|
186
|
-
return -1
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
func lastIndexFunc(s []byte, f func(rune) bool, truth bool) int {
|
|
190
|
-
for i := len(s); i > 0; {
|
|
191
|
-
r, size := decodeLastRune(s[:i])
|
|
192
|
-
i -= size
|
|
193
|
-
if f(r) == truth {
|
|
194
|
-
return i
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return -1
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
// IndexFunc interprets s as a sequence of UTF-8-encoded code points.
|
|
201
|
-
// It returns the byte index in s of the first Unicode
|
|
202
|
-
// code point satisfying f(c), or -1 if none do.
|
|
203
|
-
func IndexFunc(s []byte, f func(r rune) bool) int {
|
|
204
|
-
return indexFunc(s, f, true)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// LastIndexFunc interprets s as a sequence of UTF-8-encoded code points.
|
|
208
|
-
// It returns the byte index in s of the last Unicode
|
|
209
|
-
// code point satisfying f(c), or -1 if none do.
|
|
210
|
-
func LastIndexFunc(s []byte, f func(r rune) bool) int {
|
|
211
|
-
return lastIndexFunc(s, f, true)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// ContainsFunc reports whether any of the UTF-8-encoded code points
|
|
215
|
-
// in b satisfy f(c).
|
|
216
|
-
func ContainsFunc(b []byte, f func(rune) bool) bool {
|
|
217
|
-
return indexFunc(b, f, true) >= 0
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// CutPrefix returns s without the provided leading prefix byte slice
|
|
221
|
-
// and reports whether it found the prefix.
|
|
222
|
-
// If s doesn't start with prefix, CutPrefix returns s, false.
|
|
223
|
-
// If prefix is the empty byte slice, CutPrefix returns s, true.
|
|
224
|
-
func CutPrefix(s, prefix []byte) (after []byte, found bool) {
|
|
225
|
-
if len(s) < len(prefix) || Compare(s[:len(prefix)], prefix) != 0 {
|
|
226
|
-
return s, false
|
|
227
|
-
}
|
|
228
|
-
return s[len(prefix):], true
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// CutSuffix returns s without the provided ending suffix byte slice
|
|
232
|
-
// and reports whether it found the suffix.
|
|
233
|
-
// If s doesn't end with suffix, CutSuffix returns s, false.
|
|
234
|
-
// If suffix is the empty byte slice, CutSuffix returns s, true.
|
|
235
|
-
func CutSuffix(s, suffix []byte) (before []byte, found bool) {
|
|
236
|
-
if len(s) < len(suffix) || Compare(s[len(s)-len(suffix):], suffix) != 0 {
|
|
237
|
-
return s, false
|
|
238
|
-
}
|
|
239
|
-
return s[:len(s)-len(suffix)], true
|
|
240
|
-
}
|
package/stdlib/bytes/split.go
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
//go:build gofront
|
|
2
|
-
|
|
3
|
-
//gofront:target both
|
|
4
|
-
|
|
5
|
-
// Overlay on the emitter-backed bytes package: splitting, trimming and
|
|
6
|
-
// case members written in Go and merged into the bytes namespace. Like Go's,
|
|
7
|
-
// the slices SplitAfter and SplitAfterN return alias the input and have their
|
|
8
|
-
// capacity clipped.
|
|
9
|
-
package bytes
|
|
10
|
-
|
|
11
|
-
import (
|
|
12
|
-
"errors"
|
|
13
|
-
"unicode"
|
|
14
|
-
)
|
|
15
|
-
|
|
16
|
-
// MinRead is the minimum slice size passed to a Read call by
|
|
17
|
-
// Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond
|
|
18
|
-
// what is required to hold the contents of r, ReadFrom will not grow the
|
|
19
|
-
// underlying buffer.
|
|
20
|
-
const MinRead = 512
|
|
21
|
-
|
|
22
|
-
// ErrTooLarge is passed to panic if memory cannot be allocated to store data in a buffer.
|
|
23
|
-
var ErrTooLarge = errors.New("bytes.Buffer: too large")
|
|
24
|
-
|
|
25
|
-
// runeCount returns the number of runes in p, counting each invalid byte as
|
|
26
|
-
// one rune as utf8.RuneCount does.
|
|
27
|
-
func runeCount(p []byte) int {
|
|
28
|
-
n := 0
|
|
29
|
-
for i := 0; i < len(p); n++ {
|
|
30
|
-
_, size := decodeRune(p[i:])
|
|
31
|
-
i += size
|
|
32
|
-
}
|
|
33
|
-
return n
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// countSep counts the non-overlapping instances of sep in s; sep must not be
|
|
37
|
-
// empty.
|
|
38
|
-
func countSep(s, sep []byte) int {
|
|
39
|
-
n := 0
|
|
40
|
-
for {
|
|
41
|
-
i := index(s, sep)
|
|
42
|
-
if i < 0 {
|
|
43
|
-
return n
|
|
44
|
-
}
|
|
45
|
-
n++
|
|
46
|
-
s = s[i+len(sep):]
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// explode splits s into a slice of UTF-8 sequences, one per Unicode code point
|
|
51
|
-
// (still slices of bytes), up to a maximum of n byte slices. Invalid UTF-8
|
|
52
|
-
// sequences are chopped into individual bytes.
|
|
53
|
-
func explode(s []byte, n int) [][]byte {
|
|
54
|
-
l := runeCount(s)
|
|
55
|
-
if n < 0 || n > l {
|
|
56
|
-
n = l
|
|
57
|
-
}
|
|
58
|
-
a := make([][]byte, n)
|
|
59
|
-
for i := 0; i < n-1; i++ {
|
|
60
|
-
_, size := decodeRune(s)
|
|
61
|
-
a[i] = s[:size:size]
|
|
62
|
-
s = s[size:]
|
|
63
|
-
}
|
|
64
|
-
if n > 0 {
|
|
65
|
-
a[n-1] = s[:len(s):len(s)]
|
|
66
|
-
}
|
|
67
|
-
return a
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// genSplit splits s around sep, including sepSave bytes of sep in each
|
|
71
|
-
// subslice, into at most n subslices.
|
|
72
|
-
func genSplit(s, sep []byte, sepSave, n int) [][]byte {
|
|
73
|
-
if n == 0 {
|
|
74
|
-
return nil
|
|
75
|
-
}
|
|
76
|
-
if len(sep) == 0 {
|
|
77
|
-
return explode(s, n)
|
|
78
|
-
}
|
|
79
|
-
if n < 0 {
|
|
80
|
-
n = countSep(s, sep) + 1
|
|
81
|
-
}
|
|
82
|
-
if n > len(s)+1 {
|
|
83
|
-
n = len(s) + 1
|
|
84
|
-
}
|
|
85
|
-
a := make([][]byte, n)
|
|
86
|
-
n--
|
|
87
|
-
i := 0
|
|
88
|
-
for i < n {
|
|
89
|
-
m := index(s, sep)
|
|
90
|
-
if m < 0 {
|
|
91
|
-
break
|
|
92
|
-
}
|
|
93
|
-
a[i] = s[: m+sepSave : m+sepSave]
|
|
94
|
-
s = s[m+len(sep):]
|
|
95
|
-
i++
|
|
96
|
-
}
|
|
97
|
-
a[i] = s[:len(s):len(s)]
|
|
98
|
-
return a[:i+1]
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// SplitAfter slices s into all subslices after each instance of sep and
|
|
102
|
-
// returns a slice of those subslices.
|
|
103
|
-
// If sep is empty, SplitAfter splits after each UTF-8 sequence.
|
|
104
|
-
// It is equivalent to SplitAfterN with a count of -1.
|
|
105
|
-
func SplitAfter(s, sep []byte) [][]byte {
|
|
106
|
-
return genSplit(s, sep, len(sep), -1)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// SplitAfterN slices s into subslices after each instance of sep and
|
|
110
|
-
// returns a slice of those subslices.
|
|
111
|
-
// The count determines the number of subslices to return:
|
|
112
|
-
// - n > 0: at most n subslices; the last subslice will be the unsplit remainder;
|
|
113
|
-
// - n == 0: the result is nil (zero subslices);
|
|
114
|
-
// - n < 0: all subslices.
|
|
115
|
-
func SplitAfterN(s, sep []byte, n int) [][]byte {
|
|
116
|
-
return genSplit(s, sep, len(sep), n)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Runes interprets s as a sequence of UTF-8-encoded code points.
|
|
120
|
-
// It returns a slice of runes (Unicode code points) equivalent to s.
|
|
121
|
-
func Runes(s []byte) []rune {
|
|
122
|
-
t := make([]rune, runeCount(s))
|
|
123
|
-
i := 0
|
|
124
|
-
for len(s) > 0 {
|
|
125
|
-
r, l := decodeRune(s)
|
|
126
|
-
t[i] = r
|
|
127
|
-
i++
|
|
128
|
-
s = s[l:]
|
|
129
|
-
}
|
|
130
|
-
return t
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// isSeparator reports whether the rune could mark a word boundary.
|
|
134
|
-
func isSeparator(r rune) bool {
|
|
135
|
-
if r <= 0x7F {
|
|
136
|
-
switch {
|
|
137
|
-
case '0' <= r && r <= '9':
|
|
138
|
-
return false
|
|
139
|
-
case 'a' <= r && r <= 'z':
|
|
140
|
-
return false
|
|
141
|
-
case 'A' <= r && r <= 'Z':
|
|
142
|
-
return false
|
|
143
|
-
case r == '_':
|
|
144
|
-
return false
|
|
145
|
-
}
|
|
146
|
-
return true
|
|
147
|
-
}
|
|
148
|
-
if unicode.IsLetter(int(r)) || unicode.IsDigit(int(r)) {
|
|
149
|
-
return false
|
|
150
|
-
}
|
|
151
|
-
return unicode.IsSpace(int(r))
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// appendRune appends the UTF-8 encoding of r to p, writing RuneError for a
|
|
155
|
-
// value that is not a valid code point.
|
|
156
|
-
// The continuation bytes mask a byte(r>>n) rather than r>>n: the JS backend
|
|
157
|
-
// drops the parentheses around a wrapped int32 shift in `x | r>>n&m`.
|
|
158
|
-
func appendRune(p []byte, r rune) []byte {
|
|
159
|
-
switch {
|
|
160
|
-
case r < 0 || r > 0x10FFFF || (r >= 0xD800 && r <= 0xDFFF):
|
|
161
|
-
r = runeError
|
|
162
|
-
case r < 0x80:
|
|
163
|
-
return append(p, byte(r))
|
|
164
|
-
}
|
|
165
|
-
switch {
|
|
166
|
-
case r < 0x800:
|
|
167
|
-
return append(p, byte(0xC0|r>>6), byte(0x80|r&0x3F))
|
|
168
|
-
case r < 0x10000:
|
|
169
|
-
return append(p, byte(0xE0|r>>12), 0x80|byte(r>>6)&0x3F, byte(0x80|r&0x3F))
|
|
170
|
-
}
|
|
171
|
-
return append(p, byte(0xF0|r>>18), 0x80|byte(r>>12)&0x3F, 0x80|byte(r>>6)&0x3F, byte(0x80|r&0x3F))
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// Title treats s as UTF-8-encoded bytes and returns a copy with all Unicode
|
|
175
|
-
// letters that begin words mapped to their title case.
|
|
176
|
-
//
|
|
177
|
-
// Deprecated: The rule Title uses for word boundaries does not handle Unicode
|
|
178
|
-
// punctuation properly.
|
|
179
|
-
func Title(s []byte) []byte {
|
|
180
|
-
prev := rune(' ')
|
|
181
|
-
out := make([]byte, 0, len(s))
|
|
182
|
-
for i := 0; i < len(s); {
|
|
183
|
-
r, size := decodeRune(s[i:])
|
|
184
|
-
i += size
|
|
185
|
-
c := r
|
|
186
|
-
if isSeparator(prev) {
|
|
187
|
-
c = unicode.ToTitle(r)
|
|
188
|
-
}
|
|
189
|
-
prev = r
|
|
190
|
-
if c >= 0 {
|
|
191
|
-
out = appendRune(out, c)
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return out
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// TrimLeftFunc treats s as UTF-8-encoded bytes and returns a subslice of s by slicing off
|
|
198
|
-
// all leading UTF-8-encoded code points c that satisfy f(c).
|
|
199
|
-
func TrimLeftFunc(s []byte, f func(r rune) bool) []byte {
|
|
200
|
-
i := indexFunc(s, f, false)
|
|
201
|
-
if i == -1 {
|
|
202
|
-
return nil
|
|
203
|
-
}
|
|
204
|
-
return s[i:]
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// TrimRightFunc returns a subslice of s by slicing off all trailing
|
|
208
|
-
// UTF-8-encoded code points c that satisfy f(c).
|
|
209
|
-
func TrimRightFunc(s []byte, f func(r rune) bool) []byte {
|
|
210
|
-
i := lastIndexFunc(s, f, false)
|
|
211
|
-
if i >= 0 && s[i] >= runeSelf {
|
|
212
|
-
_, wid := decodeRune(s[i:])
|
|
213
|
-
i += wid
|
|
214
|
-
} else {
|
|
215
|
-
i++
|
|
216
|
-
}
|
|
217
|
-
return s[0:i]
|
|
218
|
-
}
|
package/stdlib/errors/overlay.go
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
//go:build gofront
|
|
2
|
-
|
|
3
|
-
//gofront:target both
|
|
4
|
-
|
|
5
|
-
// Overlay on the emitter-backed errors package: these members are written
|
|
6
|
-
// in Go and merged into the errors namespace. Unqualified references to
|
|
7
|
-
// emitter members (New) resolve to the emitter implementation.
|
|
8
|
-
package errors
|
|
9
|
-
|
|
10
|
-
// ErrUnsupported indicates that a requested operation cannot be performed,
|
|
11
|
-
// because it is unsupported.
|
|
12
|
-
var ErrUnsupported = New("unsupported operation")
|