goscript 0.0.38 → 0.0.40

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 (180) hide show
  1. package/compiler/analysis.go +15 -6
  2. package/compiler/compiler.go +184 -34
  3. package/compiler/expr-call.go +19 -9
  4. package/compiler/field.go +17 -3
  5. package/compiler/gs_dependencies_test.go +80 -0
  6. package/compiler/lit.go +12 -6
  7. package/compiler/output.go +10 -4
  8. package/compiler/spec.go +15 -2
  9. package/compiler/type-assert.go +111 -21
  10. package/compiler/type.go +37 -8
  11. package/dist/gs/builtin/builtin.d.ts +55 -0
  12. package/dist/gs/builtin/builtin.js +213 -0
  13. package/dist/gs/builtin/builtin.js.map +1 -1
  14. package/dist/gs/builtin/slice.js +13 -0
  15. package/dist/gs/builtin/slice.js.map +1 -1
  16. package/dist/gs/bytes/buffer.gs.d.ts +56 -0
  17. package/dist/gs/bytes/buffer.gs.js +611 -0
  18. package/dist/gs/bytes/buffer.gs.js.map +1 -0
  19. package/dist/gs/bytes/bytes.gs.d.ts +78 -0
  20. package/dist/gs/bytes/bytes.gs.js +1107 -0
  21. package/dist/gs/bytes/bytes.gs.js.map +1 -0
  22. package/dist/gs/bytes/index.d.ts +4 -0
  23. package/dist/gs/bytes/index.js +5 -0
  24. package/dist/gs/bytes/index.js.map +1 -0
  25. package/dist/gs/bytes/iter.gs.d.ts +9 -0
  26. package/dist/gs/bytes/iter.gs.js +143 -0
  27. package/dist/gs/bytes/iter.gs.js.map +1 -0
  28. package/dist/gs/bytes/reader.gs.d.ts +34 -0
  29. package/dist/gs/bytes/reader.gs.js +198 -0
  30. package/dist/gs/bytes/reader.gs.js.map +1 -0
  31. package/dist/gs/fmt/fmt.d.ts +49 -0
  32. package/dist/gs/fmt/fmt.js +322 -0
  33. package/dist/gs/fmt/fmt.js.map +1 -0
  34. package/dist/gs/fmt/index.d.ts +1 -0
  35. package/dist/gs/fmt/index.js +2 -0
  36. package/dist/gs/fmt/index.js.map +1 -0
  37. package/dist/gs/internal/bytealg/index.d.ts +14 -2
  38. package/dist/gs/internal/bytealg/index.js +114 -8
  39. package/dist/gs/internal/bytealg/index.js.map +1 -1
  40. package/dist/gs/path/filepath/index.d.ts +3 -0
  41. package/dist/gs/path/filepath/index.js +3 -0
  42. package/dist/gs/path/filepath/index.js.map +1 -0
  43. package/dist/gs/path/filepath/match.d.ts +3 -0
  44. package/dist/gs/path/filepath/match.js +212 -0
  45. package/dist/gs/path/filepath/match.js.map +1 -0
  46. package/dist/gs/path/filepath/path.d.ts +25 -0
  47. package/dist/gs/path/filepath/path.js +265 -0
  48. package/dist/gs/path/filepath/path.js.map +1 -0
  49. package/dist/gs/reflect/deepequal.d.ts +2 -1
  50. package/dist/gs/reflect/deepequal.js +5 -53
  51. package/dist/gs/reflect/deepequal.js.map +1 -1
  52. package/dist/gs/reflect/map.d.ts +14 -8
  53. package/dist/gs/reflect/map.js +15 -11
  54. package/dist/gs/reflect/map.js.map +1 -1
  55. package/dist/gs/reflect/type.d.ts +17 -9
  56. package/dist/gs/reflect/type.js +1 -1
  57. package/dist/gs/reflect/type.js.map +1 -1
  58. package/dist/gs/reflect/value.js +15 -6
  59. package/dist/gs/reflect/value.js.map +1 -1
  60. package/dist/gs/reflect/visiblefields.js +18 -12
  61. package/dist/gs/reflect/visiblefields.js.map +1 -1
  62. package/dist/gs/sort/index.d.ts +4 -0
  63. package/dist/gs/sort/index.js +4 -0
  64. package/dist/gs/sort/index.js.map +1 -0
  65. package/dist/gs/sort/search.gs.d.ts +6 -0
  66. package/dist/gs/sort/search.gs.js +125 -0
  67. package/dist/gs/sort/search.gs.js.map +1 -0
  68. package/dist/gs/sort/slice.gs.d.ts +4 -0
  69. package/dist/gs/sort/slice.gs.js +49 -0
  70. package/dist/gs/sort/slice.gs.js.map +1 -0
  71. package/dist/gs/sort/sort.gs.d.ts +37 -0
  72. package/dist/gs/sort/sort.gs.js +203 -0
  73. package/dist/gs/sort/sort.gs.js.map +1 -0
  74. package/dist/gs/unicode/utf8/utf8.d.ts +1 -1
  75. package/dist/gs/unicode/utf8/utf8.js +4 -2
  76. package/dist/gs/unicode/utf8/utf8.js.map +1 -1
  77. package/gs/builtin/builtin.ts +236 -0
  78. package/gs/builtin/slice.ts +17 -1
  79. package/gs/bytes/buffer.gs.ts +614 -0
  80. package/gs/bytes/bytes.gs.ts +1288 -0
  81. package/gs/bytes/godoc.txt +69 -0
  82. package/gs/bytes/index.ts +69 -0
  83. package/gs/bytes/iter.gs.ts +149 -0
  84. package/gs/bytes/metadata.go +12 -0
  85. package/gs/bytes/reader.gs.ts +230 -0
  86. package/gs/fmt/fmt.ts +407 -0
  87. package/gs/fmt/godoc.txt +382 -0
  88. package/gs/fmt/index.ts +31 -0
  89. package/gs/fmt/metadata.go +7 -0
  90. package/gs/internal/bytealg/index.ts +125 -10
  91. package/gs/internal/metadata.go +7 -0
  92. package/gs/io/metadata.go +11 -0
  93. package/gs/maps/metadata.go +8 -0
  94. package/gs/math/metadata.go +7 -0
  95. package/gs/os/metadata.go +17 -0
  96. package/gs/path/filepath/godoc.txt +35 -0
  97. package/gs/path/filepath/index.ts +27 -0
  98. package/gs/path/filepath/match.test.ts +274 -0
  99. package/gs/path/filepath/match.ts +249 -0
  100. package/gs/path/filepath/path.test.ts +246 -0
  101. package/gs/path/filepath/path.ts +328 -0
  102. package/gs/path/metadata.go +8 -0
  103. package/gs/reflect/deepequal.test.ts +41 -0
  104. package/gs/reflect/deepequal.ts +19 -4
  105. package/gs/reflect/map.test.ts +30 -0
  106. package/gs/reflect/map.ts +22 -18
  107. package/gs/reflect/metadata.go +7 -0
  108. package/gs/reflect/type.ts +19 -15
  109. package/gs/reflect/value.ts +21 -7
  110. package/gs/reflect/visiblefields.ts +17 -13
  111. package/gs/sort/godoc.txt +27 -0
  112. package/gs/sort/index.ts +24 -0
  113. package/gs/sort/search.gs.ts +128 -0
  114. package/gs/sort/slice.gs.ts +59 -0
  115. package/gs/sort/sort.gs.ts +227 -0
  116. package/gs/strconv/metadata.go +7 -0
  117. package/gs/strings/metadata.go +11 -0
  118. package/gs/sync/metadata.go +7 -0
  119. package/gs/unicode/utf8/utf8.ts +8 -5
  120. package/package.json +1 -1
  121. package/dist/gs/internal/testlog/index.d.ts +0 -1
  122. package/dist/gs/internal/testlog/index.js +0 -5
  123. package/dist/gs/internal/testlog/index.js.map +0 -1
  124. package/dist/gs/maps/iter.gs.d.ts +0 -7
  125. package/dist/gs/maps/iter.gs.js +0 -65
  126. package/dist/gs/maps/iter.gs.js.map +0 -1
  127. package/dist/gs/maps/maps.gs.d.ts +0 -7
  128. package/dist/gs/maps/maps.gs.js +0 -79
  129. package/dist/gs/maps/maps.gs.js.map +0 -1
  130. package/dist/gs/reflect/abi.d.ts +0 -59
  131. package/dist/gs/reflect/abi.gs.d.ts +0 -59
  132. package/dist/gs/reflect/abi.gs.js +0 -79
  133. package/dist/gs/reflect/abi.gs.js.map +0 -1
  134. package/dist/gs/reflect/abi.js +0 -79
  135. package/dist/gs/reflect/abi.js.map +0 -1
  136. package/dist/gs/reflect/badlinkname.d.ts +0 -52
  137. package/dist/gs/reflect/badlinkname.gs.d.ts +0 -52
  138. package/dist/gs/reflect/badlinkname.gs.js +0 -72
  139. package/dist/gs/reflect/badlinkname.gs.js.map +0 -1
  140. package/dist/gs/reflect/badlinkname.js +0 -72
  141. package/dist/gs/reflect/badlinkname.js.map +0 -1
  142. package/dist/gs/reflect/deepequal.gs.d.ts +0 -25
  143. package/dist/gs/reflect/deepequal.gs.js +0 -308
  144. package/dist/gs/reflect/deepequal.gs.js.map +0 -1
  145. package/dist/gs/reflect/float32reg_generic.gs.d.ts +0 -2
  146. package/dist/gs/reflect/float32reg_generic.gs.js +0 -10
  147. package/dist/gs/reflect/float32reg_generic.gs.js.map +0 -1
  148. package/dist/gs/reflect/index.gs.d.ts +0 -1
  149. package/dist/gs/reflect/index.gs.js +0 -3
  150. package/dist/gs/reflect/index.gs.js.map +0 -1
  151. package/dist/gs/reflect/iter.gs.d.ts +0 -3
  152. package/dist/gs/reflect/iter.gs.js +0 -24
  153. package/dist/gs/reflect/iter.gs.js.map +0 -1
  154. package/dist/gs/reflect/makefunc.gs.d.ts +0 -34
  155. package/dist/gs/reflect/makefunc.gs.js +0 -288
  156. package/dist/gs/reflect/makefunc.gs.js.map +0 -1
  157. package/dist/gs/reflect/map_swiss.gs.d.ts +0 -14
  158. package/dist/gs/reflect/map_swiss.gs.js +0 -70
  159. package/dist/gs/reflect/map_swiss.gs.js.map +0 -1
  160. package/dist/gs/reflect/reflect.gs.d.ts +0 -132
  161. package/dist/gs/reflect/reflect.gs.js +0 -437
  162. package/dist/gs/reflect/reflect.gs.js.map +0 -1
  163. package/dist/gs/reflect/swapper.gs.d.ts +0 -1
  164. package/dist/gs/reflect/swapper.gs.js +0 -32
  165. package/dist/gs/reflect/swapper.gs.js.map +0 -1
  166. package/dist/gs/reflect/type.gs.d.ts +0 -4
  167. package/dist/gs/reflect/type.gs.js +0 -21
  168. package/dist/gs/reflect/type.gs.js.map +0 -1
  169. package/dist/gs/reflect/value.gs.d.ts +0 -4
  170. package/dist/gs/reflect/value.gs.js +0 -12
  171. package/dist/gs/reflect/value.gs.js.map +0 -1
  172. package/dist/gs/reflect/visiblefields.gs.d.ts +0 -3
  173. package/dist/gs/reflect/visiblefields.gs.js +0 -123
  174. package/dist/gs/reflect/visiblefields.gs.js.map +0 -1
  175. package/dist/gs/stringslite/index.d.ts +0 -1
  176. package/dist/gs/stringslite/index.js +0 -2
  177. package/dist/gs/stringslite/index.js.map +0 -1
  178. package/dist/gs/stringslite/strings.d.ts +0 -11
  179. package/dist/gs/stringslite/strings.js +0 -67
  180. package/dist/gs/stringslite/strings.js.map +0 -1
@@ -0,0 +1,382 @@
1
+ package fmt // import "fmt"
2
+
3
+ Package fmt implements formatted I/O with functions analogous to C's printf and
4
+ scanf. The format 'verbs' are derived from C's but are simpler.
5
+
6
+ # Printing
7
+
8
+ The verbs:
9
+
10
+ General:
11
+
12
+ %v the value in a default format
13
+ when printing structs, the plus flag (%+v) adds field names
14
+ %#v a Go-syntax representation of the value
15
+ (floating-point infinities and NaNs print as ±Inf and NaN)
16
+ %T a Go-syntax representation of the type of the value
17
+ %% a literal percent sign; consumes no value
18
+
19
+ Boolean:
20
+
21
+ %t the word true or false
22
+
23
+ Integer:
24
+
25
+ %b base 2
26
+ %c the character represented by the corresponding Unicode code point
27
+ %d base 10
28
+ %o base 8
29
+ %O base 8 with 0o prefix
30
+ %q a single-quoted character literal safely escaped with Go syntax.
31
+ %x base 16, with lower-case letters for a-f
32
+ %X base 16, with upper-case letters for A-F
33
+ %U Unicode format: U+1234; same as "U+%04X"
34
+
35
+ Floating-point and complex constituents:
36
+
37
+ %b decimalless scientific notation with exponent a power of two,
38
+ in the manner of strconv.FormatFloat with the 'b' format,
39
+ e.g. -123456p-78
40
+ %e scientific notation, e.g. -1.234456e+78
41
+ %E scientific notation, e.g. -1.234456E+78
42
+ %f decimal point but no exponent, e.g. 123.456
43
+ %F synonym for %f
44
+ %g %e for large exponents, %f otherwise. Precision is discussed below.
45
+ %G %E for large exponents, %F otherwise
46
+ %x hexadecimal notation (with decimal power of two exponent), e.g. -0x1.23abcp+20
47
+ %X upper-case hexadecimal notation, e.g. -0X1.23ABCP+20
48
+
49
+ The exponent is always a decimal integer.
50
+ For formats other than %b the exponent is at least two digits.
51
+
52
+ String and slice of bytes (treated equivalently with these verbs):
53
+
54
+ %s the uninterpreted bytes of the string or slice
55
+ %q a double-quoted string safely escaped with Go syntax
56
+ %x base 16, lower-case, two characters per byte
57
+ %X base 16, upper-case, two characters per byte
58
+
59
+ Slice:
60
+
61
+ %p address of 0th element in base 16 notation, with leading 0x
62
+
63
+ Pointer:
64
+
65
+ %p base 16 notation, with leading 0x
66
+ The %b, %d, %o, %x and %X verbs also work with pointers,
67
+ formatting the value exactly as if it were an integer.
68
+
69
+ The default format for %v is:
70
+
71
+ bool: %t
72
+ int, int8 etc.: %d
73
+ uint, uint8 etc.: %d, %#x if printed with %#v
74
+ float32, complex64, etc: %g
75
+ string: %s
76
+ chan: %p
77
+ pointer: %p
78
+
79
+ For compound objects, the elements are printed using these rules, recursively,
80
+ laid out like this:
81
+
82
+ struct: {field0 field1 ...}
83
+ array, slice: [elem0 elem1 ...]
84
+ maps: map[key1:value1 key2:value2 ...]
85
+ pointer to above: &{}, &[], &map[]
86
+
87
+ Width is specified by an optional decimal number immediately preceding the verb.
88
+ If absent, the width is whatever is necessary to represent the value. Precision
89
+ is specified after the (optional) width by a period followed by a decimal
90
+ number. If no period is present, a default precision is used. A period with no
91
+ following number specifies a precision of zero. Examples:
92
+
93
+ %f default width, default precision
94
+ %9f width 9, default precision
95
+ %.2f default width, precision 2
96
+ %9.2f width 9, precision 2
97
+ %9.f width 9, precision 0
98
+
99
+ Width and precision are measured in units of Unicode code points, that is,
100
+ runes. (This differs from C's printf where the units are always measured in
101
+ bytes.) Either or both of the flags may be replaced with the character '*',
102
+ causing their values to be obtained from the next operand (preceding the one to
103
+ format), which must be of type int.
104
+
105
+ For most values, width is the minimum number of runes to output, padding the
106
+ formatted form with spaces if necessary.
107
+
108
+ For strings, byte slices and byte arrays, however, precision limits the length
109
+ of the input to be formatted (not the size of the output), truncating if
110
+ necessary. Normally it is measured in runes, but for these types when formatted
111
+ with the %x or %X format it is measured in bytes.
112
+
113
+ For floating-point values, width sets the minimum width of the field and
114
+ precision sets the number of places after the decimal, if appropriate, except
115
+ that for %g/%G precision sets the maximum number of significant digits (trailing
116
+ zeros are removed). For example, given 12.345 the format %6.3f prints 12.345
117
+ while %.3g prints 12.3. The default precision for %e, %f and %#g is 6; for %g it
118
+ is the smallest number of digits necessary to identify the value uniquely.
119
+
120
+ For complex numbers, the width and precision apply to the two components
121
+ independently and the result is parenthesized, so %f applied to 1.2+3.4i
122
+ produces (1.200000+3.400000i).
123
+
124
+ When formatting a single integer code point or a rune string (type []rune)
125
+ with %q, invalid Unicode code points are changed to the Unicode replacement
126
+ character, U+FFFD, as in strconv.QuoteRune.
127
+
128
+ Other flags:
129
+
130
+ '+' always print a sign for numeric values;
131
+ guarantee ASCII-only output for %q (%+q)
132
+ '-' pad with spaces on the right rather than the left (left-justify the field)
133
+ '#' alternate format: add leading 0b for binary (%#b), 0 for octal (%#o),
134
+ 0x or 0X for hex (%#x or %#X); suppress 0x for %p (%#p);
135
+ for %q, print a raw (backquoted) string if [strconv.CanBackquote]
136
+ returns true;
137
+ always print a decimal point for %e, %E, %f, %F, %g and %G;
138
+ do not remove trailing zeros for %g and %G;
139
+ write e.g. U+0078 'x' if the character is printable for %U (%#U)
140
+ ' ' (space) leave a space for elided sign in numbers (% d);
141
+ put spaces between bytes printing strings or slices in hex (% x, % X)
142
+ '0' pad with leading zeros rather than spaces;
143
+ for numbers, this moves the padding after the sign
144
+
145
+ Flags are ignored by verbs that do not expect them. For example there is no
146
+ alternate decimal format, so %#d and %d behave identically.
147
+
148
+ For each Printf-like function, there is also a Print function that takes no
149
+ format and is equivalent to saying %v for every operand. Another variant Println
150
+ inserts blanks between operands and appends a newline.
151
+
152
+ Regardless of the verb, if an operand is an interface value, the internal
153
+ concrete value is used, not the interface itself. Thus:
154
+
155
+ var i interface{} = 23
156
+ fmt.Printf("%v\n", i)
157
+
158
+ will print 23.
159
+
160
+ Except when printed using the verbs %T and %p, special formatting considerations
161
+ apply for operands that implement certain interfaces. In order of application:
162
+
163
+ 1. If the operand is a reflect.Value, the operand is replaced by the concrete
164
+ value that it holds, and printing continues with the next rule.
165
+
166
+ 2. If an operand implements the Formatter interface, it will be invoked. In this
167
+ case the interpretation of verbs and flags is controlled by that implementation.
168
+
169
+ 3. If the %v verb is used with the # flag (%#v) and the operand implements the
170
+ GoStringer interface, that will be invoked.
171
+
172
+ If the format (which is implicitly %v for Println etc.) is valid for a string
173
+ (%s %q %x %X), or is %v but not %#v, the following two rules apply:
174
+
175
+ 4. If an operand implements the error interface, the Error method will be
176
+ invoked to convert the object to a string, which will then be formatted as
177
+ required by the verb (if any).
178
+
179
+ 5. If an operand implements method String() string, that method will be invoked
180
+ to convert the object to a string, which will then be formatted as required by
181
+ the verb (if any).
182
+
183
+ For compound operands such as slices and structs, the format applies to the
184
+ elements of each operand, recursively, not to the operand as a whole. Thus %q
185
+ will quote each element of a slice of strings, and %6.2f will control formatting
186
+ for each element of a floating-point array.
187
+
188
+ However, when printing a byte slice with a string-like verb (%s %q %x %X),
189
+ it is treated identically to a string, as a single item.
190
+
191
+ To avoid recursion in cases such as
192
+
193
+ type X string
194
+ func (x X) String() string { return Sprintf("<%s>", x) }
195
+
196
+ convert the value before recurring:
197
+
198
+ func (x X) String() string { return Sprintf("<%s>", string(x)) }
199
+
200
+ Infinite recursion can also be triggered by self-referential data structures,
201
+ such as a slice that contains itself as an element, if that type has a String
202
+ method. Such pathologies are rare, however, and the package does not protect
203
+ against them.
204
+
205
+ When printing a struct, fmt cannot and therefore does not invoke formatting
206
+ methods such as Error or String on unexported fields.
207
+
208
+ # Explicit argument indexes
209
+
210
+ In Printf, Sprintf, and Fprintf, the default behavior is for each formatting
211
+ verb to format successive arguments passed in the call. However, the notation
212
+ [n] immediately before the verb indicates that the nth one-indexed argument
213
+ is to be formatted instead. The same notation before a '*' for a width or
214
+ precision selects the argument index holding the value. After processing a
215
+ bracketed expression [n], subsequent verbs will use arguments n+1, n+2, etc.
216
+ unless otherwise directed.
217
+
218
+ For example,
219
+
220
+ fmt.Sprintf("%[2]d %[1]d\n", 11, 22)
221
+
222
+ will yield "22 11", while
223
+
224
+ fmt.Sprintf("%[3]*.[2]*[1]f", 12.0, 2, 6)
225
+
226
+ equivalent to
227
+
228
+ fmt.Sprintf("%6.2f", 12.0)
229
+
230
+ will yield " 12.00". Because an explicit index affects subsequent verbs,
231
+ this notation can be used to print the same values multiple times by resetting
232
+ the index for the first argument to be repeated:
233
+
234
+ fmt.Sprintf("%d %d %#[1]x %#x", 16, 17)
235
+
236
+ will yield "16 17 0x10 0x11".
237
+
238
+ # Format errors
239
+
240
+ If an invalid argument is given for a verb, such as providing a string to %d,
241
+ the generated string will contain a description of the problem, as in these
242
+ examples:
243
+
244
+ Wrong type or unknown verb: %!verb(type=value)
245
+ Printf("%d", "hi"): %!d(string=hi)
246
+ Too many arguments: %!(EXTRA type=value)
247
+ Printf("hi", "guys"): hi%!(EXTRA string=guys)
248
+ Too few arguments: %!verb(MISSING)
249
+ Printf("hi%d"): hi%!d(MISSING)
250
+ Non-int for width or precision: %!(BADWIDTH) or %!(BADPREC)
251
+ Printf("%*s", 4.5, "hi"): %!(BADWIDTH)hi
252
+ Printf("%.*s", 4.5, "hi"): %!(BADPREC)hi
253
+ Invalid or invalid use of argument index: %!(BADINDEX)
254
+ Printf("%*[2]d", 7): %!d(BADINDEX)
255
+ Printf("%.[2]d", 7): %!d(BADINDEX)
256
+
257
+ All errors begin with the string "%!" followed sometimes by a single character
258
+ (the verb) and end with a parenthesized description.
259
+
260
+ If an Error or String method triggers a panic when called by a print routine,
261
+ the fmt package reformats the error message from the panic, decorating it with
262
+ an indication that it came through the fmt package. For example, if a String
263
+ method calls panic("bad"), the resulting formatted message will look like
264
+
265
+ %!s(PANIC=bad)
266
+
267
+ The %!s just shows the print verb in use when the failure occurred. If the panic
268
+ is caused by a nil receiver to an Error, String, or GoString method, however,
269
+ the output is the undecorated string, "<nil>".
270
+
271
+ # Scanning
272
+
273
+ An analogous set of functions scans formatted text to yield values. Scan, Scanf
274
+ and Scanln read from os.Stdin; Fscan, Fscanf and Fscanln read from a specified
275
+ io.Reader; Sscan, Sscanf and Sscanln read from an argument string.
276
+
277
+ Scan, Fscan, Sscan treat newlines in the input as spaces.
278
+
279
+ Scanln, Fscanln and Sscanln stop scanning at a newline and require that the
280
+ items be followed by a newline or EOF.
281
+
282
+ Scanf, Fscanf, and Sscanf parse the arguments according to a format string,
283
+ analogous to that of Printf. In the text that follows, 'space' means any Unicode
284
+ whitespace character except newline.
285
+
286
+ In the format string, a verb introduced by the % character consumes and parses
287
+ input; these verbs are described in more detail below. A character other than %,
288
+ space, or newline in the format consumes exactly that input character, which
289
+ must be present. A newline with zero or more spaces before it in the format
290
+ string consumes zero or more spaces in the input followed by a single newline or
291
+ the end of the input. A space following a newline in the format string consumes
292
+ zero or more spaces in the input. Otherwise, any run of one or more spaces in
293
+ the format string consumes as many spaces as possible in the input. Unless the
294
+ run of spaces in the format string appears adjacent to a newline, the run must
295
+ consume at least one space from the input or find the end of the input.
296
+
297
+ The handling of spaces and newlines differs from that of C's scanf family: in C,
298
+ newlines are treated as any other space, and it is never an error when a run of
299
+ spaces in the format string finds no spaces to consume in the input.
300
+
301
+ The verbs behave analogously to those of Printf. For example, %x will scan an
302
+ integer as a hexadecimal number, and %v will scan the default representation
303
+ format for the value. The Printf verbs %p and %T and the flags # and + are not
304
+ implemented. For floating-point and complex values, all valid formatting verbs
305
+ (%b %e %E %f %F %g %G %x %X and %v) are equivalent and accept both decimal and
306
+ hexadecimal notation (for example: "2.3e+7", "0x4.5p-8") and digit-separating
307
+ underscores (for example: "3.14159_26535_89793").
308
+
309
+ Input processed by verbs is implicitly space-delimited: the implementation of
310
+ every verb except %c starts by discarding leading spaces from the remaining
311
+ input, and the %s verb (and %v reading into a string) stops consuming input at
312
+ the first space or newline character.
313
+
314
+ The familiar base-setting prefixes 0b (binary), 0o and 0 (octal), and 0x
315
+ (hexadecimal) are accepted when scanning integers without a format or with the
316
+ %v verb, as are digit-separating underscores.
317
+
318
+ Width is interpreted in the input text but there is no syntax for scanning with
319
+ a precision (no %5.2f, just %5f). If width is provided, it applies after leading
320
+ spaces are trimmed and specifies the maximum number of runes to read to satisfy
321
+ the verb. For example,
322
+
323
+ Sscanf(" 1234567 ", "%5s%d", &s, &i)
324
+
325
+ will set s to "12345" and i to 67 while
326
+
327
+ Sscanf(" 12 34 567 ", "%5s%d", &s, &i)
328
+
329
+ will set s to "12" and i to 34.
330
+
331
+ In all the scanning functions, a carriage return followed immediately by a
332
+ newline is treated as a plain newline (\r\n means the same as \n).
333
+
334
+ In all the scanning functions, if an operand implements method Scan (that is,
335
+ it implements the Scanner interface) that method will be used to scan the text
336
+ for that operand. Also, if the number of arguments scanned is less than the
337
+ number of arguments provided, an error is returned.
338
+
339
+ All arguments to be scanned must be either pointers to basic types or
340
+ implementations of the Scanner interface.
341
+
342
+ Like Scanf and Fscanf, Sscanf need not consume its entire input. There is no way
343
+ to recover how much of the input string Sscanf used.
344
+
345
+ Note: Fscan etc. can read one character (rune) past the input they return,
346
+ which means that a loop calling a scan routine may skip some of the input.
347
+ This is usually a problem only when there is no space between input values.
348
+ If the reader provided to Fscan implements ReadRune, that method will be used
349
+ to read characters. If the reader also implements UnreadRune, that method
350
+ will be used to save the character and successive calls will not lose data.
351
+ To attach ReadRune and UnreadRune methods to a reader without that capability,
352
+ use bufio.NewReader.
353
+
354
+ func Append(b []byte, a ...any) []byte
355
+ func Appendf(b []byte, format string, a ...any) []byte
356
+ func Appendln(b []byte, a ...any) []byte
357
+ func Errorf(format string, a ...any) error
358
+ func FormatString(state State, verb rune) string
359
+ func Fprint(w io.Writer, a ...any) (n int, err error)
360
+ func Fprintf(w io.Writer, format string, a ...any) (n int, err error)
361
+ func Fprintln(w io.Writer, a ...any) (n int, err error)
362
+ func Fscan(r io.Reader, a ...any) (n int, err error)
363
+ func Fscanf(r io.Reader, format string, a ...any) (n int, err error)
364
+ func Fscanln(r io.Reader, a ...any) (n int, err error)
365
+ func Print(a ...any) (n int, err error)
366
+ func Printf(format string, a ...any) (n int, err error)
367
+ func Println(a ...any) (n int, err error)
368
+ func Scan(a ...any) (n int, err error)
369
+ func Scanf(format string, a ...any) (n int, err error)
370
+ func Scanln(a ...any) (n int, err error)
371
+ func Sprint(a ...any) string
372
+ func Sprintf(format string, a ...any) string
373
+ func Sprintln(a ...any) string
374
+ func Sscan(str string, a ...any) (n int, err error)
375
+ func Sscanf(str string, format string, a ...any) (n int, err error)
376
+ func Sscanln(str string, a ...any) (n int, err error)
377
+ type Formatter interface{ ... }
378
+ type GoStringer interface{ ... }
379
+ type ScanState interface{ ... }
380
+ type Scanner interface{ ... }
381
+ type State interface{ ... }
382
+ type Stringer interface{ ... }
@@ -0,0 +1,31 @@
1
+ export {
2
+ Errorf,
3
+ Print,
4
+ Printf,
5
+ Println,
6
+ Sprint,
7
+ Sprintf,
8
+ Sprintln,
9
+ Fprint,
10
+ Fprintf,
11
+ Fprintln,
12
+ Append,
13
+ Appendf,
14
+ Appendln,
15
+ FormatString,
16
+ Scan,
17
+ Scanf,
18
+ Scanln,
19
+ Sscan,
20
+ Sscanf,
21
+ Sscanln,
22
+ Fscan,
23
+ Fscanf,
24
+ Fscanln,
25
+ Formatter,
26
+ GoStringer,
27
+ Stringer,
28
+ State,
29
+ Scanner,
30
+ ScanState,
31
+ } from './fmt.js'
@@ -0,0 +1,7 @@
1
+ package fmt
2
+
3
+ // GsDependencies lists the import paths that this gs/ package requires
4
+ // These dependencies will be automatically copied when this package is included
5
+ var GsDependencies = []string{
6
+ "errors",
7
+ }
@@ -1,12 +1,31 @@
1
1
  // Placeholder bytealg module for reflect package compatibility
2
2
 
3
+ // Helper function to normalize bytes input
4
+ function normalizeBytes(b: any): any[] {
5
+ if (b === null || b === undefined) {
6
+ return []
7
+ }
8
+ if (Array.isArray(b)) {
9
+ return b
10
+ }
11
+ if (b instanceof Uint8Array) {
12
+ return Array.from(b)
13
+ }
14
+ if (b && typeof b === 'object' && 'data' in b && Array.isArray(b.data)) {
15
+ return b.data
16
+ }
17
+ return []
18
+ }
19
+
3
20
  // Equal reports whether a and b are the same length and contain the same bytes.
4
- export function Equal(a: Uint8Array | any[], b: Uint8Array | any[]): boolean {
5
- if (a.length !== b.length) {
21
+ export function Equal(a: any, b: any): boolean {
22
+ const aNorm = normalizeBytes(a)
23
+ const bNorm = normalizeBytes(b)
24
+ if (aNorm.length !== bNorm.length) {
6
25
  return false
7
26
  }
8
- for (let i = 0; i < a.length; i++) {
9
- if (a[i] !== b[i]) {
27
+ for (let i = 0; i < aNorm.length; i++) {
28
+ if (aNorm[i] !== bNorm[i]) {
10
29
  return false
11
30
  }
12
31
  }
@@ -14,21 +33,117 @@ export function Equal(a: Uint8Array | any[], b: Uint8Array | any[]): boolean {
14
33
  }
15
34
 
16
35
  // Compare returns an integer comparing two byte slices lexicographically.
17
- export function Compare(a: Uint8Array | any[], b: Uint8Array | any[]): number {
18
- const minLen = Math.min(a.length, b.length)
36
+ export function Compare(a: any, b: any): number {
37
+ const aNorm = normalizeBytes(a)
38
+ const bNorm = normalizeBytes(b)
39
+ const minLen = Math.min(aNorm.length, bNorm.length)
19
40
  for (let i = 0; i < minLen; i++) {
20
- if (a[i] < b[i]) {
41
+ if (aNorm[i] < bNorm[i]) {
21
42
  return -1
22
43
  }
23
- if (a[i] > b[i]) {
44
+ if (aNorm[i] > bNorm[i]) {
24
45
  return 1
25
46
  }
26
47
  }
27
- if (a.length < b.length) {
48
+ if (aNorm.length < bNorm.length) {
28
49
  return -1
29
50
  }
30
- if (a.length > b.length) {
51
+ if (aNorm.length > bNorm.length) {
31
52
  return 1
32
53
  }
33
54
  return 0
34
55
  }
56
+
57
+ // Additional functions needed by bytes package
58
+ export function Count(s: any, b: number): number {
59
+ const sNorm = normalizeBytes(s)
60
+ let count = 0
61
+ for (let i = 0; i < sNorm.length; i++) {
62
+ if (sNorm[i] === b) {
63
+ count++
64
+ }
65
+ }
66
+ return count
67
+ }
68
+
69
+ export function IndexByte(s: any, b: number): number {
70
+ const sNorm = normalizeBytes(s)
71
+ for (let i = 0; i < sNorm.length; i++) {
72
+ if (sNorm[i] === b) {
73
+ return i
74
+ }
75
+ }
76
+ return -1
77
+ }
78
+
79
+ export function LastIndexByte(s: any, b: number): number {
80
+ const sNorm = normalizeBytes(s)
81
+ for (let i = sNorm.length - 1; i >= 0; i--) {
82
+ if (sNorm[i] === b) {
83
+ return i
84
+ }
85
+ }
86
+ return -1
87
+ }
88
+
89
+ export function Index(s: any, sep: any): number {
90
+ const sNorm = normalizeBytes(s)
91
+ const sepNorm = normalizeBytes(sep)
92
+ if (sepNorm.length === 0) return 0
93
+ if (sepNorm.length > sNorm.length) return -1
94
+
95
+ for (let i = 0; i <= sNorm.length - sepNorm.length; i++) {
96
+ let found = true
97
+ for (let j = 0; j < sepNorm.length; j++) {
98
+ if (sNorm[i + j] !== sepNorm[j]) {
99
+ found = false
100
+ break
101
+ }
102
+ }
103
+ if (found) return i
104
+ }
105
+ return -1
106
+ }
107
+
108
+ export function LastIndexRabinKarp(s: any, sep: any): number {
109
+ const sNorm = normalizeBytes(s)
110
+ const sepNorm = normalizeBytes(sep)
111
+ // Simple implementation
112
+ for (let i = sNorm.length - sepNorm.length; i >= 0; i--) {
113
+ let found = true
114
+ for (let j = 0; j < sepNorm.length; j++) {
115
+ if (sNorm[i + j] !== sepNorm[j]) {
116
+ found = false
117
+ break
118
+ }
119
+ }
120
+ if (found) return i
121
+ }
122
+ return -1
123
+ }
124
+
125
+ export function IndexRabinKarp(s: any, sep: any): number {
126
+ return Index(s, sep)
127
+ }
128
+
129
+ export function IndexByteString(s: string, b: number): number {
130
+ const char = String.fromCharCode(b)
131
+ return s.indexOf(char)
132
+ }
133
+
134
+ export function IndexString(s: string, substr: string): number {
135
+ return s.indexOf(substr)
136
+ }
137
+
138
+ export function MakeNoZero(n: number): Uint8Array {
139
+ return new Uint8Array(n)
140
+ }
141
+
142
+ export function Cutover(_n: number): number {
143
+ // TODO: Implement Cutover function
144
+ return 10 // Simple threshold
145
+ }
146
+
147
+ // Constants needed by bytes package
148
+ export const MaxBruteForce = 64
149
+ export const MaxLen = 32
@@ -0,0 +1,7 @@
1
+ package internal
2
+
3
+ // GsDependencies lists the import paths that this gs/ package requires
4
+ // These dependencies will be automatically copied when this package is included
5
+ var GsDependencies = []string{
6
+ "errors",
7
+ }
@@ -0,0 +1,11 @@
1
+ package io
2
+
3
+ // GsDependencies lists the import paths that this gs/ package requires
4
+ // These dependencies will be automatically copied when this package is included
5
+ var GsDependencies = []string{
6
+ "errors",
7
+ "internal/oserror",
8
+ "path",
9
+ "time",
10
+ "unicode/utf8",
11
+ }
@@ -0,0 +1,8 @@
1
+ package maps
2
+
3
+ // GsDependencies lists the import paths that this gs/ package requires
4
+ // These dependencies will be automatically copied when this package is included
5
+ var GsDependencies = []string{
6
+ "iter",
7
+ "unsafe",
8
+ }
@@ -0,0 +1,7 @@
1
+ package math
2
+
3
+ // GsDependencies lists the import paths that this gs/ package requires
4
+ // These dependencies will be automatically copied when this package is included
5
+ var GsDependencies = []string{
6
+ "math/bits",
7
+ }
@@ -0,0 +1,17 @@
1
+ package os
2
+
3
+ // GsDependencies lists the import paths that this gs/ package requires
4
+ // These dependencies will be automatically copied when this package is included
5
+ var GsDependencies = []string{
6
+ "errors",
7
+ "internal/byteorder",
8
+ "internal/goarch",
9
+ "internal/poll",
10
+ "io",
11
+ "io/fs",
12
+ "runtime",
13
+ "sync",
14
+ "syscall",
15
+ "time",
16
+ "unsafe",
17
+ }
@@ -0,0 +1,35 @@
1
+ package filepath // import "path/filepath"
2
+
3
+ Package filepath implements utility routines for manipulating filename paths in
4
+ a way compatible with the target operating system-defined file paths.
5
+
6
+ The filepath package uses either forward slashes or backslashes, depending on
7
+ the operating system. To process paths such as URLs that always use forward
8
+ slashes regardless of the operating system, see the path package.
9
+
10
+ const Separator = os.PathSeparator ...
11
+ var ErrBadPattern = errors.New("syntax error in pattern")
12
+ var SkipAll error = fs.SkipAll
13
+ var SkipDir error = fs.SkipDir
14
+ func Abs(path string) (string, error)
15
+ func Base(path string) string
16
+ func Clean(path string) string
17
+ func Dir(path string) string
18
+ func EvalSymlinks(path string) (string, error)
19
+ func Ext(path string) string
20
+ func FromSlash(path string) string
21
+ func Glob(pattern string) (matches []string, err error)
22
+ func HasPrefix(p, prefix string) bool
23
+ func IsAbs(path string) bool
24
+ func IsLocal(path string) bool
25
+ func Join(elem ...string) string
26
+ func Localize(path string) (string, error)
27
+ func Match(pattern, name string) (matched bool, err error)
28
+ func Rel(basepath, targpath string) (string, error)
29
+ func Split(path string) (dir, file string)
30
+ func SplitList(path string) []string
31
+ func ToSlash(path string) string
32
+ func VolumeName(path string) string
33
+ func Walk(root string, fn WalkFunc) error
34
+ func WalkDir(root string, fn fs.WalkDirFunc) error
35
+ type WalkFunc func(path string, info fs.FileInfo, err error) error