typenative 0.6.2 → 0.7.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 +1 -1
- package/bin/cli.js +18 -8
- package/bin/go/overrides.js +21 -1
- package/bin/index.js +48 -25
- package/bin/main.js +2 -1
- package/bin/node/assert.js +56 -17
- package/bin/node/async_hooks.js +69 -10
- package/bin/node/buffer.js +321 -7
- package/bin/node/child_process.js +220 -16
- package/bin/node/cluster.js +436 -32
- package/bin/node/crypto.js +814 -5
- package/bin/node/crypto_curves.js +142 -0
- package/bin/node/crypto_keys.js +1147 -48
- package/bin/node/crypto_pem.js +313 -0
- package/bin/node/crypto_pkcs12.js +17 -0
- package/bin/node/dgram.js +161 -10
- package/bin/node/diagnostics_channel.js +5 -1
- package/bin/node/events.js +358 -8
- package/bin/node/ffi.js +933 -0
- package/bin/node/fs.js +1346 -10
- package/bin/node/histogram.js +1991 -0
- package/bin/node/http.js +630 -55
- package/bin/node/http2.js +1141 -88
- package/bin/node/intl.js +4576 -0
- package/bin/node/intl_data.js +65412 -0
- package/bin/node/module_v8.js +155 -16
- package/bin/node/net.js +59 -10
- package/bin/node/path.js +5 -1
- package/bin/node/process.js +355 -4
- package/bin/node/readline.js +558 -8
- package/bin/node/registry.js +2 -0
- package/bin/node/sqlite.js +1539 -7
- package/bin/node/stream.js +371 -32
- package/bin/node/stream_web.js +422 -15
- package/bin/node/system_extra.js +40 -154
- package/bin/node/temporal.js +96 -0
- package/bin/node/temporal_runtime.js +5075 -0
- package/bin/node/temporal_zones.js +460 -0
- package/bin/node/test.js +191 -8
- package/bin/node/test_coverage.js +58 -0
- package/bin/node/test_report.js +50 -4
- package/bin/node/test_run.js +64 -3
- package/bin/node/timers.js +123 -0
- package/bin/node/tls.js +346 -12
- package/bin/node/tls_roots.js +122 -0
- package/bin/node/typed_arrays.js +867 -93
- package/bin/node/url.js +657 -0
- package/bin/node/util.js +449 -7
- package/bin/node/util_extra.js +6 -0
- package/bin/node/wasi.js +214 -0
- package/bin/node/webassembly.js +1137 -0
- package/bin/node/websocket.js +763 -0
- package/bin/node/webview.js +3257 -244
- package/bin/node/worker_threads.js +434 -52
- package/bin/node/zlib.js +455 -22
- package/bin/node/zlib_iter.js +585 -0
- package/bin/node/zlib_zip.js +2392 -0
- package/bin/transpiler.js +3417 -501
- package/bin/typecheck-node.js +49 -17
- package/bin/version.js +1 -1
- package/govendor/github.com/cloudflare/circl/.golangci.yaml +64 -0
- package/govendor/github.com/cloudflare/circl/.semgrepignore +1 -0
- package/govendor/github.com/cloudflare/circl/AGENTS.md +91 -0
- package/govendor/github.com/cloudflare/circl/CITATION.cff +30 -0
- package/govendor/github.com/cloudflare/circl/LICENSE +57 -0
- package/govendor/github.com/cloudflare/circl/Makefile +70 -0
- package/govendor/github.com/cloudflare/circl/README.md +206 -0
- package/govendor/github.com/cloudflare/circl/REVIEW.md +83 -0
- package/govendor/github.com/cloudflare/circl/codecov.yml +21 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve.go +104 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_amd64.go +30 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_amd64.h +111 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_amd64.s +194 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_generic.go +100 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/curve_noasm.go +11 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/doc.go +19 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/key.go +46 -0
- package/govendor/github.com/cloudflare/circl/dh/x448/table.go +460 -0
- package/govendor/github.com/cloudflare/circl/doc.go +8 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/constants.go +71 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/curve.go +90 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/isogeny.go +52 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/point.go +181 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/scalar.go +203 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twist.go +138 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twistPoint.go +135 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twistTables.go +216 -0
- package/govendor/github.com/cloudflare/circl/ecc/goldilocks/twist_basemult.go +62 -0
- package/govendor/github.com/cloudflare/circl/go.mod +3 -0
- package/govendor/github.com/cloudflare/circl/internal/conv/conv.go +173 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/doc.go +62 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/hashes.go +69 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/keccakf.go +391 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/rc.go +29 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/sha3.go +200 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/sha3_s390x.s +33 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/shake.go +119 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/xor.go +15 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/xor_generic.go +33 -0
- package/govendor/github.com/cloudflare/circl/internal/sha3/xor_unaligned.go +61 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp.go +164 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_amd64.go +43 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_amd64.h +591 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_amd64.s +75 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_generic.go +339 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fp_noasm.go +12 -0
- package/govendor/github.com/cloudflare/circl/math/fp448/fuzzer.go +75 -0
- package/govendor/github.com/cloudflare/circl/math/integer.go +16 -0
- package/govendor/github.com/cloudflare/circl/math/mlsbset/mlsbset.go +145 -0
- package/govendor/github.com/cloudflare/circl/math/mlsbset/power.go +64 -0
- package/govendor/github.com/cloudflare/circl/math/primes.go +34 -0
- package/govendor/github.com/cloudflare/circl/math/wnaf.go +84 -0
- package/govendor/github.com/cloudflare/circl/sign/ed448/ed448.go +417 -0
- package/govendor/github.com/cloudflare/circl/sign/ed448/signapi.go +89 -0
- package/govendor/github.com/cloudflare/circl/sign/sign.go +119 -0
- package/{examples/react-compiler/vendor/picocolors → govendor/github.com/decred/dcrd/dcrec/secp256k1/v4}/LICENSE +4 -2
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/README.md +72 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/compressedbytepoints.go +18 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/curve.go +1310 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/curve_embedded.go +14 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/curve_precompute.go +14 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/doc.go +59 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdh.go +21 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/README.md +52 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/doc.go +42 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/error.go +134 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ecdsa/signature.go +1001 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/ellipticadaptor.go +296 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/error.go +67 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/field.go +1696 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/go.mod +3 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/loadprecomputed.go +91 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/modnscalar.go +1105 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/nonce.go +263 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/privkey.go +111 -0
- package/govendor/github.com/decred/dcrd/dcrec/secp256k1/v4/pubkey.go +236 -0
- package/govendor/github.com/ebitengine/purego/LICENSE +201 -0
- package/govendor/github.com/ebitengine/purego/README.md +124 -0
- package/govendor/github.com/ebitengine/purego/abi_amd64.h +99 -0
- package/govendor/github.com/ebitengine/purego/abi_arm64.h +39 -0
- package/govendor/github.com/ebitengine/purego/abi_loong64.h +60 -0
- package/govendor/github.com/ebitengine/purego/cdecl.go +11 -0
- package/govendor/github.com/ebitengine/purego/cgo.go +19 -0
- package/govendor/github.com/ebitengine/purego/dlerror.go +17 -0
- package/govendor/github.com/ebitengine/purego/dlfcn.go +99 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_android.go +34 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_darwin.go +20 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_freebsd.go +14 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_linux.go +16 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_netbsd.go +15 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_nocgo_freebsd.go +11 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_nocgo_linux.go +19 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_nocgo_netbsd.go +11 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_playground.go +24 -0
- package/govendor/github.com/ebitengine/purego/dlfcn_stubs.s +22 -0
- package/govendor/github.com/ebitengine/purego/func.go +780 -0
- package/govendor/github.com/ebitengine/purego/gen.go +6 -0
- package/govendor/github.com/ebitengine/purego/go.mod +3 -0
- package/govendor/github.com/ebitengine/purego/go_runtime.go +19 -0
- package/govendor/github.com/ebitengine/purego/internal/cgo/dlfcn_cgo_unix.go +56 -0
- package/govendor/github.com/ebitengine/purego/internal/cgo/empty.go +6 -0
- package/govendor/github.com/ebitengine/purego/internal/cgo/syscall_cgo_unix.go +49 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_amd64.h +99 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_arm64.h +39 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_loong64.h +60 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_ppc64x.h +195 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/abi_riscv64.h +72 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_386.s +29 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_amd64.s +39 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_arm.s +58 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_arm64.s +35 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_loong64.s +38 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_ppc64le.s +79 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_riscv64.s +36 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/asm_s390x.s +52 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/callbacks.go +93 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/doc.go +32 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/fakecgo.go +14 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/freebsd.go +27 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_darwin.go +86 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_freebsd.go +77 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_libinit.go +72 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_linux.go +77 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_netbsd.go +83 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_setenv.go +18 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/go_util.go +38 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/iscgo.go +19 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo.go +37 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_darwin.go +37 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_freebsd.go +27 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_linux.go +27 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/libcgo_netbsd.go +36 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/linux.go +189 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/netbsd.go +23 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/setenv.go +19 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/threadentry_amd64.go +15 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/threadentry_noasm.go +24 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_386.s +130 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_amd64.s +124 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_arm.s +131 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_arm64.s +81 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_386.s +78 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_amd64.s +69 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_arm.s +69 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_arm64.s +60 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_loong64.s +60 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_ppc64le.s +69 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_riscv64.s +60 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_linux_s390x.s +51 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_loong64.s +78 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_ppc64le.s +132 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_riscv64.s +76 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/trampolines_s390x.s +158 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols.go +165 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_darwin.go +59 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_freebsd.go +48 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_linux.go +158 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/zsymbols_netbsd.go +59 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_darwin.s +19 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_freebsd.s +16 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_linux.s +46 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_netbsd.s +19 -0
- package/govendor/github.com/ebitengine/purego/internal/fakecgo/ztrampolines_stubs.s +55 -0
- package/govendor/github.com/ebitengine/purego/internal/strings/strings.go +40 -0
- package/govendor/github.com/ebitengine/purego/is_ios.go +13 -0
- package/govendor/github.com/ebitengine/purego/nocgo.go +25 -0
- package/govendor/github.com/ebitengine/purego/struct_amd64.go +518 -0
- package/govendor/github.com/ebitengine/purego/struct_arm.go +100 -0
- package/govendor/github.com/ebitengine/purego/struct_arm64.go +757 -0
- package/govendor/github.com/ebitengine/purego/struct_loong64.go +244 -0
- package/govendor/github.com/ebitengine/purego/struct_other.go +54 -0
- package/govendor/github.com/ebitengine/purego/struct_ppc64le.go +180 -0
- package/govendor/github.com/ebitengine/purego/struct_riscv64.go +158 -0
- package/govendor/github.com/ebitengine/purego/struct_s390x.go +158 -0
- package/govendor/github.com/ebitengine/purego/sys_386.s +153 -0
- package/govendor/github.com/ebitengine/purego/sys_amd64.s +206 -0
- package/govendor/github.com/ebitengine/purego/sys_arm.s +153 -0
- package/govendor/github.com/ebitengine/purego/sys_arm64.s +133 -0
- package/govendor/github.com/ebitengine/purego/sys_loong64.s +131 -0
- package/govendor/github.com/ebitengine/purego/sys_ppc64le.s +126 -0
- package/govendor/github.com/ebitengine/purego/sys_riscv64.s +135 -0
- package/govendor/github.com/ebitengine/purego/sys_s390x.s +148 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_386.s +234 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_arm.s +99 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_arm64.s +75 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_loong64.s +79 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_ppc64le.s +114 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_riscv64.s +79 -0
- package/govendor/github.com/ebitengine/purego/sys_unix_s390x.s +111 -0
- package/govendor/github.com/ebitengine/purego/syscall.go +95 -0
- package/govendor/github.com/ebitengine/purego/syscall_32bit.go +97 -0
- package/govendor/github.com/ebitengine/purego/syscall_cgo_linux.go +20 -0
- package/govendor/github.com/ebitengine/purego/syscall_notstackargs.go +55 -0
- package/govendor/github.com/ebitengine/purego/syscall_ppc64le.go +73 -0
- package/govendor/github.com/ebitengine/purego/syscall_stackargs_ppc64le.go +38 -0
- package/govendor/github.com/ebitengine/purego/syscall_stackargs_s390x.go +38 -0
- package/govendor/github.com/ebitengine/purego/syscall_unix.go +392 -0
- package/govendor/github.com/ebitengine/purego/syscall_windows.go +54 -0
- package/govendor/github.com/ebitengine/purego/zcallback_386.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_amd64.s +2014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_arm.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_arm64.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_loong64.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_ppc64le.s +4014 -0
- package/govendor/github.com/ebitengine/purego/zcallback_riscv64.s +4051 -0
- package/govendor/github.com/ebitengine/purego/zcallback_s390x.s +4015 -0
- package/govendor/github.com/klauspost/compress/.gitattributes +3 -0
- package/govendor/github.com/klauspost/compress/.goreleaser.yml +132 -0
- package/govendor/github.com/klauspost/compress/AGENTS.md +106 -0
- package/govendor/github.com/klauspost/compress/LICENSE +304 -0
- package/govendor/github.com/klauspost/compress/README.md +766 -0
- package/govendor/github.com/klauspost/compress/SECURITY.md +25 -0
- package/govendor/github.com/klauspost/compress/compressible.go +85 -0
- package/govendor/github.com/klauspost/compress/fse/README.md +79 -0
- package/govendor/github.com/klauspost/compress/fse/bitreader.go +122 -0
- package/govendor/github.com/klauspost/compress/fse/bitwriter.go +167 -0
- package/govendor/github.com/klauspost/compress/fse/bytereader.go +47 -0
- package/govendor/github.com/klauspost/compress/fse/compress.go +685 -0
- package/govendor/github.com/klauspost/compress/fse/decompress.go +383 -0
- package/govendor/github.com/klauspost/compress/fse/fse.go +150 -0
- package/govendor/github.com/klauspost/compress/gen.sh +4 -0
- package/govendor/github.com/klauspost/compress/go.mod +3 -0
- package/govendor/github.com/klauspost/compress/huff0/README.md +89 -0
- package/govendor/github.com/klauspost/compress/huff0/bitreader.go +323 -0
- package/govendor/github.com/klauspost/compress/huff0/bitwriter.go +97 -0
- package/govendor/github.com/klauspost/compress/huff0/build_table.go +168 -0
- package/govendor/github.com/klauspost/compress/huff0/compress.go +747 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress.go +1188 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_amd64.go +128 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_amd64.s +3476 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_arm64.go +72 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_arm64.s +1648 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_asm.go +252 -0
- package/govendor/github.com/klauspost/compress/huff0/decompress_generic.go +278 -0
- package/govendor/github.com/klauspost/compress/huff0/huff0.go +337 -0
- package/govendor/github.com/klauspost/compress/internal/cpuinfo/cpuinfo.go +34 -0
- package/govendor/github.com/klauspost/compress/internal/cpuinfo/cpuinfo_amd64.go +10 -0
- package/govendor/github.com/klauspost/compress/internal/cpuinfo/cpuinfo_amd64.s +34 -0
- package/govendor/github.com/klauspost/compress/internal/le/le.go +5 -0
- package/govendor/github.com/klauspost/compress/internal/le/unsafe_disabled.go +42 -0
- package/govendor/github.com/klauspost/compress/internal/le/unsafe_enabled.go +52 -0
- package/govendor/github.com/klauspost/compress/internal/regmask/regmask.go +50 -0
- package/govendor/github.com/klauspost/compress/internal/regmask/regmask_386.go +39 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/LICENSE +27 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/decode.go +264 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/decode_other.go +113 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/encode.go +291 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/encode_other.go +250 -0
- package/govendor/github.com/klauspost/compress/internal/snapref/snappy.go +98 -0
- package/govendor/github.com/klauspost/compress/s2sx.mod +3 -0
- package/govendor/github.com/klauspost/compress/s2sx.sum +0 -0
- package/govendor/github.com/klauspost/compress/zstd/README.md +487 -0
- package/govendor/github.com/klauspost/compress/zstd/bitreader.go +176 -0
- package/govendor/github.com/klauspost/compress/zstd/bitwriter.go +151 -0
- package/govendor/github.com/klauspost/compress/zstd/blockdec.go +728 -0
- package/govendor/github.com/klauspost/compress/zstd/blockenc.go +923 -0
- package/govendor/github.com/klauspost/compress/zstd/blocktype_string.go +85 -0
- package/govendor/github.com/klauspost/compress/zstd/bytebuf.go +131 -0
- package/govendor/github.com/klauspost/compress/zstd/bytereader.go +82 -0
- package/govendor/github.com/klauspost/compress/zstd/decodeheader.go +261 -0
- package/govendor/github.com/klauspost/compress/zstd/decoder.go +995 -0
- package/govendor/github.com/klauspost/compress/zstd/decoder_options.go +213 -0
- package/govendor/github.com/klauspost/compress/zstd/dict.go +605 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_base.go +200 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_best.go +572 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_better.go +1262 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_dfast.go +1136 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_fast.go +892 -0
- package/govendor/github.com/klauspost/compress/zstd/enc_jobs.go +352 -0
- package/govendor/github.com/klauspost/compress/zstd/encoder.go +881 -0
- package/govendor/github.com/klauspost/compress/zstd/encoder_options.go +422 -0
- package/govendor/github.com/klauspost/compress/zstd/framedec.go +404 -0
- package/govendor/github.com/klauspost/compress/zstd/frameenc.go +137 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder.go +333 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder_amd64.s +132 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder_arm64.s +148 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder_asm.go +70 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_decoder_generic.go +71 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_encoder.go +701 -0
- package/govendor/github.com/klauspost/compress/zstd/fse_predefined.go +168 -0
- package/govendor/github.com/klauspost/compress/zstd/hash.go +57 -0
- package/govendor/github.com/klauspost/compress/zstd/history.go +119 -0
- package/{examples/react-compiler/vendor/jsesc/LICENSE-MIT.txt → govendor/github.com/klauspost/compress/zstd/internal/xxhash/LICENSE.txt} +3 -1
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/README.md +71 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash.go +242 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_amd64.s +210 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_arm64.s +184 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_asm.go +11 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_other.go +75 -0
- package/govendor/github.com/klauspost/compress/zstd/internal/xxhash/xxhash_safe.go +11 -0
- package/govendor/github.com/klauspost/compress/zstd/matchlen_amd64.go +15 -0
- package/govendor/github.com/klauspost/compress/zstd/matchlen_amd64.s +66 -0
- package/govendor/github.com/klauspost/compress/zstd/matchlen_generic.go +37 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec.go +620 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_amd64.go +115 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_amd64.s +4762 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_arm64.go +81 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_arm64.s +2919 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_asm.go +327 -0
- package/govendor/github.com/klauspost/compress/zstd/seqdec_generic.go +258 -0
- package/govendor/github.com/klauspost/compress/zstd/seqenc.go +159 -0
- package/govendor/github.com/klauspost/compress/zstd/simple.go +54 -0
- package/govendor/github.com/klauspost/compress/zstd/snappy.go +447 -0
- package/govendor/github.com/klauspost/compress/zstd/zip.go +141 -0
- package/govendor/github.com/klauspost/compress/zstd/zstd.go +126 -0
- package/govendor/github.com/tetratelabs/wazero/.editorconfig +7 -0
- package/govendor/github.com/tetratelabs/wazero/.gitattributes +2 -0
- package/govendor/github.com/tetratelabs/wazero/.gitmodules +3 -0
- package/govendor/github.com/tetratelabs/wazero/CONTRIBUTING.md +75 -0
- package/govendor/github.com/tetratelabs/wazero/LICENSE +201 -0
- package/govendor/github.com/tetratelabs/wazero/Makefile +385 -0
- package/govendor/github.com/tetratelabs/wazero/NOTICE +2 -0
- package/govendor/github.com/tetratelabs/wazero/RATIONALE.md +1577 -0
- package/govendor/github.com/tetratelabs/wazero/README.md +135 -0
- package/govendor/github.com/tetratelabs/wazero/api/features.go +228 -0
- package/govendor/github.com/tetratelabs/wazero/api/wasm.go +766 -0
- package/govendor/github.com/tetratelabs/wazero/builder.go +367 -0
- package/govendor/github.com/tetratelabs/wazero/cache.go +123 -0
- package/govendor/github.com/tetratelabs/wazero/codecov.yml +9 -0
- package/govendor/github.com/tetratelabs/wazero/config.go +899 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/checkpoint.go +35 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/close.go +63 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/compilationworkers.go +19 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/experimental.go +41 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/features.go +39 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/importresolver.go +19 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/listener.go +324 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/memory.go +52 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/dir.go +92 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/errno.go +98 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/error.go +45 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/file.go +356 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/fs.go +292 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/oflag.go +70 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/poll.go +48 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno.go +106 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno_notwindows.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno_unsupported.go +7 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/syscall_errno_windows.go +37 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/time.go +10 -0
- package/govendor/github.com/tetratelabs/wazero/experimental/sys/unimplemented.go +160 -0
- package/govendor/github.com/tetratelabs/wazero/fsconfig.go +213 -0
- package/govendor/github.com/tetratelabs/wazero/go.mod +3 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/args.go +97 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/clock.go +116 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/environ.go +100 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/fs.go +2015 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/poll.go +247 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/proc.go +44 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/random.go +55 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/sched.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/sock.go +188 -0
- package/govendor/github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1/wasi.go +314 -0
- package/govendor/github.com/tetratelabs/wazero/internal/descriptor/table.go +149 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/compiler.go +3884 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/format.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/interpreter.go +4963 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/operations.go +2978 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/interpreter/signature.go +825 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/abi.go +170 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/backend.go +3 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/compiler.go +402 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/compiler_lower.go +226 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/go_call.go +33 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi.go +186 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_entry_amd64.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_entry_amd64.s +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_entry_preamble.go +248 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/abi_go_call.go +440 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/cond.go +168 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/ext.go +35 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/instr.go +2495 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/instr_encoding.go +1714 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/lower_constant.go +71 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/lower_mem.go +187 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine.go +3782 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine_pro_epi_logue.go +334 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine_regalloc.go +352 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/machine_vec.go +992 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/operands.go +336 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/reg.go +181 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/amd64/stack.go +130 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi.go +376 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_entry_arm64.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_entry_arm64.s +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_entry_preamble.go +233 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/abi_go_call.go +430 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/cond.go +215 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/instr.go +2562 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/instr_encoding.go +2357 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_constant.go +301 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_instr.go +2227 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_instr_operands.go +340 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/lower_mem.go +451 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine.go +631 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine_pro_epi_logue.go +486 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine_regalloc.go +351 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/machine_relocation.go +128 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/reg.go +397 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/isa/arm64/unwind_stack.go +84 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/machine.go +119 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/api.go +124 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/reg.go +123 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/regalloc.go +1189 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/regalloc/regset.go +96 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/backend/vdef.go +19 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/call_engine.go +884 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine.go +1008 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/engine_cache.go +347 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/entrypoint_amd64.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/entrypoint_arm64.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/entrypoint_other.go +15 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/frontend.go +663 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/lower.go +5045 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/misc.go +10 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/frontend/sort_id.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/hostmodule.go +88 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/isa_amd64.go +30 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/isa_arm64.go +32 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/isa_other.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/memmove.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/module_engine.go +403 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/basic_block.go +381 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/basic_block_sort.go +32 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/builder.go +790 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/cmp.go +107 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/funcref.go +12 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/instructions.go +3024 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/pass.go +393 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/pass_blk_layouts.go +334 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/pass_cfg.go +313 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/signature.go +49 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/ssa.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/type.go +115 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/ssa/vs.go +114 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/debug_options.go +189 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/exitcode.go +150 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/offsetdata.go +248 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/perfmap.go +96 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/perfmap_disabled.go +5 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/perfmap_enabled.go +5 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/pool.go +215 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/ptr.go +15 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/queue.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/engine/wazevo/wazevoapi/resetmap.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/checkpoint.go +10 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/close.go +5 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/compilationworkers.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/expctxkeys.go +2 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/importresolver.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/listener.go +7 -0
- package/govendor/github.com/tetratelabs/wazero/internal/expctxkeys/memory.go +4 -0
- package/govendor/github.com/tetratelabs/wazero/internal/filecache/compilationcache.go +42 -0
- package/govendor/github.com/tetratelabs/wazero/internal/filecache/file_cache.go +76 -0
- package/govendor/github.com/tetratelabs/wazero/internal/ieee754/ieee754.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/internalapi/internal.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/leb128/leb128.go +285 -0
- package/govendor/github.com/tetratelabs/wazero/internal/moremath/moremath.go +271 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid_amd64.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid_arm64.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/cpuid_unsupported.go +5 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/crypto.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_linux.go +72 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_other.go +19 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_unix.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_unsupported.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/mmap_windows.go +31 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/path.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/path_windows.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/platform.go +71 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/time.go +76 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/time_notwindows.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/platform/time_windows.go +40 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sock/sock.go +89 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sock/sock_supported.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sock/sock_unsupported.go +10 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sys/fs.go +458 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sys/lazy.go +135 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sys/stdio.go +125 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sys/sys.go +228 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/adapter.go +105 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/datasync_linux.go +12 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/datasync_unsupported.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/dir.go +24 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/dirfs.go +137 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file.go +576 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file_unix.go +39 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file_unsupported.go +28 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/file_windows.go +133 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_darwin.go +42 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_darwin.s +8 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_linux.go +38 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_unsupported.go +18 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/futimens_windows.go +42 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/ino_unix.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/ino_unsupported.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/ino_windows.go +28 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/nonblock_unix.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/nonblock_unsupported.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/nonblock_windows.go +23 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/oflag.go +38 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_bsd.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_darwin.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_supported.go +30 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_unix.go +20 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_unsupported.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/open_file_windows.go +163 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/osfile.go +318 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_darwin.go +55 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_darwin.s +8 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_linux.go +57 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_unsupported.go +12 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/poll_windows.go +224 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/readfs.go +117 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/rename_unix.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/rename_unsupported.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/rename_windows.go +55 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock.go +186 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_supported.go +76 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_unix.go +48 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_unsupported.go +79 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sock_windows.go +80 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat_supported.go +40 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat_unsupported.go +40 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/stat_windows.go +118 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sync.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sync_windows.go +20 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/syscall6_darwin.go +13 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/sysfs.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/unlink_unix.go +17 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/unlink_unsupported.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/internal/sysfs/unlink_windows.go +25 -0
- package/govendor/github.com/tetratelabs/wazero/internal/u32/u32.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/u64/u64.go +15 -0
- package/govendor/github.com/tetratelabs/wazero/internal/version/version.go +52 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/args.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/clock.go +16 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/environ.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/errno.go +314 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/fs.go +164 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/poll.go +15 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/proc.go +6 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/random.go +3 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/rights.go +148 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/sched.go +3 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/sock.go +71 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasip1/wasi.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/code.go +124 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/const_expr.go +116 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/custom.go +22 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/data.go +79 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/decoder.go +235 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/element.go +250 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/errors.go +11 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/export.go +32 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/function.go +56 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/global.go +50 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/header.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/import.go +68 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/limits.go +47 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/memory.go +42 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/names.go +151 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/section.go +309 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/table.go +79 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/binary/value.go +97 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/const_expr.go +259 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/counts.go +53 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/engine.go +76 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/exception.go +9 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/func_validation.go +2804 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/function_definition.go +210 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/global.go +55 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/gofunc.go +279 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/host.go +179 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/instruction.go +1962 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/memory.go +475 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/memory_definition.go +128 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/module.go +1359 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/module_instance.go +251 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/module_instance_lookup.go +73 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/store.go +726 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/store_module_list.go +95 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasm/table.go +321 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasmdebug/debug.go +170 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasmdebug/dwarf.go +225 -0
- package/govendor/github.com/tetratelabs/wazero/internal/wasmruntime/errors.go +54 -0
- package/govendor/github.com/tetratelabs/wazero/netlify.toml +15 -0
- package/govendor/github.com/tetratelabs/wazero/runtime.go +399 -0
- package/govendor/github.com/tetratelabs/wazero/sys/clock.go +26 -0
- package/govendor/github.com/tetratelabs/wazero/sys/error.go +83 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat.go +105 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat_bsd.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat_posix.go +29 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat_unsupported.go +14 -0
- package/govendor/github.com/tetratelabs/wazero/sys/stat_windows.go +24 -0
- package/govendor/golang.org/x/crypto/LICENSE +27 -0
- package/govendor/golang.org/x/crypto/PATENTS +22 -0
- package/govendor/golang.org/x/crypto/cryptobyte/asn1/asn1.go +46 -0
- package/govendor/golang.org/x/crypto/cryptobyte/asn1.go +825 -0
- package/govendor/golang.org/x/crypto/cryptobyte/builder.go +350 -0
- package/govendor/golang.org/x/crypto/cryptobyte/string.go +183 -0
- package/govendor/golang.org/x/crypto/go.mod +3 -0
- package/govendor/golang.org/x/crypto/pbkdf2/pbkdf2.go +30 -0
- package/govendor/golang.org/x/net/LICENSE +27 -0
- package/govendor/golang.org/x/net/PATENTS +22 -0
- package/govendor/golang.org/x/net/dns/dnsmessage/message.go +2733 -0
- package/govendor/golang.org/x/net/dns/dnsmessage/svcb.go +333 -0
- package/govendor/golang.org/x/net/go.mod +3 -0
- package/govendor/golang.org/x/net/http/httpguts/guts.go +50 -0
- package/govendor/golang.org/x/net/http/httpguts/httplex.go +347 -0
- package/govendor/golang.org/x/net/http2/README.md +19 -0
- package/govendor/golang.org/x/net/http2/ascii.go +65 -0
- package/govendor/golang.org/x/net/http2/ciphers.go +641 -0
- package/govendor/golang.org/x/net/http2/client_conn_pool.go +301 -0
- package/govendor/golang.org/x/net/http2/client_priority_go126.go +20 -0
- package/govendor/golang.org/x/net/http2/client_priority_go127.go +13 -0
- package/govendor/golang.org/x/net/http2/clientconn.go +57 -0
- package/govendor/golang.org/x/net/http2/config.go +171 -0
- package/govendor/golang.org/x/net/http2/config_go125.go +15 -0
- package/govendor/golang.org/x/net/http2/config_go126.go +15 -0
- package/govendor/golang.org/x/net/http2/databuffer.go +146 -0
- package/govendor/golang.org/x/net/http2/errors.go +145 -0
- package/govendor/golang.org/x/net/http2/flow.go +175 -0
- package/govendor/golang.org/x/net/http2/frame.go +1887 -0
- package/govendor/golang.org/x/net/http2/gotrack.go +181 -0
- package/govendor/golang.org/x/net/http2/hpack/encode.go +244 -0
- package/govendor/golang.org/x/net/http2/hpack/hpack.go +522 -0
- package/govendor/golang.org/x/net/http2/hpack/huffman.go +226 -0
- package/govendor/golang.org/x/net/http2/hpack/static_table.go +188 -0
- package/govendor/golang.org/x/net/http2/hpack/tables.go +426 -0
- package/govendor/golang.org/x/net/http2/http2.go +415 -0
- package/govendor/golang.org/x/net/http2/pipe.go +184 -0
- package/govendor/golang.org/x/net/http2/server.go +3239 -0
- package/govendor/golang.org/x/net/http2/server_common.go +268 -0
- package/govendor/golang.org/x/net/http2/server_wrap.go +217 -0
- package/govendor/golang.org/x/net/http2/transport.go +3084 -0
- package/govendor/golang.org/x/net/http2/transport_common.go +516 -0
- package/govendor/golang.org/x/net/http2/transport_wrap.go +583 -0
- package/govendor/golang.org/x/net/http2/unencrypted.go +32 -0
- package/govendor/golang.org/x/net/http2/write.go +381 -0
- package/govendor/golang.org/x/net/http2/writesched.go +253 -0
- package/govendor/golang.org/x/net/http2/writesched_common.go +90 -0
- package/govendor/golang.org/x/net/http2/writesched_priority_rfc7540.go +420 -0
- package/govendor/golang.org/x/net/http2/writesched_priority_rfc9218.go +226 -0
- package/govendor/golang.org/x/net/http2/writesched_random.go +81 -0
- package/govendor/golang.org/x/net/http2/writesched_roundrobin.go +121 -0
- package/govendor/golang.org/x/net/idna/idna.go +884 -0
- package/govendor/golang.org/x/net/idna/punycode.go +220 -0
- package/govendor/golang.org/x/net/idna/tables15.0.0.go +5144 -0
- package/govendor/golang.org/x/net/idna/tables17.0.0.go +5302 -0
- package/govendor/golang.org/x/net/idna/trie.go +51 -0
- package/govendor/golang.org/x/net/idna/trieval.go +119 -0
- package/govendor/golang.org/x/net/internal/httpcommon/README.md +7 -0
- package/govendor/golang.org/x/net/internal/httpcommon/ascii.go +53 -0
- package/govendor/golang.org/x/net/internal/httpcommon/gzip.go +132 -0
- package/govendor/golang.org/x/net/internal/httpcommon/headermap.go +115 -0
- package/govendor/golang.org/x/net/internal/httpcommon/request.go +503 -0
- package/govendor/golang.org/x/net/internal/httpsfv/httpsfv.go +665 -0
- package/govendor/golang.org/x/sys/cpu/asm_aix_ppc64.s +17 -0
- package/govendor/golang.org/x/sys/cpu/asm_darwin_arm64_gc.s +12 -0
- package/govendor/golang.org/x/sys/cpu/asm_darwin_x86_gc.s +17 -0
- package/govendor/golang.org/x/sys/cpu/byteorder.go +66 -0
- package/govendor/golang.org/x/sys/cpu/cpu.go +357 -0
- package/govendor/golang.org/x/sys/cpu/cpu_aix.go +33 -0
- package/govendor/golang.org/x/sys/cpu/cpu_arm.go +73 -0
- package/govendor/golang.org/x/sys/cpu/cpu_arm64.go +191 -0
- package/govendor/golang.org/x/sys/cpu/cpu_arm64.s +35 -0
- package/govendor/golang.org/x/sys/cpu/cpu_darwin_arm64.go +67 -0
- package/govendor/golang.org/x/sys/cpu/cpu_darwin_arm64_other.go +31 -0
- package/govendor/golang.org/x/sys/cpu/cpu_darwin_x86.go +61 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_arm64.go +12 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_riscv64.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_s390x.go +21 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_x86.go +15 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gc_x86.s +26 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gccgo_arm64.go +12 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gccgo_s390x.go +22 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c +37 -0
- package/govendor/golang.org/x/sys/cpu/cpu_gccgo_x86.go +25 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux.go +15 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_arm.go +39 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_arm64.go +120 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_loong64.go +22 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_mips64x.go +22 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_noinit.go +9 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_ppc64x.go +34 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_riscv64.go +173 -0
- package/govendor/golang.org/x/sys/cpu/cpu_linux_s390x.go +40 -0
- package/govendor/golang.org/x/sys/cpu/cpu_loong64.go +62 -0
- package/govendor/golang.org/x/sys/cpu/cpu_loong64.s +13 -0
- package/govendor/golang.org/x/sys/cpu/cpu_mips64x.go +15 -0
- package/govendor/golang.org/x/sys/cpu/cpu_mipsx.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_netbsd_amd64.go +47 -0
- package/govendor/golang.org/x/sys/cpu/cpu_netbsd_arm64.go +173 -0
- package/govendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.go +65 -0
- package/govendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.s +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_arm.go +9 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_arm64.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_mips64x.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_ppc64x.go +12 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_riscv64.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_other_x86.go +11 -0
- package/govendor/golang.org/x/sys/cpu/cpu_ppc64x.go +16 -0
- package/govendor/golang.org/x/sys/cpu/cpu_riscv64.go +33 -0
- package/govendor/golang.org/x/sys/cpu/cpu_riscv64.s +17 -0
- package/govendor/golang.org/x/sys/cpu/cpu_s390x.go +172 -0
- package/govendor/golang.org/x/sys/cpu/cpu_s390x.s +57 -0
- package/govendor/golang.org/x/sys/cpu/cpu_sparc64.go +12 -0
- package/govendor/golang.org/x/sys/cpu/cpu_wasm.go +17 -0
- package/govendor/golang.org/x/sys/cpu/cpu_windows.go +26 -0
- package/govendor/golang.org/x/sys/cpu/cpu_windows_arm64.go +38 -0
- package/govendor/golang.org/x/sys/cpu/cpu_x86.go +259 -0
- package/govendor/golang.org/x/sys/cpu/cpu_zos.go +10 -0
- package/govendor/golang.org/x/sys/cpu/cpu_zos_s390x.go +25 -0
- package/govendor/golang.org/x/sys/cpu/endian_big.go +10 -0
- package/govendor/golang.org/x/sys/cpu/endian_little.go +10 -0
- package/govendor/golang.org/x/sys/cpu/hwcap_linux.go +71 -0
- package/govendor/golang.org/x/sys/cpu/parse.go +55 -0
- package/govendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.go +53 -0
- package/govendor/golang.org/x/sys/cpu/runtime_auxv.go +16 -0
- package/govendor/golang.org/x/sys/cpu/runtime_auxv_go121.go +18 -0
- package/govendor/golang.org/x/sys/cpu/syscall_aix_gccgo.go +26 -0
- package/govendor/golang.org/x/sys/cpu/syscall_aix_ppc64_gc.go +35 -0
- package/govendor/golang.org/x/sys/cpu/syscall_darwin_arm64_gc.go +54 -0
- package/govendor/golang.org/x/sys/cpu/syscall_darwin_x86_gc.go +98 -0
- package/govendor/golang.org/x/sys/cpu/zcpu_windows.go +48 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_ppc64x.s +20 -0
- package/govendor/golang.org/x/sys/unix/asm_linux_sparc64.s +48 -0
- package/govendor/golang.org/x/sys/unix/asm_zos_s390x.s +4 -186
- package/govendor/golang.org/x/sys/unix/bpxsvc_zos.s +9 -9
- package/govendor/golang.org/x/sys/unix/fcntl_darwin.go +2 -2
- package/govendor/golang.org/x/sys/unix/mkerrors.sh +1 -1
- package/govendor/golang.org/x/sys/unix/ptrace_zos.go +537 -0
- package/govendor/golang.org/x/sys/unix/ptrace_zos_singlestep.go +425 -0
- package/govendor/golang.org/x/sys/unix/syscall_darwin.go +1 -0
- package/govendor/golang.org/x/sys/unix/syscall_freebsd.go +9 -0
- package/govendor/golang.org/x/sys/unix/syscall_linux.go +20 -1
- package/govendor/golang.org/x/sys/unix/syscall_linux_sparc64.go +3 -3
- package/govendor/golang.org/x/sys/unix/syscall_netbsd.go +9 -0
- package/govendor/golang.org/x/sys/unix/syscall_unix_gc.go +1 -1
- package/govendor/golang.org/x/sys/unix/syscall_zos_s390x.go +0 -4
- package/govendor/golang.org/x/sys/unix/xattr_bsd.go +12 -12
- package/govendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go +6 -0
- package/govendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go +6 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux.go +32 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_386.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_arm.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mips.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +2 -0
- package/govendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +2 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +11 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +11 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_riscv64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_linux.go +28 -1
- package/govendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +3 -3
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go +159 -0
- package/govendor/golang.org/x/sys/unix/zsysnum_zos_s390x.go +13 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux.go +65 -36
- package/govendor/golang.org/x/sys/unix/ztypes_linux_386.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_arm.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_loong64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mips.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc.go +6 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +7 -0
- package/govendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go +10 -5
- package/govendor/golang.org/x/sys/unix/ztypes_zos_s390x.go +78 -0
- package/govendor/golang.org/x/text/.gitattributes +10 -0
- package/govendor/golang.org/x/text/CONTRIBUTING.md +26 -0
- package/govendor/golang.org/x/text/LICENSE +27 -0
- package/govendor/golang.org/x/text/PATENTS +22 -0
- package/govendor/golang.org/x/text/README.md +81 -0
- package/govendor/golang.org/x/text/cases/cases.go +162 -0
- package/govendor/golang.org/x/text/cases/context.go +376 -0
- package/govendor/golang.org/x/text/cases/fold.go +34 -0
- package/govendor/golang.org/x/text/cases/icu.go +61 -0
- package/govendor/golang.org/x/text/cases/info.go +82 -0
- package/govendor/golang.org/x/text/cases/map.go +816 -0
- package/govendor/golang.org/x/text/cases/tables15.0.0.go +2527 -0
- package/govendor/golang.org/x/text/cases/tables17.0.0.go +2642 -0
- package/govendor/golang.org/x/text/cases/trieval.go +217 -0
- package/govendor/golang.org/x/text/codereview.cfg +1 -0
- package/govendor/golang.org/x/text/collate/collate.go +402 -0
- package/govendor/golang.org/x/text/collate/index.go +32 -0
- package/govendor/golang.org/x/text/collate/option.go +239 -0
- package/govendor/golang.org/x/text/collate/sort.go +81 -0
- package/govendor/golang.org/x/text/collate/tables.go +73789 -0
- package/govendor/golang.org/x/text/currency/common.go +67 -0
- package/govendor/golang.org/x/text/currency/currency.go +185 -0
- package/govendor/golang.org/x/text/currency/format.go +220 -0
- package/govendor/golang.org/x/text/currency/query.go +152 -0
- package/govendor/golang.org/x/text/currency/tables.go +2629 -0
- package/govendor/golang.org/x/text/doc.go +16 -0
- package/govendor/golang.org/x/text/feature/plural/common.go +70 -0
- package/govendor/golang.org/x/text/feature/plural/message.go +244 -0
- package/govendor/golang.org/x/text/feature/plural/plural.go +262 -0
- package/govendor/golang.org/x/text/feature/plural/tables.go +552 -0
- package/govendor/golang.org/x/text/go.mod +3 -0
- package/govendor/golang.org/x/text/internal/catmsg/catmsg.go +417 -0
- package/govendor/golang.org/x/text/internal/catmsg/codec.go +407 -0
- package/govendor/golang.org/x/text/internal/catmsg/varint.go +62 -0
- package/govendor/golang.org/x/text/internal/colltab/collelem.go +374 -0
- package/govendor/golang.org/x/text/internal/colltab/colltab.go +105 -0
- package/govendor/golang.org/x/text/internal/colltab/contract.go +145 -0
- package/govendor/golang.org/x/text/internal/colltab/iter.go +178 -0
- package/govendor/golang.org/x/text/internal/colltab/numeric.go +236 -0
- package/govendor/golang.org/x/text/internal/colltab/table.go +275 -0
- package/govendor/golang.org/x/text/internal/colltab/trie.go +159 -0
- package/govendor/golang.org/x/text/internal/colltab/weighter.go +31 -0
- package/govendor/golang.org/x/text/internal/format/format.go +41 -0
- package/govendor/golang.org/x/text/internal/format/parser.go +358 -0
- package/govendor/golang.org/x/text/internal/internal.go +49 -0
- package/govendor/golang.org/x/text/internal/language/common.go +16 -0
- package/govendor/golang.org/x/text/internal/language/compact/compact.go +61 -0
- package/govendor/golang.org/x/text/internal/language/compact/language.go +260 -0
- package/govendor/golang.org/x/text/internal/language/compact/parents.go +120 -0
- package/govendor/golang.org/x/text/internal/language/compact/tables.go +1015 -0
- package/govendor/golang.org/x/text/internal/language/compact/tags.go +91 -0
- package/govendor/golang.org/x/text/internal/language/compact.go +29 -0
- package/govendor/golang.org/x/text/internal/language/compose.go +167 -0
- package/govendor/golang.org/x/text/internal/language/coverage.go +28 -0
- package/govendor/golang.org/x/text/internal/language/language.go +627 -0
- package/govendor/golang.org/x/text/internal/language/lookup.go +412 -0
- package/govendor/golang.org/x/text/internal/language/match.go +226 -0
- package/govendor/golang.org/x/text/internal/language/parse.go +608 -0
- package/govendor/golang.org/x/text/internal/language/tables.go +3494 -0
- package/govendor/golang.org/x/text/internal/language/tags.go +48 -0
- package/govendor/golang.org/x/text/internal/match.go +67 -0
- package/govendor/golang.org/x/text/internal/number/common.go +55 -0
- package/govendor/golang.org/x/text/internal/number/decimal.go +500 -0
- package/govendor/golang.org/x/text/internal/number/format.go +533 -0
- package/govendor/golang.org/x/text/internal/number/number.go +152 -0
- package/govendor/golang.org/x/text/internal/number/pattern.go +485 -0
- package/govendor/golang.org/x/text/internal/number/roundingmode_string.go +30 -0
- package/govendor/golang.org/x/text/internal/number/tables.go +1219 -0
- package/govendor/golang.org/x/text/internal/stringset/set.go +86 -0
- package/govendor/golang.org/x/text/internal/tag/tag.go +100 -0
- package/govendor/golang.org/x/text/language/coverage.go +187 -0
- package/govendor/golang.org/x/text/language/display/dict.go +92 -0
- package/govendor/golang.org/x/text/language/display/display.go +420 -0
- package/govendor/golang.org/x/text/language/display/lookup.go +253 -0
- package/govendor/golang.org/x/text/language/display/tables.go +53114 -0
- package/govendor/golang.org/x/text/language/doc.go +98 -0
- package/govendor/golang.org/x/text/language/language.go +605 -0
- package/govendor/golang.org/x/text/language/match.go +735 -0
- package/govendor/golang.org/x/text/language/parse.go +258 -0
- package/govendor/golang.org/x/text/language/tables.go +298 -0
- package/govendor/golang.org/x/text/language/tags.go +145 -0
- package/govendor/golang.org/x/text/message/catalog/catalog.go +365 -0
- package/govendor/golang.org/x/text/message/catalog/dict.go +133 -0
- package/govendor/golang.org/x/text/secure/bidirule/bidirule.go +346 -0
- package/govendor/golang.org/x/text/transform/transform.go +709 -0
- package/govendor/golang.org/x/text/unicode/bidi/bidi.go +359 -0
- package/govendor/golang.org/x/text/unicode/bidi/bracket.go +335 -0
- package/govendor/golang.org/x/text/unicode/bidi/core.go +1050 -0
- package/govendor/golang.org/x/text/unicode/bidi/prop.go +206 -0
- package/govendor/golang.org/x/text/unicode/bidi/tables15.0.0.go +2042 -0
- package/govendor/golang.org/x/text/unicode/bidi/tables17.0.0.go +2135 -0
- package/govendor/golang.org/x/text/unicode/bidi/trieval.go +48 -0
- package/govendor/golang.org/x/text/unicode/norm/composition.go +524 -0
- package/govendor/golang.org/x/text/unicode/norm/forminfo.go +296 -0
- package/govendor/golang.org/x/text/unicode/norm/input.go +109 -0
- package/govendor/golang.org/x/text/unicode/norm/iter.go +454 -0
- package/govendor/golang.org/x/text/unicode/norm/normalize.go +613 -0
- package/govendor/golang.org/x/text/unicode/norm/readwriter.go +125 -0
- package/govendor/golang.org/x/text/unicode/norm/tables15.0.0.go +7907 -0
- package/govendor/golang.org/x/text/unicode/norm/tables17.0.0.go +8104 -0
- package/govendor/golang.org/x/text/unicode/norm/transform.go +89 -0
- package/govendor/golang.org/x/text/unicode/norm/trie.go +54 -0
- package/govendor/manifest.txt +11 -2
- package/govendor/software.sslmate.com/src/go-pkcs12/.gitattributes +10 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/LICENSE +28 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/README.md +31 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/bmp-string.go +63 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/crypto.go +331 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/errors.go +23 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/go.mod +3 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/internal/rc2/rc2.go +271 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/mac.go +202 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pbkdf.go +184 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/pkcs12.go +1000 -0
- package/govendor/software.sslmate.com/src/go-pkcs12/safebags.go +107 -0
- package/package.json +11 -1
- package/types/tsconfig.json +17 -0
- package/types/typenative-npm.d.ts +1327 -80
- package/types/typenative.d.ts +1312 -25
- package/.gitattributes +0 -1
- package/.github/workflows/ci.yml +0 -68
- package/.github/workflows/npm-publish-github-packages.yml +0 -88
- package/CHANGELOG.md +0 -1358
- package/CONTRIBUTION.md +0 -133
- package/conformance.md +0 -1450
- package/examples/README.md +0 -113
- package/examples/angular-templates/README.md +0 -141
- package/examples/angular-templates/bench.mjs +0 -173
- package/examples/angular-templates/dom-type-globals.d.ts +0 -21
- package/examples/angular-templates/dom-type-stubs.ts +0 -21
- package/examples/angular-templates/main.ts +0 -135
- package/examples/angular-templates/parity.mjs +0 -157
- package/examples/angular-templates/run-node.mjs +0 -69
- package/examples/angular-templates/vendor/angular/compiler/LICENSE +0 -21
- package/examples/desktop-notes/README.md +0 -106
- package/examples/desktop-notes/bench.mjs +0 -125
- package/examples/desktop-notes/main.ts +0 -131
- package/examples/desktop-notes/package-lock.json +0 -726
- package/examples/desktop-notes/package.json +0 -9
- package/examples/desktop-notes/ui.ts +0 -176
- package/examples/dupe-finder/README.md +0 -78
- package/examples/dupe-finder/bench.mjs +0 -120
- package/examples/dupe-finder/main.ts +0 -87
- package/examples/fibonacci/README.md +0 -89
- package/examples/fibonacci/bench.mjs +0 -87
- package/examples/fibonacci/main.ts +0 -21
- package/examples/hello-world/README.md +0 -62
- package/examples/hello-world/bench.mjs +0 -66
- package/examples/hello-world/main.ts +0 -7
- package/examples/json-server/README.md +0 -131
- package/examples/json-server/bench.mjs +0 -263
- package/examples/json-server/main.ts +0 -67
- package/examples/mandelbrot-png/README.md +0 -63
- package/examples/mandelbrot-png/bench.mjs +0 -95
- package/examples/mandelbrot-png/main.ts +0 -98
- package/examples/mandelbrot-png/preview.png +0 -0
- package/examples/marked-cli/README.md +0 -175
- package/examples/marked-cli/bench.mjs +0 -178
- package/examples/marked-cli/main.ts +0 -410
- package/examples/marked-cli/parity.mjs +0 -185
- package/examples/marked-cli/vendor/marked/LICENSE +0 -44
- package/examples/marked-cli/vendor/marked/VENDOR.md +0 -26
- package/examples/openai-chat/README.md +0 -148
- package/examples/openai-chat/bench.mjs +0 -175
- package/examples/openai-chat/main.ts +0 -488
- package/examples/react-compiler/README.md +0 -185
- package/examples/react-compiler/bench.mjs +0 -181
- package/examples/react-compiler/main.ts +0 -324
- package/examples/react-compiler/parity.mjs +0 -362
- package/examples/react-compiler/run-node.mjs +0 -90
- package/examples/react-compiler/vendor/babel/LICENSE +0 -22
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-lower.json +0 -15
- package/examples/react-compiler/vendor/babel/helper-globals/data/builtin-upper.json +0 -51
- package/examples/react-compiler/vendor/charcodes/package.json +0 -25
- package/examples/react-compiler/vendor/invariant/LICENSE +0 -21
- package/examples/react-compiler/vendor/invariant/invariant.cjs +0 -51
- package/examples/react-compiler/vendor/invariant/invariant.d.cts +0 -11
- package/examples/react-compiler/vendor/invariant/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/jridgewell/gen-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/resolve-uri/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/sourcemap-codec/LICENSE +0 -19
- package/examples/react-compiler/vendor/jridgewell/trace-mapping/LICENSE +0 -19
- package/examples/react-compiler/vendor/js-tokens/LICENSE +0 -21
- package/examples/react-compiler/vendor/js-tokens/index.cjs +0 -23
- package/examples/react-compiler/vendor/js-tokens/index.d.cts +0 -13
- package/examples/react-compiler/vendor/jsesc/jsesc.cjs +0 -337
- package/examples/react-compiler/vendor/jsesc/jsesc.d.cts +0 -384
- package/examples/react-compiler/vendor/jsesc/types/LICENSE +0 -21
- package/examples/react-compiler/vendor/picocolors/picocolors.cjs +0 -75
- package/examples/react-compiler/vendor/picocolors/picocolors.d.cts +0 -5
- package/examples/react-compiler/vendor/picocolors/types.d.ts +0 -51
- package/examples/react-compiler/vendor/react-compiler/LICENSE +0 -21
- package/examples/react-compiler/vendor/stubs/babel-core.ts +0 -31
- package/examples/react-compiler/vendor/stubs/debug.ts +0 -18
- package/examples/react-compiler/vendor/stubs/js-tokens.d.ts +0 -13
- package/examples/react-compiler/vendor/stubs/pretty-format.ts +0 -18
- package/examples/react-compiler/vendor/zod/LICENSE +0 -21
- package/examples/react-compiler/vendor/zod-validation-error/LICENSE +0 -9
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/NonEmptyArray.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinPath.ts +0 -49
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/joinValues.ts +0 -48
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/stringify.ts +0 -50
- package/examples/react-compiler/vendor/zod-validation-error/lib/utils/titleCase.ts +0 -6
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/MessageBuilder.ts +0 -126
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/ValidationError.ts +0 -39
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/custom.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/errorMap.ts +0 -78
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/index.ts +0 -2
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidElement.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidKey.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidStringFormat.ts +0 -131
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidType.ts +0 -54
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidUnion.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/invalidValue.ts +0 -40
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/notMultipleOf.ts +0 -12
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooBig.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/tooSmall.ts +0 -76
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/types.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/errorMap/unrecognizedKeys.ts +0 -27
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromError.ts +0 -13
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodError.ts +0 -61
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/fromZodIssue.ts +0 -38
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/index.ts +0 -20
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationError.ts +0 -5
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isValidationErrorLike.ts +0 -8
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/isZodErrorLike.ts +0 -11
- package/examples/react-compiler/vendor/zod-validation-error/lib/v4/toValidationError.ts +0 -20
- package/examples/react-compiler/vendor.mjs +0 -688
- package/examples/todo-cli/README.md +0 -69
- package/examples/todo-cli/bench.mjs +0 -89
- package/examples/todo-cli/main.ts +0 -92
- package/examples/yaml-cli/README.md +0 -152
- package/examples/yaml-cli/bench.mjs +0 -265
- package/examples/yaml-cli/main.ts +0 -251
- package/examples/yaml-cli/parity.mjs +0 -156
- package/examples/yaml-cli/vendor/yaml/LICENSE +0 -13
- package/examples/yaml-cli/vendor/yaml/VENDOR.md +0 -25
- package/govendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go +0 -22
- package/govendor/golang.org/x/sys/windows/types_windows_arm.go +0 -35
- package/performance/README.md +0 -196
- package/performance/any-dynamic.ts +0 -21
- package/performance/any-record-view.ts +0 -20
- package/performance/arr-hof.ts +0 -21
- package/performance/arr-push-index.ts +0 -15
- package/performance/arr-sort.ts +0 -21
- package/performance/async-await.ts +0 -24
- package/performance/class-dispatch.ts +0 -52
- package/performance/events-emit.ts +0 -27
- package/performance/exc-throw-rare.ts +0 -25
- package/performance/exc-try-catch.ts +0 -26
- package/performance/fn-closures.ts +0 -29
- package/performance/fn-recursion-tree.ts +0 -31
- package/performance/gen-for-of.ts +0 -46
- package/performance/json-roundtrip.ts +0 -27
- package/performance/map-delete.ts +0 -24
- package/performance/map-string-keys.ts +0 -22
- package/performance/num-arith-loop.ts +0 -14
- package/performance/num-bitwise.ts +0 -21
- package/performance/num-mod-int.ts +0 -16
- package/performance/num-to-string.ts +0 -16
- package/performance/obj-alloc.ts +0 -32
- package/performance/regex-exec.ts +0 -29
- package/performance/regex-site.ts +0 -28
- package/performance/set-ops.ts +0 -20
- package/performance/str-char-scan.ts +0 -35
- package/performance/str-concat-plus.ts +0 -18
- package/performance/str-concat.ts +0 -24
- package/performance/str-short-scan.ts +0 -26
- package/performance/str-split-join.ts +0 -23
- package/performance/str-template.ts +0 -16
- package/performance/union-switch.ts +0 -57
- package/tsparser/check.go +0 -158
- package/tsparser/go.mod +0 -14
- package/tsparser/go.sum +0 -22
- package/tsparser/main.go +0 -363
- package/tsparser/tsparser.exe +0 -4
package/bin/node/intl.js
ADDED
|
@@ -0,0 +1,4576 @@
|
|
|
1
|
+
// The Intl global (JS API): NumberFormat, DateTimeFormat, Collator,
|
|
2
|
+
// PluralRules, ListFormat, RelativeTimeFormat, Segmenter, DisplayNames and
|
|
3
|
+
// Locale, plus getCanonicalLocales and supportedValuesOf. The patterns,
|
|
4
|
+
// symbols and names come from intl_data.ts, captured from Node's own ICU, so
|
|
5
|
+
// the output matches Node; language tags and matching, plural rules,
|
|
6
|
+
// collation and locale case mapping run on the vendored golang.org/x/text.
|
|
7
|
+
// Registered beside registerWebAssembly in src/transpiler.ts.
|
|
8
|
+
import { defineClass, defineHelper, setResults } from './registry.js';
|
|
9
|
+
import { intlCoreData, intlNumberData, intlDateData, intlListRelData, intlDisplayData } from './intl_data.js';
|
|
10
|
+
import { registerTemporalZones } from './temporal_zones.js';
|
|
11
|
+
// Result types of a class's members: instance methods (looked up as
|
|
12
|
+
// 'Intl.X#name') and statics ('Intl.X.name') share one spec
|
|
13
|
+
function setIntlResults(r, key, spec) {
|
|
14
|
+
setResults(r, key, spec);
|
|
15
|
+
const parts = spec.split(';');
|
|
16
|
+
for (let i = 0; i < parts.length; i++) {
|
|
17
|
+
const part = parts[i].trim();
|
|
18
|
+
if (part === '')
|
|
19
|
+
continue;
|
|
20
|
+
const eq = part.indexOf('=');
|
|
21
|
+
const name = eq < 0 ? part : part.substring(0, eq).trim();
|
|
22
|
+
const type = eq < 0 ? '' : part.substring(eq + 1).trim();
|
|
23
|
+
r.results[key + '#' + name] = type;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const intlCoreGo = `// Intl: option reading, locale resolution and shared plumbing. The locale
|
|
27
|
+
// data lives in the generated maps (intl_data.ts, captured from Node's ICU).
|
|
28
|
+
|
|
29
|
+
// A pattern token (see intl_data.ts): kind, width, range source and literal
|
|
30
|
+
// text. Date fields: 'y' year, 'M' month, 'd' day, 'w' weekday, 'h'/'1' the
|
|
31
|
+
// 12-hour cycles (h12/h11), 'H' 24-hour, 'm' minute, 's' second, 'p' flexible
|
|
32
|
+
// day period, 'P' the AM/PM marker, 'e' era, 'z' zone, 'f' fractional
|
|
33
|
+
// seconds. Number tokens: 'N' the number, 'M' minus sign, 'P' plus sign, 'C'
|
|
34
|
+
// currency symbol, 'U' unit, 'K' compact marker, 'p' percent sign, 'E'
|
|
35
|
+
// exponent separator, 'X' exponent minus sign, 'x' exponent digits.
|
|
36
|
+
type tnIntlPart struct {
|
|
37
|
+
kind byte
|
|
38
|
+
width byte
|
|
39
|
+
src byte
|
|
40
|
+
text string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
func tnIntlRangeError(msg string) { panic(TnNodeError("RangeError", "", msg)) }
|
|
44
|
+
|
|
45
|
+
func tnIntlHasString(list []string, s string) bool {
|
|
46
|
+
for _, v := range list {
|
|
47
|
+
if v == s {
|
|
48
|
+
return true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return false
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// A JS object with its keys in order (parts, segments, resolvedOptions: the
|
|
55
|
+
// program sees Node's key order in JSON.stringify and Object.keys)
|
|
56
|
+
func tnIntlObj(kv ...interface{}) *TnMap[string, interface{}] {
|
|
57
|
+
o := TnNewMap[string, interface{}]()
|
|
58
|
+
for i := 0; i+1 < len(kv); i += 2 {
|
|
59
|
+
o.Set(kv[i].(string), kv[i+1])
|
|
60
|
+
}
|
|
61
|
+
return o
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// A field of such an object
|
|
65
|
+
func tnIntlGet(obj interface{}, key string) interface{} {
|
|
66
|
+
if o, ok := obj.(*TnMap[string, interface{}]); ok {
|
|
67
|
+
return o.Get(key)
|
|
68
|
+
}
|
|
69
|
+
return TnGetValue(obj, key)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
func tnIntlOptStr(options interface{}, key string) (string, bool) {
|
|
73
|
+
if options == nil {
|
|
74
|
+
return "", false
|
|
75
|
+
}
|
|
76
|
+
if v, ok := TnGetValue(options, key).(string); ok {
|
|
77
|
+
return v, true
|
|
78
|
+
}
|
|
79
|
+
return "", false
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func tnIntlOptFloat(options interface{}, key string) (float64, bool) {
|
|
83
|
+
if options == nil {
|
|
84
|
+
return 0, false
|
|
85
|
+
}
|
|
86
|
+
v := TnGetValue(options, key)
|
|
87
|
+
if v == nil {
|
|
88
|
+
return 0, false
|
|
89
|
+
}
|
|
90
|
+
return TnNumber(v), true
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// An option that must be one of a set of strings, with the given default
|
|
94
|
+
func tnIntlOptionChoice(options interface{}, key string, def string, choices ...string) string {
|
|
95
|
+
if v, ok := tnIntlOptStr(options, key); ok {
|
|
96
|
+
if tnIntlHasString(choices, v) {
|
|
97
|
+
return v
|
|
98
|
+
}
|
|
99
|
+
tnIntlRangeError("Invalid " + key + ": " + v)
|
|
100
|
+
}
|
|
101
|
+
return def
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// --- locale resolution
|
|
105
|
+
|
|
106
|
+
var tnIntlLocaleSet = func() map[string]bool {
|
|
107
|
+
m := make(map[string]bool, len(tnIntlLocales))
|
|
108
|
+
for _, l := range tnIntlLocales {
|
|
109
|
+
m[l] = true
|
|
110
|
+
}
|
|
111
|
+
return m
|
|
112
|
+
}()
|
|
113
|
+
|
|
114
|
+
// The generated locales of each base language, for the fallback by language
|
|
115
|
+
var tnIntlByLanguage = func() map[string][]string {
|
|
116
|
+
m := map[string][]string{}
|
|
117
|
+
for _, l := range tnIntlLocales {
|
|
118
|
+
base := l
|
|
119
|
+
if i := strings.IndexByte(l, '-'); i >= 0 {
|
|
120
|
+
base = l[:i]
|
|
121
|
+
}
|
|
122
|
+
m[base] = append(m[base], l)
|
|
123
|
+
}
|
|
124
|
+
return m
|
|
125
|
+
}()
|
|
126
|
+
|
|
127
|
+
// The base language of a canonical id
|
|
128
|
+
func tnIntlLanguageOf(id string) string {
|
|
129
|
+
if i := strings.IndexByte(id, '-'); i >= 0 {
|
|
130
|
+
return id[:i]
|
|
131
|
+
}
|
|
132
|
+
return id
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// The id without its extensions (-u-…, -x-…)
|
|
136
|
+
func tnIntlBaseOf(id string) string {
|
|
137
|
+
base := id
|
|
138
|
+
for _, mark := range []string{"-u-", "-x-"} {
|
|
139
|
+
if i := strings.Index(base, mark); i >= 0 {
|
|
140
|
+
base = base[:i]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return base
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// The -u-…/-x-… extensions of a canonical id
|
|
147
|
+
func tnIntlExtensionOf(id string) string {
|
|
148
|
+
for _, mark := range []string{"-u-", "-x-"} {
|
|
149
|
+
if i := strings.Index(id, mark); i >= 0 {
|
|
150
|
+
return id[i:]
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return ""
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Region variants whose script differs from their language's likely one
|
|
157
|
+
// (zh-TW / zh-HK / zh-MO are Traditional while zh's likely script is Hans)
|
|
158
|
+
var tnIntlScriptByRegion = map[string]string{"zh": "TW,HK,MO=Hant"}
|
|
159
|
+
|
|
160
|
+
// The script of a canonical id: the explicit one, else the likely-subtags one
|
|
161
|
+
func tnIntlScriptOf(id string) string {
|
|
162
|
+
base := tnIntlBaseOf(id)
|
|
163
|
+
parts := strings.Split(base, "-")
|
|
164
|
+
if len(parts) > 1 && len(parts[1]) == 4 {
|
|
165
|
+
return parts[1]
|
|
166
|
+
}
|
|
167
|
+
lang := parts[0]
|
|
168
|
+
if rules, ok := tnIntlScriptByRegion[lang]; ok && len(parts) > 1 {
|
|
169
|
+
for _, pair := range strings.Split(rules, ";") {
|
|
170
|
+
kv := strings.SplitN(pair, "=", 2)
|
|
171
|
+
if len(kv) == 2 && tnIntlHasString(strings.Split(kv[0], ","), parts[len(parts)-1]) {
|
|
172
|
+
return kv[1]
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if full, ok := tnIntlLikely[lang]; ok {
|
|
177
|
+
fp := strings.Split(full, "-")
|
|
178
|
+
if len(fp) > 1 && len(fp[1]) == 4 {
|
|
179
|
+
return fp[1]
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return ""
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// The region of a canonical id: the 2-letter uppercase or 3-digit part
|
|
186
|
+
func tnIntlRegionOf(id string) string {
|
|
187
|
+
parts := strings.Split(tnIntlBaseOf(id), "-")
|
|
188
|
+
for i := 1; i < len(parts); i++ {
|
|
189
|
+
p := parts[i]
|
|
190
|
+
if len(p) == 4 {
|
|
191
|
+
continue
|
|
192
|
+
}
|
|
193
|
+
if (len(p) == 2 && p[0] >= 'A' && p[0] <= 'Z' && p[1] >= 'A' && p[1] <= 'Z') || (len(p) == 3 && p[0] >= '0' && p[0] <= '9' && p[1] >= '0' && p[1] <= '9' && p[2] >= '0' && p[2] <= '9') {
|
|
194
|
+
return p
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return ""
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// The generated locale a resolved id uses its data from: the exact locale,
|
|
201
|
+
// else a same-region / same-script / same-language entry, else nothing
|
|
202
|
+
// (unknown languages fall back to the root locale, pt-PT since CLDR 46, as
|
|
203
|
+
// Node resolves them)
|
|
204
|
+
func tnIntlMatchData(id string) string {
|
|
205
|
+
if tnIntlLocaleSet[id] {
|
|
206
|
+
return id
|
|
207
|
+
}
|
|
208
|
+
cands := tnIntlByLanguage[tnIntlLanguageOf(id)]
|
|
209
|
+
if len(cands) == 0 {
|
|
210
|
+
return ""
|
|
211
|
+
}
|
|
212
|
+
inRegion, inScript := tnIntlRegionOf(id), tnIntlScriptOf(id)
|
|
213
|
+
if inRegion != "" {
|
|
214
|
+
for _, c := range cands {
|
|
215
|
+
if tnIntlRegionOf(c) == inRegion {
|
|
216
|
+
return c
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
if inScript != "" {
|
|
221
|
+
for _, c := range cands {
|
|
222
|
+
if tnIntlScriptOf(c) == inScript {
|
|
223
|
+
return c
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
for _, c := range cands {
|
|
228
|
+
if !strings.Contains(tnIntlBaseOf(c), "-") {
|
|
229
|
+
return c
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return cands[0]
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// A resolved locale: the tag (its -u- extensions drive nu/hc/kn/kf/ca/co),
|
|
236
|
+
// the id resolvedOptions reports (the generated locale actually used, with
|
|
237
|
+
// the extensions kept, as Node reports the best available locale) and the
|
|
238
|
+
// generated locale the data comes from
|
|
239
|
+
type TnIntlLoc struct {
|
|
240
|
+
id string
|
|
241
|
+
tag xlanguage.Tag
|
|
242
|
+
data string
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
func tnIntlTagOf(id string) xlanguage.Tag {
|
|
246
|
+
tag, err := xlanguage.Parse(id)
|
|
247
|
+
if err != nil {
|
|
248
|
+
return xlanguage.MustParse("en-US")
|
|
249
|
+
}
|
|
250
|
+
return tag
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// The canonicalized requested locales (getCanonicalLocales): a RangeError on
|
|
254
|
+
// a malformed tag, duplicates removed
|
|
255
|
+
func TnIntlCanonicalList(locales interface{}) []string {
|
|
256
|
+
var in []string
|
|
257
|
+
switch v := locales.(type) {
|
|
258
|
+
case nil:
|
|
259
|
+
case string:
|
|
260
|
+
in = []string{v}
|
|
261
|
+
case []string:
|
|
262
|
+
in = v
|
|
263
|
+
case []interface{}:
|
|
264
|
+
for _, e := range v {
|
|
265
|
+
in = append(in, TnJSString(e))
|
|
266
|
+
}
|
|
267
|
+
default:
|
|
268
|
+
for _, e := range TnToArray(locales) {
|
|
269
|
+
in = append(in, TnJSString(e))
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
out := []string{}
|
|
273
|
+
seen := map[string]bool{}
|
|
274
|
+
for _, s := range in {
|
|
275
|
+
c, ok := tnIntlCanonicalTag(s)
|
|
276
|
+
if !ok {
|
|
277
|
+
panic(TnNodeError("RangeError", "", "Incorrect locale information provided"))
|
|
278
|
+
}
|
|
279
|
+
if !seen[c] {
|
|
280
|
+
seen[c] = true
|
|
281
|
+
out = append(out, c)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return out
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// A well-formed BCP 47 language tag (unicode_locale_id), canonicalized:
|
|
288
|
+
// golang.org/x/text's form when it knows the subtags, else the subtags'
|
|
289
|
+
// canonical case (unknown languages such as "xx" are well-formed)
|
|
290
|
+
var tnIntlTagRE = regexp.MustCompile("^(?i)([a-z]{2,3}|[a-z]{5,8})(-[a-z]{4})?(-([a-z]{2}|[0-9]{3}))?(-([a-z0-9]{5,8}|[0-9][a-z0-9]{3}))*(-[0-9a-wy-z](-[a-z0-9]{2,8})+)*(-x(-[a-z0-9]{1,8})+)?$")
|
|
291
|
+
|
|
292
|
+
func tnIntlCanonicalTag(s string) (string, bool) {
|
|
293
|
+
if !tnIntlTagRE.MatchString(s) {
|
|
294
|
+
return "", false
|
|
295
|
+
}
|
|
296
|
+
if tag, err := xlanguage.Parse(s); err == nil && !tag.IsRoot() {
|
|
297
|
+
return tag.String(), true
|
|
298
|
+
}
|
|
299
|
+
parts := strings.Split(strings.ToLower(s), "-")
|
|
300
|
+
for i := 1; i < len(parts); i++ {
|
|
301
|
+
if len(parts[i]) == 1 {
|
|
302
|
+
break // extensions stay lowercase
|
|
303
|
+
}
|
|
304
|
+
switch {
|
|
305
|
+
case len(parts[i]) == 4 && i == 1:
|
|
306
|
+
parts[i] = strings.ToUpper(parts[i][:1]) + parts[i][1:]
|
|
307
|
+
case len(parts[i]) == 2:
|
|
308
|
+
parts[i] = strings.ToUpper(parts[i])
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return strings.Join(parts, "-"), true
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// The first requested locale that resolves to generated data, else the root
|
|
315
|
+
// fallback (its extensions kept, as ICU keeps them)
|
|
316
|
+
func TnIntlResolve(locales interface{}) *TnIntlLoc {
|
|
317
|
+
ids := TnIntlCanonicalList(locales)
|
|
318
|
+
// (no locale with data: the default locale's, as ECMA-402's
|
|
319
|
+
// ResolveLocale falls back to DefaultLocale; then en-US)
|
|
320
|
+
ids = append(ids, tnIntlDefaultID(), "en-US")
|
|
321
|
+
var exts []string
|
|
322
|
+
for _, id := range ids {
|
|
323
|
+
tag := tnIntlTagOf(id)
|
|
324
|
+
if len(exts) == 0 {
|
|
325
|
+
for _, e := range tag.Extensions() {
|
|
326
|
+
exts = append(exts, e.String())
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if data := tnIntlMatchData(id); data != "" {
|
|
330
|
+
// (ICU has data for nearly every region: the requested base is
|
|
331
|
+
// what resolvedOptions().locale reports — de-AT, not de)
|
|
332
|
+
full := tnIntlBaseOf(id)
|
|
333
|
+
for _, e := range tag.Extensions() {
|
|
334
|
+
full += "-" + e.String()
|
|
335
|
+
}
|
|
336
|
+
if t2, err := xlanguage.Parse(full); err == nil {
|
|
337
|
+
full = t2.String()
|
|
338
|
+
}
|
|
339
|
+
return &TnIntlLoc{id: full, tag: tag, data: data}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
_ = exts
|
|
343
|
+
return &TnIntlLoc{id: "en-US", tag: tnIntlTagOf("en-US"), data: "en-US"}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Intl.getCanonicalLocales
|
|
347
|
+
func TnIntlGetCanonicalLocales(locales interface{}) []string { return TnIntlCanonicalList(locales) }
|
|
348
|
+
|
|
349
|
+
// supportedLocalesOf: the requested locales that resolve to generated data
|
|
350
|
+
func TnIntlSupportedLocalesOf(locales interface{}) []string {
|
|
351
|
+
out := []string{}
|
|
352
|
+
for _, id := range TnIntlCanonicalList(locales) {
|
|
353
|
+
if tnIntlMatchData(id) != "" {
|
|
354
|
+
out = append(out, id)
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return out
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Rendering digit runs with a numbering system's digits (0-9, one rune each)
|
|
361
|
+
func tnIntlMapDigits(s string, digits string) string {
|
|
362
|
+
if digits == "" {
|
|
363
|
+
return s
|
|
364
|
+
}
|
|
365
|
+
native := []rune(digits)
|
|
366
|
+
if len(native) != 10 {
|
|
367
|
+
return s
|
|
368
|
+
}
|
|
369
|
+
var b strings.Builder
|
|
370
|
+
for _, c := range s {
|
|
371
|
+
if c >= '0' && c <= '9' {
|
|
372
|
+
b.WriteRune(native[c-'0'])
|
|
373
|
+
continue
|
|
374
|
+
}
|
|
375
|
+
b.WriteRune(c)
|
|
376
|
+
}
|
|
377
|
+
return b.String()
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// The default locale: the OS's (tnIntlSystemLocale — the env on Unix,
|
|
381
|
+
// GetUserDefaultLocaleName on Windows), canonicalized, else en-US
|
|
382
|
+
var tnIntlDefaultOnce sync.Once
|
|
383
|
+
var tnIntlDefaultIDValue string
|
|
384
|
+
|
|
385
|
+
func tnIntlDefaultID() string {
|
|
386
|
+
tnIntlDefaultOnce.Do(func() {
|
|
387
|
+
id := strings.TrimSpace(tnIntlSystemLocale())
|
|
388
|
+
if c, ok := tnIntlCanonicalTag(id); ok && tnIntlMatchData(c) != "" {
|
|
389
|
+
tnIntlDefaultIDValue = c
|
|
390
|
+
return
|
|
391
|
+
}
|
|
392
|
+
tnIntlDefaultIDValue = "en-US"
|
|
393
|
+
})
|
|
394
|
+
return tnIntlDefaultIDValue
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// --- plural rules (golang.org/x/text/feature/plural)
|
|
398
|
+
|
|
399
|
+
func tnIntlPluralName(f xplural.Form) string {
|
|
400
|
+
switch f {
|
|
401
|
+
case xplural.Zero:
|
|
402
|
+
return "zero"
|
|
403
|
+
case xplural.One:
|
|
404
|
+
return "one"
|
|
405
|
+
case xplural.Two:
|
|
406
|
+
return "two"
|
|
407
|
+
case xplural.Few:
|
|
408
|
+
return "few"
|
|
409
|
+
case xplural.Many:
|
|
410
|
+
return "many"
|
|
411
|
+
}
|
|
412
|
+
return "other"
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// The plural operands of a rendered number's digits ("1234.50")
|
|
416
|
+
func tnIntlPluralOperands(digits string) (i, v, w, f, t int) {
|
|
417
|
+
intPart, frac := digits, ""
|
|
418
|
+
if dot := strings.IndexByte(digits, '.'); dot >= 0 {
|
|
419
|
+
intPart, frac = digits[:dot], digits[dot+1:]
|
|
420
|
+
}
|
|
421
|
+
intPart = strings.TrimLeft(intPart, "0")
|
|
422
|
+
if intPart == "" {
|
|
423
|
+
intPart = "0"
|
|
424
|
+
}
|
|
425
|
+
i64, _ := strconv.ParseInt(intPart, 10, 62)
|
|
426
|
+
i = int(i64)
|
|
427
|
+
v = len(frac)
|
|
428
|
+
f64, _ := strconv.ParseInt("1"+frac, 10, 62)
|
|
429
|
+
f = int(f64) - 1
|
|
430
|
+
trimmed := strings.TrimRight(frac, "0")
|
|
431
|
+
w = len(trimmed)
|
|
432
|
+
if trimmed == "" {
|
|
433
|
+
t = 0
|
|
434
|
+
} else {
|
|
435
|
+
t64, _ := strconv.ParseInt("1"+trimmed, 10, 62)
|
|
436
|
+
t = int(t64) - 1
|
|
437
|
+
}
|
|
438
|
+
return i, v, w, f, t
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// The cardinal plural category of a rendered number string
|
|
442
|
+
func tnIntlPluralOfDigits(tag xlanguage.Tag, digits string) string {
|
|
443
|
+
i, v, w, f, t := tnIntlPluralOperands(digits)
|
|
444
|
+
return tnIntlCardinal(tag, i, v, w, f, t)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// The cardinal category: golang.org/x/text's rules with the CLDR changes
|
|
448
|
+
// since its data (CLDR 38: "many" for millions in fr / es / it / pt / ca;
|
|
449
|
+
// CLDR 42: Hebrew without "many", fractions below 1 "one")
|
|
450
|
+
func tnIntlCardinal(tag xlanguage.Tag, i, v, w, f, t int) string {
|
|
451
|
+
base, _ := tag.Base()
|
|
452
|
+
switch base.String() {
|
|
453
|
+
case "fr", "es", "it", "pt", "ca":
|
|
454
|
+
if v == 0 && i != 0 && i%1000000 == 0 {
|
|
455
|
+
return "many"
|
|
456
|
+
}
|
|
457
|
+
case "he", "iw":
|
|
458
|
+
switch {
|
|
459
|
+
case (i == 1 && v == 0) || (i == 0 && v != 0):
|
|
460
|
+
return "one"
|
|
461
|
+
case i == 2 && v == 0:
|
|
462
|
+
return "two"
|
|
463
|
+
}
|
|
464
|
+
return "other"
|
|
465
|
+
}
|
|
466
|
+
return tnIntlPluralName(xplural.Cardinal.MatchPlural(tag, i, v, w, f, t))
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// The plural category of a JS number (the digits its string form shows)
|
|
470
|
+
func tnIntlPluralOfNumber(tag xlanguage.Tag, x float64) string {
|
|
471
|
+
if math.IsNaN(x) || math.IsInf(x, 0) || math.Abs(x) >= 1e21 {
|
|
472
|
+
return "other"
|
|
473
|
+
}
|
|
474
|
+
s := strconv.FormatFloat(math.Abs(x), 'f', -1, 64)
|
|
475
|
+
return tnIntlPluralOfDigits(tag, s)
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Intl.supportedValuesOf
|
|
479
|
+
func TnIntlSupportedValuesOf(kind string) []string {
|
|
480
|
+
switch kind {
|
|
481
|
+
case "calendar":
|
|
482
|
+
return tnIntlCalendars
|
|
483
|
+
case "currency":
|
|
484
|
+
return tnIntlCurrencies
|
|
485
|
+
case "numberingSystem":
|
|
486
|
+
return tnIntlNumberings
|
|
487
|
+
case "timeZone":
|
|
488
|
+
return tnIntlTimeZones
|
|
489
|
+
case "unit":
|
|
490
|
+
return tnIntlUnits
|
|
491
|
+
}
|
|
492
|
+
panic(TnNodeError("RangeError", "", "Invalid key: "+kind))
|
|
493
|
+
}`;
|
|
494
|
+
const intlLocaleOSWindows = `// The system locale on Windows: GetUserDefaultLocaleName (Node asks ICU for
|
|
495
|
+
// the OS locale), then the env vars
|
|
496
|
+
func tnIntlSystemLocale() string {
|
|
497
|
+
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
|
498
|
+
if proc := kernel32.NewProc("GetUserDefaultLocaleName"); proc.Find() == nil {
|
|
499
|
+
buf := make([]uint16, 85)
|
|
500
|
+
n, _, _ := proc.Call(uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)))
|
|
501
|
+
if n > 1 {
|
|
502
|
+
return syscall.UTF16ToString(buf[:n-1])
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return tnIntlEnvLocale()
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
func tnIntlEnvLocale() string {
|
|
509
|
+
for _, name := range []string{"LC_ALL", "LC_MESSAGES", "LANG"} {
|
|
510
|
+
if v := os.Getenv(name); v != "" {
|
|
511
|
+
v = strings.SplitN(v, ".", 2)[0]
|
|
512
|
+
if v != "C" && v != "POSIX" {
|
|
513
|
+
return strings.ReplaceAll(v, "_", "-")
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return ""
|
|
518
|
+
}`;
|
|
519
|
+
const intlLocaleOSOther = `// The system locale: the env vars (LC_ALL, LC_MESSAGES, LANG), "" if none
|
|
520
|
+
func tnIntlSystemLocale() string {
|
|
521
|
+
for _, name := range []string{"LC_ALL", "LC_MESSAGES", "LANG"} {
|
|
522
|
+
if v := os.Getenv(name); v != "" {
|
|
523
|
+
v = strings.SplitN(v, ".", 2)[0]
|
|
524
|
+
if v != "C" && v != "POSIX" {
|
|
525
|
+
return strings.ReplaceAll(v, "_", "-")
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return ""
|
|
530
|
+
}`;
|
|
531
|
+
const intlNumberSymsGo = `// Intl: the number symbol tables (keyed by generated locale; every resolved
|
|
532
|
+
// data locale is present, with en as the guard)
|
|
533
|
+
func tnIntlNumSym(data string, key string) string {
|
|
534
|
+
if m := tnIntlNumberNames[data]; m != nil {
|
|
535
|
+
if v, ok := m[key]; ok {
|
|
536
|
+
return v
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
if m := tnIntlNumberNames["en"]; m != nil {
|
|
540
|
+
return m[key]
|
|
541
|
+
}
|
|
542
|
+
return ""
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
func tnIntlNumParts(data string) map[string][]tnIntlPart {
|
|
546
|
+
if m := tnIntlNumberParts[data]; m != nil {
|
|
547
|
+
return m
|
|
548
|
+
}
|
|
549
|
+
return tnIntlNumberParts["en"]
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// The digits a locale formats with: its -u-nu- numbering system's, else the
|
|
553
|
+
// locale's own ("" = latin)
|
|
554
|
+
func tnIntlDigitsFor(loc *TnIntlLoc) string {
|
|
555
|
+
if nu := loc.tag.TypeForKey("nu"); nu != "" {
|
|
556
|
+
if d, ok := tnIntlNumberingDigits[nu]; ok {
|
|
557
|
+
return d
|
|
558
|
+
}
|
|
559
|
+
return ""
|
|
560
|
+
}
|
|
561
|
+
return tnIntlNumSym(loc.data, "digits")
|
|
562
|
+
}
|
|
563
|
+
`;
|
|
564
|
+
const intlNumberGo = `// Intl.NumberFormat: digits and rounding on the exact decimal expansion of
|
|
565
|
+
// the double (as V8 rounds), then the locale's symbols and patterns
|
|
566
|
+
|
|
567
|
+
type TnIntlNumberFormat struct {
|
|
568
|
+
loc *TnIntlLoc
|
|
569
|
+
style string
|
|
570
|
+
currency string
|
|
571
|
+
currencyDisplay string
|
|
572
|
+
unit string
|
|
573
|
+
unitDisplay string
|
|
574
|
+
notation string
|
|
575
|
+
compactDisplay string
|
|
576
|
+
minInt int
|
|
577
|
+
minFD, maxFD int
|
|
578
|
+
useSD bool
|
|
579
|
+
minSD, maxSD int
|
|
580
|
+
mode string
|
|
581
|
+
increment int
|
|
582
|
+
trailing string
|
|
583
|
+
sign string
|
|
584
|
+
grouping string
|
|
585
|
+
compactAuto bool // compact notation without digit options
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
var tnIntlRoundingModes = map[string]bool{"ceil": true, "floor": true, "expand": true, "trunc": true, "halfExpand": true, "halfCeil": true, "halfFloor": true, "halfTrunc": true, "halfEven": true}
|
|
589
|
+
var tnIntlIncrements = map[string]bool{"1": true, "2": true, "5": true, "10": true, "20": true, "25": true, "50": true, "100": true, "200": true, "250": true, "500": true, "1000": true, "2000": true, "2500": true, "5000": true}
|
|
590
|
+
|
|
591
|
+
// A currency's fraction digits (tnIntlCurrencyDigits lists those that aren't 2)
|
|
592
|
+
func tnIntlCurrencyFD(code string) int {
|
|
593
|
+
if d, ok := tnIntlCurrencyDigits[code]; ok {
|
|
594
|
+
n, _ := strconv.Atoi(d)
|
|
595
|
+
return n
|
|
596
|
+
}
|
|
597
|
+
return 2
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// new Intl.NumberFormat(locales, options)
|
|
601
|
+
func TnNewIntlNumberFormat(locales interface{}, options interface{}) *TnIntlNumberFormat {
|
|
602
|
+
f := &TnIntlNumberFormat{
|
|
603
|
+
loc: TnIntlResolve(locales),
|
|
604
|
+
style: "decimal",
|
|
605
|
+
currencyDisplay: "symbol",
|
|
606
|
+
unitDisplay: "short",
|
|
607
|
+
notation: "standard",
|
|
608
|
+
compactDisplay: "short",
|
|
609
|
+
minInt: 1,
|
|
610
|
+
minFD: 0,
|
|
611
|
+
maxFD: 3,
|
|
612
|
+
mode: "halfExpand",
|
|
613
|
+
increment: 1,
|
|
614
|
+
trailing: "auto",
|
|
615
|
+
sign: "auto",
|
|
616
|
+
grouping: "auto",
|
|
617
|
+
}
|
|
618
|
+
f.style = tnIntlOptionChoice(options, "style", f.style, "decimal", "percent", "currency", "unit")
|
|
619
|
+
if f.style == "currency" {
|
|
620
|
+
code, ok := tnIntlOptStr(options, "currency")
|
|
621
|
+
if !ok || code == "" {
|
|
622
|
+
panic(TnNodeError("TypeError", "", "Currency code is required"))
|
|
623
|
+
}
|
|
624
|
+
code = strings.ToUpper(code)
|
|
625
|
+
if !tnIntlHasString(tnIntlCurrencies, code) {
|
|
626
|
+
tnIntlRangeError("Invalid currency code")
|
|
627
|
+
}
|
|
628
|
+
f.currency = code
|
|
629
|
+
f.currencyDisplay = tnIntlOptionChoice(options, "currencyDisplay", "symbol", "symbol", "narrowSymbol", "code", "name")
|
|
630
|
+
}
|
|
631
|
+
if f.style == "unit" {
|
|
632
|
+
unit, ok := tnIntlOptStr(options, "unit")
|
|
633
|
+
if !ok || unit == "" {
|
|
634
|
+
panic(TnNodeError("TypeError", "", "Unit is required"))
|
|
635
|
+
}
|
|
636
|
+
// a sanctioned unit, or two joined by -per- (kilometer-per-hour)
|
|
637
|
+
num, den, per := strings.Cut(unit, "-per-")
|
|
638
|
+
if !tnIntlHasString(tnIntlUnits, num) || (per && !tnIntlHasString(tnIntlUnits, den)) {
|
|
639
|
+
tnIntlRangeError("Invalid unit argument for Intl.NumberFormat() '" + unit + "'")
|
|
640
|
+
}
|
|
641
|
+
f.unit = unit
|
|
642
|
+
f.unitDisplay = tnIntlOptionChoice(options, "unitDisplay", "short", "short", "long", "narrow")
|
|
643
|
+
}
|
|
644
|
+
f.notation = tnIntlOptionChoice(options, "notation", "standard", "standard", "scientific", "engineering", "compact")
|
|
645
|
+
if f.notation == "compact" {
|
|
646
|
+
f.compactDisplay = tnIntlOptionChoice(options, "compactDisplay", "short", "short", "long")
|
|
647
|
+
}
|
|
648
|
+
// significant digits override the fraction digits
|
|
649
|
+
if v, ok := tnIntlOptFloat(options, "minimumSignificantDigits"); ok {
|
|
650
|
+
n := int(v)
|
|
651
|
+
if v != math.Trunc(v) || n < 1 || n > 21 {
|
|
652
|
+
tnIntlRangeError("minimumSignificantDigits value is out of range.")
|
|
653
|
+
}
|
|
654
|
+
f.useSD, f.minSD = true, n
|
|
655
|
+
if v, ok := tnIntlOptFloat(options, "maximumSignificantDigits"); ok {
|
|
656
|
+
n := int(v)
|
|
657
|
+
if v != math.Trunc(v) || n < f.minSD || n > 21 {
|
|
658
|
+
tnIntlRangeError("maximumSignificantDigits value is out of range.")
|
|
659
|
+
}
|
|
660
|
+
f.maxSD = n
|
|
661
|
+
} else {
|
|
662
|
+
f.maxSD = 21
|
|
663
|
+
}
|
|
664
|
+
} else if v, ok := tnIntlOptFloat(options, "maximumSignificantDigits"); ok {
|
|
665
|
+
n := int(v)
|
|
666
|
+
if v != math.Trunc(v) || n < 1 || n > 21 {
|
|
667
|
+
tnIntlRangeError("maximumSignificantDigits value is out of range.")
|
|
668
|
+
}
|
|
669
|
+
f.useSD, f.minSD, f.maxSD = true, 1, n
|
|
670
|
+
}
|
|
671
|
+
if !f.useSD {
|
|
672
|
+
switch f.notation {
|
|
673
|
+
case "scientific", "engineering":
|
|
674
|
+
f.minFD, f.maxFD = 0, 3
|
|
675
|
+
case "compact":
|
|
676
|
+
f.minFD, f.maxFD = 0, 1
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
if mode, ok := tnIntlOptStr(options, "roundingMode"); ok {
|
|
680
|
+
if !tnIntlRoundingModes[mode] {
|
|
681
|
+
tnIntlRangeError("Invalid roundingMode: " + mode)
|
|
682
|
+
}
|
|
683
|
+
f.mode = mode
|
|
684
|
+
}
|
|
685
|
+
if inc, ok := tnIntlOptFloat(options, "roundingIncrement"); ok {
|
|
686
|
+
n := int(inc)
|
|
687
|
+
if inc != math.Trunc(inc) || !tnIntlIncrements[strconv.Itoa(n)] {
|
|
688
|
+
tnIntlRangeError("roundingIncrement value is out of range.")
|
|
689
|
+
}
|
|
690
|
+
f.increment = n
|
|
691
|
+
if f.useSD {
|
|
692
|
+
tnIntlRangeError("roundingIncrement with significant digits is out of range.")
|
|
693
|
+
}
|
|
694
|
+
// with an increment, minimum and maximum fraction digits are equal
|
|
695
|
+
mn, mnok := tnIntlOptFloat(options, "minimumFractionDigits")
|
|
696
|
+
mx, mxok := tnIntlOptFloat(options, "maximumFractionDigits")
|
|
697
|
+
if mnok && mxok && int(mn) != int(mx) {
|
|
698
|
+
tnIntlRangeError("roundingIncrement needs equal minimum and maximum fraction digits")
|
|
699
|
+
}
|
|
700
|
+
d := mn
|
|
701
|
+
if !mnok {
|
|
702
|
+
d = mx
|
|
703
|
+
}
|
|
704
|
+
if d != math.Trunc(d) || int(d) < 0 || int(d) > 20 {
|
|
705
|
+
tnIntlRangeError("minimumFractionDigits value is out of range.")
|
|
706
|
+
}
|
|
707
|
+
f.minFD, f.maxFD = int(d), int(d)
|
|
708
|
+
}
|
|
709
|
+
if !f.useSD && f.increment == 1 {
|
|
710
|
+
if v, ok := tnIntlOptFloat(options, "minimumIntegerDigits"); ok {
|
|
711
|
+
n := int(v)
|
|
712
|
+
if v != math.Trunc(v) || n < 1 || n > 21 {
|
|
713
|
+
tnIntlRangeError("minimumIntegerDigits value is out of range.")
|
|
714
|
+
}
|
|
715
|
+
f.minInt = n
|
|
716
|
+
}
|
|
717
|
+
mn, mnok := tnIntlOptFloat(options, "minimumFractionDigits")
|
|
718
|
+
if mnok {
|
|
719
|
+
n := int(mn)
|
|
720
|
+
if mn != math.Trunc(mn) || n < 0 || n > 20 {
|
|
721
|
+
tnIntlRangeError("minimumFractionDigits value is out of range.")
|
|
722
|
+
}
|
|
723
|
+
f.minFD = n
|
|
724
|
+
}
|
|
725
|
+
mx, mxok := tnIntlOptFloat(options, "maximumFractionDigits")
|
|
726
|
+
if mxok {
|
|
727
|
+
n := int(mx)
|
|
728
|
+
if mx != math.Trunc(mx) || n < 0 || n > 20 || n < f.minFD {
|
|
729
|
+
tnIntlRangeError("maximumFractionDigits value is out of range.")
|
|
730
|
+
}
|
|
731
|
+
f.maxFD = n
|
|
732
|
+
}
|
|
733
|
+
// the defaults (SetNumberFormatDigitOptions): decimal 0-3, currency
|
|
734
|
+
// its digits (2, JPY 0, KWD 3 …), percent 0-0; compact rounds to 0
|
|
735
|
+
// fraction digits or 2 significant digits, whichever keeps more
|
|
736
|
+
defMin, defMax := 0, 3
|
|
737
|
+
switch f.style {
|
|
738
|
+
case "currency":
|
|
739
|
+
defMin = tnIntlCurrencyFD(f.currency)
|
|
740
|
+
defMax = defMin
|
|
741
|
+
case "percent":
|
|
742
|
+
defMin, defMax = 0, 0
|
|
743
|
+
}
|
|
744
|
+
switch {
|
|
745
|
+
case !mnok && !mxok:
|
|
746
|
+
if f.notation == "compact" {
|
|
747
|
+
defMin, defMax = 0, 0
|
|
748
|
+
f.compactAuto = true
|
|
749
|
+
}
|
|
750
|
+
f.minFD, f.maxFD = defMin, defMax
|
|
751
|
+
case mnok && !mxok:
|
|
752
|
+
f.maxFD = max(defMax, f.minFD)
|
|
753
|
+
case mxok && !mnok:
|
|
754
|
+
f.minFD = min(defMin, f.maxFD)
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
f.trailing = tnIntlOptionChoice(options, "trailingZeroDisplay", "auto", "auto", "stripIfInteger")
|
|
758
|
+
f.sign = tnIntlOptionChoice(options, "signDisplay", "auto", "auto", "always", "never", "exceptZero", "negative")
|
|
759
|
+
if f.notation == "compact" {
|
|
760
|
+
f.grouping = "min2" // compact's default
|
|
761
|
+
}
|
|
762
|
+
if v, ok := tnIntlOptStr(options, "useGrouping"); ok {
|
|
763
|
+
if v != "true" && v != "false" && v != "min2" && v != "always" && v != "auto" {
|
|
764
|
+
tnIntlRangeError("useGrouping value is out of range.")
|
|
765
|
+
}
|
|
766
|
+
f.grouping = v
|
|
767
|
+
} else if options != nil {
|
|
768
|
+
if gv := TnGetValue(options, "useGrouping"); gv != nil {
|
|
769
|
+
if TnTruthy(gv) {
|
|
770
|
+
f.grouping = "true"
|
|
771
|
+
} else {
|
|
772
|
+
f.grouping = "false"
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
return f
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// The decimal digits of the absolute value of a finite double, as ICU reads
|
|
780
|
+
// a double: its shortest round-trip form ("1234.5678", "0.0000001", "1e21" →
|
|
781
|
+
// "1000000000000000000000"), so 1.005 rounds to 1.01 as in Node
|
|
782
|
+
func tnFloatDigits(x float64) string {
|
|
783
|
+
if x == 0 {
|
|
784
|
+
return "0"
|
|
785
|
+
}
|
|
786
|
+
s := strconv.FormatFloat(x, 'e', -1, 64)
|
|
787
|
+
mant, expStr, _ := strings.Cut(s, "e")
|
|
788
|
+
exp, _ := strconv.Atoi(expStr)
|
|
789
|
+
digits := strings.Replace(mant, ".", "", 1)
|
|
790
|
+
// digits is d.ddd × 10^exp: the point sits after exp+1 digits
|
|
791
|
+
point := exp + 1
|
|
792
|
+
switch {
|
|
793
|
+
case point <= 0:
|
|
794
|
+
return "0." + strings.Repeat("0", -point) + digits
|
|
795
|
+
case point >= len(digits):
|
|
796
|
+
return digits + strings.Repeat("0", point-len(digits))
|
|
797
|
+
}
|
|
798
|
+
return digits[:point] + "." + digits[point:]
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
var tnIntlPow10Cache = map[int]*tnbig.Int{0: tnbig.NewInt(1)}
|
|
802
|
+
|
|
803
|
+
func tnIntlPow10(k int) *tnbig.Int {
|
|
804
|
+
if k < 0 {
|
|
805
|
+
k = 0
|
|
806
|
+
}
|
|
807
|
+
if v, ok := tnIntlPow10Cache[k]; ok {
|
|
808
|
+
return v
|
|
809
|
+
}
|
|
810
|
+
v := new(tnbig.Int).Mul(tnIntlPow10(k-1), tnbig.NewInt(10))
|
|
811
|
+
tnIntlPow10Cache[k] = v
|
|
812
|
+
return v
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// One rounding step: q + r/div rounded by the mode (a non-negative value)
|
|
816
|
+
func tnIntlRoundQuotient(q, r, div *tnbig.Int, mode string) *tnbig.Int {
|
|
817
|
+
cmp := new(tnbig.Int).Mul(r, tnbig.NewInt(2)).Cmp(div)
|
|
818
|
+
up := false
|
|
819
|
+
switch mode {
|
|
820
|
+
case "ceil", "expand":
|
|
821
|
+
up = r.Sign() > 0
|
|
822
|
+
case "floor", "trunc":
|
|
823
|
+
up = false
|
|
824
|
+
case "halfExpand":
|
|
825
|
+
up = cmp >= 0
|
|
826
|
+
case "halfCeil", "halfFloor", "halfTrunc":
|
|
827
|
+
up = cmp > 0
|
|
828
|
+
case "halfEven":
|
|
829
|
+
if cmp > 0 {
|
|
830
|
+
up = true
|
|
831
|
+
} else if cmp == 0 {
|
|
832
|
+
up = q.Bit(0) == 1
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
if up {
|
|
836
|
+
return new(tnbig.Int).Add(q, tnbig.NewInt(1))
|
|
837
|
+
}
|
|
838
|
+
return q
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
// Round |value| (the digit string with fracLen fraction digits) to maxFD
|
|
842
|
+
// fraction digits, with an optional increment quantum, by the mode, on the
|
|
843
|
+
// exact expansion. Returns the rounded digits with exactly maxFD fraction
|
|
844
|
+
// digits (no decimal point)
|
|
845
|
+
func tnIntlRound(digits string, fracLen int, maxFD int, mode string, increment int) string {
|
|
846
|
+
n := new(tnbig.Int)
|
|
847
|
+
if digits != "" {
|
|
848
|
+
n.SetString(digits, 10)
|
|
849
|
+
}
|
|
850
|
+
target := n
|
|
851
|
+
if maxFD > fracLen {
|
|
852
|
+
target = new(tnbig.Int).Mul(n, tnIntlPow10(maxFD-fracLen))
|
|
853
|
+
} else if maxFD < fracLen {
|
|
854
|
+
q, r := new(tnbig.Int).QuoRem(n, tnIntlPow10(fracLen-maxFD), new(tnbig.Int))
|
|
855
|
+
target = tnIntlRoundQuotient(q, r, tnIntlPow10(fracLen-maxFD), mode)
|
|
856
|
+
}
|
|
857
|
+
if increment > 1 {
|
|
858
|
+
// the quantum is inc × 10^-maxFD: the scaled value is a multiple of inc
|
|
859
|
+
q, r := new(tnbig.Int).QuoRem(target, tnbig.NewInt(int64(increment)), new(tnbig.Int))
|
|
860
|
+
q = tnIntlRoundQuotient(q, r, tnbig.NewInt(int64(increment)), mode)
|
|
861
|
+
target = new(tnbig.Int).Mul(q, tnbig.NewInt(int64(increment)))
|
|
862
|
+
}
|
|
863
|
+
s := target.String()
|
|
864
|
+
if len(s) <= maxFD {
|
|
865
|
+
s = strings.Repeat("0", maxFD-len(s)+1) + s
|
|
866
|
+
}
|
|
867
|
+
return s
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// Whether rounding the kept digits up by the rest (digits beyond the kept
|
|
871
|
+
// ones) moves the last kept digit up (possibly carrying)
|
|
872
|
+
func tnIntlRoundRest(kept, rest, mode string) bool {
|
|
873
|
+
if rest == "" {
|
|
874
|
+
return false
|
|
875
|
+
}
|
|
876
|
+
allHalf := rest[0] == '5' && strings.Trim(rest[1:], "0") == ""
|
|
877
|
+
beyond := strings.Trim(rest, "0") != ""
|
|
878
|
+
switch mode {
|
|
879
|
+
case "ceil", "expand":
|
|
880
|
+
return beyond
|
|
881
|
+
case "floor", "trunc":
|
|
882
|
+
return false
|
|
883
|
+
case "halfExpand":
|
|
884
|
+
return rest[0] > '5' || (rest[0] == '5' && (beyond || allHalf))
|
|
885
|
+
case "halfCeil", "halfFloor", "halfTrunc":
|
|
886
|
+
return rest[0] > '5' || (rest[0] == '5' && beyond)
|
|
887
|
+
case "halfEven":
|
|
888
|
+
if rest[0] > '5' || (rest[0] == '5' && beyond) {
|
|
889
|
+
return true
|
|
890
|
+
}
|
|
891
|
+
if allHalf {
|
|
892
|
+
return kept[len(kept)-1]%2 == 1
|
|
893
|
+
}
|
|
894
|
+
return false
|
|
895
|
+
}
|
|
896
|
+
return false
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// Round to significant digits: |x|'s digits rounded to maxSD significant
|
|
900
|
+
// digits by the mode, padded to minSD. Returns the digits (no point) and the
|
|
901
|
+
// fraction digit count shown
|
|
902
|
+
func tnIntlRoundSignificant(intPart, fracPart string, minSD, maxSD int, mode string) (string, int) {
|
|
903
|
+
all := intPart + fracPart
|
|
904
|
+
first := 0
|
|
905
|
+
for first < len(all) && all[first] == '0' {
|
|
906
|
+
first++
|
|
907
|
+
}
|
|
908
|
+
if first == len(all) {
|
|
909
|
+
return strings.Repeat("0", minSD), minSD - 1
|
|
910
|
+
}
|
|
911
|
+
intDigits := len(intPart) - first
|
|
912
|
+
if intDigits < 0 {
|
|
913
|
+
intDigits = 0
|
|
914
|
+
}
|
|
915
|
+
sig := all[first:]
|
|
916
|
+
kept := sig
|
|
917
|
+
carry := false
|
|
918
|
+
if len(sig) > maxSD {
|
|
919
|
+
rest := sig[maxSD:]
|
|
920
|
+
kept = sig[:maxSD]
|
|
921
|
+
carry = tnIntlRoundRest(kept, rest, mode)
|
|
922
|
+
}
|
|
923
|
+
if carry {
|
|
924
|
+
// "999" → "1000": the leading digit shifts
|
|
925
|
+
kept = "1" + strings.Repeat("0", maxSD-1)
|
|
926
|
+
intDigits++
|
|
927
|
+
}
|
|
928
|
+
if len(kept) < minSD {
|
|
929
|
+
kept += strings.Repeat("0", minSD-len(kept))
|
|
930
|
+
}
|
|
931
|
+
fracShown := len(kept) - intDigits
|
|
932
|
+
if fracShown < 0 {
|
|
933
|
+
fracShown = 0
|
|
934
|
+
}
|
|
935
|
+
digits := kept
|
|
936
|
+
if intDigits > len(kept) {
|
|
937
|
+
digits = kept + strings.Repeat("0", intDigits-len(kept))
|
|
938
|
+
fracShown = 0
|
|
939
|
+
}
|
|
940
|
+
return digits, fracShown
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// The locale's grouping sizes ("3", "3;2")
|
|
944
|
+
func tnIntlGroupSizes(data string) []int {
|
|
945
|
+
spec := tnIntlNumSym(data, "grpSizes")
|
|
946
|
+
if spec == "" {
|
|
947
|
+
return []int{3}
|
|
948
|
+
}
|
|
949
|
+
out := []int{}
|
|
950
|
+
for _, s := range strings.Split(spec, ";") {
|
|
951
|
+
n, _ := strconv.Atoi(s)
|
|
952
|
+
if n <= 0 {
|
|
953
|
+
n = 3
|
|
954
|
+
}
|
|
955
|
+
out = append(out, n)
|
|
956
|
+
}
|
|
957
|
+
return out
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
// The integer digit groups, left to right, by the locale's sizes
|
|
961
|
+
func tnIntlGroupDigits(intPart string, sizes []int, grouping string) []string {
|
|
962
|
+
if grouping == "false" || len(intPart) == 0 || (grouping == "min2" && len(intPart) < 5) {
|
|
963
|
+
return []string{intPart}
|
|
964
|
+
}
|
|
965
|
+
if len(sizes) == 0 {
|
|
966
|
+
return []string{intPart}
|
|
967
|
+
}
|
|
968
|
+
groups := []string{}
|
|
969
|
+
pos := len(intPart)
|
|
970
|
+
size := sizes[0]
|
|
971
|
+
for pos > 0 {
|
|
972
|
+
start := pos - size
|
|
973
|
+
if start < 0 {
|
|
974
|
+
start = 0
|
|
975
|
+
}
|
|
976
|
+
groups = append([]string{intPart[start:pos]}, groups...)
|
|
977
|
+
pos = start
|
|
978
|
+
if len(sizes) > 1 {
|
|
979
|
+
size = sizes[1]
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
if grouping == "min2" && len(groups) < 2 {
|
|
983
|
+
return []string{intPart}
|
|
984
|
+
}
|
|
985
|
+
return groups
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// The rendered number: the sign and its parts — digit groups ('i'), the
|
|
989
|
+
// group separators ('g'), the decimal separator ('d') and the fraction ('f')
|
|
990
|
+
func tnIntlRenderNumber(f *TnIntlNumberFormat, digits string, point int, fracShown int, negative bool, negativeZero bool) (string, []tnIntlPart) {
|
|
991
|
+
data := f.loc.data
|
|
992
|
+
digitsMap := tnIntlDigitsFor(f.loc)
|
|
993
|
+
intPart := "0"
|
|
994
|
+
if point > 0 && point <= len(digits) {
|
|
995
|
+
intPart = digits[:point]
|
|
996
|
+
} else if point > len(digits) {
|
|
997
|
+
intPart = digits + strings.Repeat("0", point-len(digits))
|
|
998
|
+
}
|
|
999
|
+
intPart = strings.TrimLeft(intPart, "0")
|
|
1000
|
+
if intPart == "" {
|
|
1001
|
+
intPart = "0"
|
|
1002
|
+
}
|
|
1003
|
+
for len(intPart) < f.minInt {
|
|
1004
|
+
intPart = "0" + intPart
|
|
1005
|
+
}
|
|
1006
|
+
frac := ""
|
|
1007
|
+
if point >= 0 && point < len(digits) {
|
|
1008
|
+
frac = digits[point:]
|
|
1009
|
+
}
|
|
1010
|
+
for len(frac) < fracShown {
|
|
1011
|
+
frac += "0"
|
|
1012
|
+
}
|
|
1013
|
+
if len(frac) > fracShown {
|
|
1014
|
+
frac = frac[:fracShown]
|
|
1015
|
+
}
|
|
1016
|
+
grouping := f.grouping
|
|
1017
|
+
if grouping == "auto" {
|
|
1018
|
+
grouping = "true"
|
|
1019
|
+
if tnIntlNumSym(data, "minGrp") == "2" {
|
|
1020
|
+
grouping = "min2"
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
parts := []tnIntlPart{}
|
|
1024
|
+
for i, g := range tnIntlGroupDigits(intPart, tnIntlGroupSizes(data), grouping) {
|
|
1025
|
+
if i > 0 {
|
|
1026
|
+
parts = append(parts, tnIntlPart{kind: 'g', text: tnIntlNumSym(data, "grp")})
|
|
1027
|
+
}
|
|
1028
|
+
parts = append(parts, tnIntlPart{kind: 'i', text: tnIntlMapDigits(g, digitsMap)})
|
|
1029
|
+
}
|
|
1030
|
+
if frac != "" {
|
|
1031
|
+
parts = append(parts, tnIntlPart{kind: 'd', text: tnIntlNumSym(data, "dec")})
|
|
1032
|
+
parts = append(parts, tnIntlPart{kind: 'f', text: tnIntlMapDigits(frac, digitsMap)})
|
|
1033
|
+
}
|
|
1034
|
+
sign := ""
|
|
1035
|
+
switch f.sign {
|
|
1036
|
+
case "auto":
|
|
1037
|
+
if negative || negativeZero {
|
|
1038
|
+
sign = tnIntlNumSym(data, "minus")
|
|
1039
|
+
}
|
|
1040
|
+
case "always":
|
|
1041
|
+
if negative || negativeZero {
|
|
1042
|
+
sign = tnIntlNumSym(data, "minus")
|
|
1043
|
+
} else {
|
|
1044
|
+
sign = tnIntlNumSym(data, "plus")
|
|
1045
|
+
}
|
|
1046
|
+
case "exceptZero":
|
|
1047
|
+
// (zero — rounded to zero too — shows no sign)
|
|
1048
|
+
if strings.Trim(intPart+frac, "0") == "" {
|
|
1049
|
+
break
|
|
1050
|
+
}
|
|
1051
|
+
if negative {
|
|
1052
|
+
sign = tnIntlNumSym(data, "minus")
|
|
1053
|
+
} else {
|
|
1054
|
+
sign = tnIntlNumSym(data, "plus")
|
|
1055
|
+
}
|
|
1056
|
+
case "negative":
|
|
1057
|
+
if negative && strings.Trim(intPart+frac, "0") != "" {
|
|
1058
|
+
sign = tnIntlNumSym(data, "minus")
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
return sign, parts
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
// A value as (the exact |digits|, their fraction length, sign, negative zero)
|
|
1065
|
+
func tnIntlNumberDigits(f *TnIntlNumberFormat, x interface{}) (string, int, bool, bool, bool, bool) {
|
|
1066
|
+
switch v := x.(type) {
|
|
1067
|
+
case *tnbig.Int:
|
|
1068
|
+
neg := v.Sign() < 0
|
|
1069
|
+
digits := new(tnbig.Int).Abs(v).String()
|
|
1070
|
+
return digits, 0, neg, false, false, false
|
|
1071
|
+
case float64:
|
|
1072
|
+
if math.IsNaN(v) {
|
|
1073
|
+
return "", 0, false, false, true, false
|
|
1074
|
+
}
|
|
1075
|
+
if math.IsInf(v, 0) {
|
|
1076
|
+
return "", 0, v < 0, false, false, true
|
|
1077
|
+
}
|
|
1078
|
+
neg := math.Signbit(v)
|
|
1079
|
+
if v == 0 {
|
|
1080
|
+
return "0", 1, neg, neg, false, false
|
|
1081
|
+
}
|
|
1082
|
+
d := tnFloatDigits(math.Abs(v))
|
|
1083
|
+
fracLen := 0
|
|
1084
|
+
if dot := strings.IndexByte(d, '.'); dot >= 0 {
|
|
1085
|
+
d = d[:dot] + d[dot+1:]
|
|
1086
|
+
fracLen = len(d) - dot
|
|
1087
|
+
}
|
|
1088
|
+
if f.style == "percent" {
|
|
1089
|
+
// the value × 100 before rounding
|
|
1090
|
+
fracLen -= 2
|
|
1091
|
+
for fracLen < 0 {
|
|
1092
|
+
d += "0"
|
|
1093
|
+
fracLen++
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
return d, fracLen, neg, false, false, false
|
|
1097
|
+
}
|
|
1098
|
+
return tnIntlNumberDigits(f, TnNumber(x))
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
// The digits, integer-digit count and fraction digits shown after rounding
|
|
1102
|
+
func tnIntlRoundStandard(f *TnIntlNumberFormat, digits string, fracLen int) (string, int, int) {
|
|
1103
|
+
if f.useSD {
|
|
1104
|
+
intPart, fracPart := "", ""
|
|
1105
|
+
if fracLen > 0 && fracLen <= len(digits) {
|
|
1106
|
+
intPart, fracPart = digits[:len(digits)-fracLen], digits[len(digits)-fracLen:]
|
|
1107
|
+
} else {
|
|
1108
|
+
intPart = digits
|
|
1109
|
+
}
|
|
1110
|
+
d, frac := tnIntlRoundSignificant(intPart, fracPart, f.minSD, f.maxSD, f.mode)
|
|
1111
|
+
return d, len(d) - frac, frac
|
|
1112
|
+
}
|
|
1113
|
+
rounded := tnIntlRound(digits, fracLen, f.maxFD, f.mode, f.increment)
|
|
1114
|
+
point := len(rounded) - f.maxFD
|
|
1115
|
+
if point < 0 {
|
|
1116
|
+
point = 0
|
|
1117
|
+
}
|
|
1118
|
+
frac := f.maxFD
|
|
1119
|
+
fracDigits := rounded[point:]
|
|
1120
|
+
// trailing zeros beyond the minimum disappear
|
|
1121
|
+
for frac > f.minFD && strings.HasSuffix(fracDigits, "0") {
|
|
1122
|
+
frac--
|
|
1123
|
+
fracDigits = fracDigits[:len(fracDigits)-1]
|
|
1124
|
+
}
|
|
1125
|
+
if f.trailing == "stripIfInteger" && strings.Trim(fracDigits, "0") == "" {
|
|
1126
|
+
frac = 0
|
|
1127
|
+
}
|
|
1128
|
+
return rounded, point, frac
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
// The currency template's key prefix and the value its currency part takes
|
|
1132
|
+
// ("" keeps the generated symbol). Currencies without generated symbols show
|
|
1133
|
+
// their ISO code, as ICU does for codes it has no symbol for
|
|
1134
|
+
func tnIntlCurrencyTemplate(f *TnIntlNumberFormat, cat string) (string, string) {
|
|
1135
|
+
all := tnIntlNumParts(f.loc.data)
|
|
1136
|
+
switch f.currencyDisplay {
|
|
1137
|
+
case "code":
|
|
1138
|
+
return "curCode:", f.currency
|
|
1139
|
+
case "name":
|
|
1140
|
+
name := tnIntlNumSym(f.loc.data, "curName:"+f.currency+":"+cat)
|
|
1141
|
+
if name == "" {
|
|
1142
|
+
name = tnIntlNumSym(f.loc.data, "curName:"+f.currency+":other")
|
|
1143
|
+
}
|
|
1144
|
+
if name == "" {
|
|
1145
|
+
name = f.currency
|
|
1146
|
+
}
|
|
1147
|
+
return "curNm", name
|
|
1148
|
+
case "narrowSymbol":
|
|
1149
|
+
if _, ok := all["curNar:"+f.currency+":P"]; ok {
|
|
1150
|
+
return "curNar:" + f.currency + ":", ""
|
|
1151
|
+
}
|
|
1152
|
+
default:
|
|
1153
|
+
if _, ok := all["cur:"+f.currency+":P"]; ok {
|
|
1154
|
+
return "cur:" + f.currency + ":", ""
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
return "curCode:", f.currency
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// The currency symbol a range shows (its templates are shared by currencies)
|
|
1161
|
+
func tnIntlCurrencySymbol(f *TnIntlNumberFormat) string {
|
|
1162
|
+
prefix, value := tnIntlCurrencyTemplate(f, "other")
|
|
1163
|
+
if value != "" {
|
|
1164
|
+
return value
|
|
1165
|
+
}
|
|
1166
|
+
for _, p := range tnIntlTemplate(f.loc.data, prefix) {
|
|
1167
|
+
if p.kind == 'C' && p.text != "" {
|
|
1168
|
+
return p.text
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
return f.currency
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
// A template by its key prefix (the P/N suffix picked by the sign)
|
|
1175
|
+
func tnIntlTemplate(data string, prefix string) []tnIntlPart {
|
|
1176
|
+
all := tnIntlNumParts(data)
|
|
1177
|
+
if tpl, ok := all[prefix+"P"]; ok {
|
|
1178
|
+
return tpl
|
|
1179
|
+
}
|
|
1180
|
+
if tpl, ok := all[prefix]; ok {
|
|
1181
|
+
return tpl
|
|
1182
|
+
}
|
|
1183
|
+
return all["decP"]
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// The negative variant of a template: the minus sign part in front
|
|
1187
|
+
func tnIntlNegTemplate(tpl []tnIntlPart) []tnIntlPart {
|
|
1188
|
+
for _, p := range tpl {
|
|
1189
|
+
if p.kind == 'M' {
|
|
1190
|
+
return nil // already the negative template
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
out := make([]tnIntlPart, 0, len(tpl)+1)
|
|
1194
|
+
out = append(out, tnIntlPart{kind: 'M'})
|
|
1195
|
+
return append(out, tpl...)
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
// A number's parts as JS parts (the integer/group/decimal/fraction kinds)
|
|
1199
|
+
func tnIntlNumJSParts(num []tnIntlPart, unitTag string) []interface{} {
|
|
1200
|
+
out := []interface{}{}
|
|
1201
|
+
for _, p := range num {
|
|
1202
|
+
kind := "integer"
|
|
1203
|
+
switch p.kind {
|
|
1204
|
+
case 'g':
|
|
1205
|
+
kind = "group"
|
|
1206
|
+
case 'd':
|
|
1207
|
+
kind = "decimal"
|
|
1208
|
+
case 'f':
|
|
1209
|
+
kind = "fraction"
|
|
1210
|
+
}
|
|
1211
|
+
m := tnIntlObj("type", kind, "value", p.text)
|
|
1212
|
+
if unitTag != "" {
|
|
1213
|
+
m.Set("unit", unitTag)
|
|
1214
|
+
}
|
|
1215
|
+
out = append(out, m)
|
|
1216
|
+
}
|
|
1217
|
+
return out
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
// Expanding a number template into parts
|
|
1221
|
+
func tnIntlNumberEmit(f *TnIntlNumberFormat, sign string, num []tnIntlPart, tpl []tnIntlPart, currencyValue string, skipSign bool) []interface{} {
|
|
1222
|
+
data := f.loc.data
|
|
1223
|
+
out := []interface{}{}
|
|
1224
|
+
// the sign goes first when the template doesn't carry it (signDisplay
|
|
1225
|
+
// always / exceptZero render "+$1.00")
|
|
1226
|
+
if (f.sign == "always" || f.sign == "exceptZero") && !skipSign && sign != "" && (len(tpl) == 0 || tpl[0].kind != 'M') {
|
|
1227
|
+
out = append(out, tnIntlObj("type", "plusSign", "value", sign))
|
|
1228
|
+
skipSign = true
|
|
1229
|
+
}
|
|
1230
|
+
for _, p := range tpl {
|
|
1231
|
+
switch p.kind {
|
|
1232
|
+
case 'N':
|
|
1233
|
+
out = append(out, tnIntlNumJSParts(num, "")...)
|
|
1234
|
+
case 'M':
|
|
1235
|
+
if !skipSign && sign != "" {
|
|
1236
|
+
out = append(out, tnIntlObj("type", "minusSign", "value", sign))
|
|
1237
|
+
}
|
|
1238
|
+
case 'P':
|
|
1239
|
+
if !skipSign && sign != "" {
|
|
1240
|
+
out = append(out, tnIntlObj("type", "plusSign", "value", sign))
|
|
1241
|
+
}
|
|
1242
|
+
case 'C':
|
|
1243
|
+
v := p.text
|
|
1244
|
+
if currencyValue != "" {
|
|
1245
|
+
v = currencyValue
|
|
1246
|
+
}
|
|
1247
|
+
out = append(out, tnIntlObj("type", "currency", "value", v))
|
|
1248
|
+
case 'p':
|
|
1249
|
+
out = append(out, tnIntlObj("type", "percentSign", "value", p.text))
|
|
1250
|
+
case 'U':
|
|
1251
|
+
out = append(out, tnIntlObj("type", "unit", "value", p.text))
|
|
1252
|
+
case 'K':
|
|
1253
|
+
out = append(out, tnIntlObj("type", "compact", "value", p.text))
|
|
1254
|
+
case 'E':
|
|
1255
|
+
out = append(out, tnIntlObj("type", "exponentSeparator", "value", p.text))
|
|
1256
|
+
case 'X':
|
|
1257
|
+
out = append(out, tnIntlObj("type", "exponentMinusSign", "value", tnIntlNumSym(data, "minus")))
|
|
1258
|
+
case 'x':
|
|
1259
|
+
out = append(out, tnIntlObj("type", "exponentInteger", "value", tnIntlMapDigits(p.text, tnIntlDigitsFor(f.loc))))
|
|
1260
|
+
default:
|
|
1261
|
+
if p.text != "" {
|
|
1262
|
+
out = append(out, tnIntlObj("type", "literal", "value", p.text))
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
return out
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
// The parts of a formatted number (the standard notation)
|
|
1270
|
+
func TnIntlNumberFormatParts(f *TnIntlNumberFormat, x interface{}) []interface{} {
|
|
1271
|
+
value, fracLen, negative, negativeZero, isNaN, isInf := tnIntlNumberDigits(f, x)
|
|
1272
|
+
data := f.loc.data
|
|
1273
|
+
if isNaN {
|
|
1274
|
+
return []interface{}{tnIntlObj("type", "literal", "value", "NaN")}
|
|
1275
|
+
}
|
|
1276
|
+
if isInf {
|
|
1277
|
+
out := []interface{}{}
|
|
1278
|
+
if negative && f.sign != "never" {
|
|
1279
|
+
out = append(out, tnIntlObj("type", "literal", "value", tnIntlNumSym(data, "minus")))
|
|
1280
|
+
}
|
|
1281
|
+
out = append(out, tnIntlObj("type", "literal", "value", tnIntlNumSym(data, "inf")))
|
|
1282
|
+
return out
|
|
1283
|
+
}
|
|
1284
|
+
digits, point, fracShown := tnIntlRoundStandard(f, value, fracLen)
|
|
1285
|
+
sign, num := tnIntlRenderNumber(f, digits, point, fracShown, negative, negativeZero)
|
|
1286
|
+
cat := tnIntlPluralOfDigits(f.loc.tag, tnIntlShown(digits, point, fracShown))
|
|
1287
|
+
prefix := "dec"
|
|
1288
|
+
currencyValue := ""
|
|
1289
|
+
switch f.style {
|
|
1290
|
+
case "percent":
|
|
1291
|
+
prefix = "pct"
|
|
1292
|
+
case "currency":
|
|
1293
|
+
prefix, currencyValue = tnIntlCurrencyTemplate(f, cat)
|
|
1294
|
+
case "unit":
|
|
1295
|
+
prefix = "u:" + f.unit + ":" + f.unitDisplay[0:1] + ":" + cat
|
|
1296
|
+
}
|
|
1297
|
+
tpl := tnIntlTemplate(data, prefix)
|
|
1298
|
+
if negative || (negativeZero && (f.sign == "auto" || f.sign == "always" || f.sign == "exceptZero")) {
|
|
1299
|
+
// the locale's own negative pattern (nl "€ -1.234,56"), else the minus in front
|
|
1300
|
+
if neg, ok := tnIntlNumParts(data)[prefix+"N"]; ok {
|
|
1301
|
+
tpl = neg
|
|
1302
|
+
} else if neg := tnIntlNegTemplate(tpl); neg != nil {
|
|
1303
|
+
tpl = neg
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
skipSign := f.sign == "never" || (f.sign == "negative" && !negative && !negativeZero)
|
|
1307
|
+
return tnIntlNumberEmit(f, sign, num, tpl, currencyValue, skipSign)
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
// The number as shown: the integer digits and the fraction digits displayed
|
|
1311
|
+
// ("1" for 1 at three fraction digits, not "1.000": the plural operands)
|
|
1312
|
+
func tnIntlShown(digits string, point int, fracShown int) string {
|
|
1313
|
+
intPart, frac := "0", ""
|
|
1314
|
+
switch {
|
|
1315
|
+
case point > len(digits):
|
|
1316
|
+
intPart = digits + strings.Repeat("0", point-len(digits))
|
|
1317
|
+
case point > 0:
|
|
1318
|
+
intPart, frac = digits[:point], digits[point:]
|
|
1319
|
+
default:
|
|
1320
|
+
frac = digits
|
|
1321
|
+
}
|
|
1322
|
+
for len(frac) < fracShown {
|
|
1323
|
+
frac += "0"
|
|
1324
|
+
}
|
|
1325
|
+
if len(frac) > fracShown {
|
|
1326
|
+
frac = frac[:fracShown]
|
|
1327
|
+
}
|
|
1328
|
+
if frac == "" {
|
|
1329
|
+
return intPart
|
|
1330
|
+
}
|
|
1331
|
+
return intPart + "." + frac
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
func tnIntlPointed(digits string, point int) string {
|
|
1335
|
+
if point > 0 && point <= len(digits) {
|
|
1336
|
+
return digits[:point] + "." + digits[point:]
|
|
1337
|
+
}
|
|
1338
|
+
return digits
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
// The exponent of a value from its digits and integer-digit count (the
|
|
1342
|
+
// position of its first significant digit: "000012" with point 1 is 1.2E-4)
|
|
1343
|
+
func tnIntlExponentOf(digits string, point int) int {
|
|
1344
|
+
for i := 0; i < len(digits); i++ {
|
|
1345
|
+
if digits[i] != '0' {
|
|
1346
|
+
return point - 1 - i
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
return 0
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
// The parts with notation scientific / engineering
|
|
1353
|
+
func TnIntlNumberFormatSci(f *TnIntlNumberFormat, x interface{}) []interface{} {
|
|
1354
|
+
value, fracLen, negative, negativeZero, isNaN, isInf := tnIntlNumberDigits(f, x)
|
|
1355
|
+
data := f.loc.data
|
|
1356
|
+
if isNaN || isInf {
|
|
1357
|
+
return TnIntlNumberFormatParts(f, x)
|
|
1358
|
+
}
|
|
1359
|
+
point := len(value) - fracLen
|
|
1360
|
+
exp := tnIntlExponentOf(value, point)
|
|
1361
|
+
if f.notation == "engineering" {
|
|
1362
|
+
exp = exp - ((exp%3)+3)%3
|
|
1363
|
+
}
|
|
1364
|
+
// the mantissa: the point moved left by the exponent (one integer digit;
|
|
1365
|
+
// one to three for engineering)
|
|
1366
|
+
mant := value
|
|
1367
|
+
mantPoint := point - exp
|
|
1368
|
+
if mantPoint > len(mant) {
|
|
1369
|
+
mant += strings.Repeat("0", mantPoint-len(mant))
|
|
1370
|
+
} else if mantPoint <= 0 {
|
|
1371
|
+
mant = strings.Repeat("0", 1-mantPoint) + mant
|
|
1372
|
+
mantPoint = 1
|
|
1373
|
+
}
|
|
1374
|
+
mantFracLen := len(mant) - mantPoint
|
|
1375
|
+
if mantFracLen < 0 {
|
|
1376
|
+
mantFracLen = 0
|
|
1377
|
+
}
|
|
1378
|
+
md, mpoint, mfrac := tnIntlRoundStandard(f, mant, mantFracLen)
|
|
1379
|
+
sign, num := tnIntlRenderNumber(f, md, mpoint, mfrac, negative, negativeZero)
|
|
1380
|
+
tpl := tnIntlTemplate(data, "sci")
|
|
1381
|
+
if negative || (negativeZero && (f.sign == "auto" || f.sign == "always" || f.sign == "exceptZero")) {
|
|
1382
|
+
if neg := tnIntlNegTemplate(tpl); neg != nil {
|
|
1383
|
+
tpl = neg
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
skipSign := f.sign == "never" || (f.sign == "negative" && !negative && !negativeZero)
|
|
1387
|
+
expDigits := strconv.Itoa(exp)
|
|
1388
|
+
if exp < 0 {
|
|
1389
|
+
expDigits = strconv.Itoa(-exp)
|
|
1390
|
+
}
|
|
1391
|
+
out := []interface{}{}
|
|
1392
|
+
for _, p := range tpl {
|
|
1393
|
+
switch p.kind {
|
|
1394
|
+
case 'N':
|
|
1395
|
+
out = append(out, tnIntlNumJSParts(num, "")...)
|
|
1396
|
+
case 'M':
|
|
1397
|
+
if !skipSign && sign != "" {
|
|
1398
|
+
out = append(out, tnIntlObj("type", "minusSign", "value", sign))
|
|
1399
|
+
}
|
|
1400
|
+
case 'P':
|
|
1401
|
+
if !skipSign && sign != "" {
|
|
1402
|
+
out = append(out, tnIntlObj("type", "plusSign", "value", sign))
|
|
1403
|
+
}
|
|
1404
|
+
case 'E':
|
|
1405
|
+
out = append(out, tnIntlObj("type", "exponentSeparator", "value", p.text))
|
|
1406
|
+
case 'X':
|
|
1407
|
+
if exp < 0 {
|
|
1408
|
+
out = append(out, tnIntlObj("type", "exponentMinusSign", "value", tnIntlNumSym(data, "minus")))
|
|
1409
|
+
}
|
|
1410
|
+
case 'x':
|
|
1411
|
+
out = append(out, tnIntlObj("type", "exponentInteger", "value", tnIntlMapDigits(expDigits, tnIntlDigitsFor(f.loc))))
|
|
1412
|
+
default:
|
|
1413
|
+
if p.text != "" {
|
|
1414
|
+
out = append(out, tnIntlObj("type", "literal", "value", p.text))
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
return out
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
// The parts with notation compact
|
|
1422
|
+
func TnIntlNumberFormatCompact(f *TnIntlNumberFormat, x interface{}) []interface{} {
|
|
1423
|
+
value, fracLen, negative, negativeZero, isNaN, isInf := tnIntlNumberDigits(f, x)
|
|
1424
|
+
if isNaN || isInf {
|
|
1425
|
+
return TnIntlNumberFormatParts(f, x)
|
|
1426
|
+
}
|
|
1427
|
+
point := len(value) - fracLen
|
|
1428
|
+
exp := tnIntlExponentOf(value, point)
|
|
1429
|
+
p := exp
|
|
1430
|
+
if p > 14 {
|
|
1431
|
+
p = 14 // beyond the table: the trillions' pattern ("1000T")
|
|
1432
|
+
}
|
|
1433
|
+
styleKey := map[string]string{"short": "S", "long": "L"}[f.compactDisplay]
|
|
1434
|
+
divisor := -1
|
|
1435
|
+
if p >= 3 {
|
|
1436
|
+
// (the locale's own table only: en's thousands don't apply to de)
|
|
1437
|
+
if d, ok := tnIntlNumberNames[f.loc.data]["cmpD:"+styleKey+":"+strconv.Itoa(p)]; ok {
|
|
1438
|
+
divisor, _ = strconv.Atoi(d)
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
// the rounding: the options', or (compactAuto) 0 fraction digits when
|
|
1442
|
+
// the mantissa has two integer digits or more, else 2 significant digits
|
|
1443
|
+
rounder := func(intDigits int) *TnIntlNumberFormat {
|
|
1444
|
+
if !f.compactAuto {
|
|
1445
|
+
return f
|
|
1446
|
+
}
|
|
1447
|
+
g := *f
|
|
1448
|
+
g.useSD, g.minFD, g.maxFD = false, 0, 0
|
|
1449
|
+
if intDigits < 2 {
|
|
1450
|
+
g.maxFD = 1
|
|
1451
|
+
}
|
|
1452
|
+
return &g
|
|
1453
|
+
}
|
|
1454
|
+
if divisor < 0 {
|
|
1455
|
+
// no compact pattern for this magnitude (below 1000, de's 1000): plain
|
|
1456
|
+
g := rounder(max(point, 1))
|
|
1457
|
+
digits, dpoint, dfrac := tnIntlRoundStandard(g, value, fracLen)
|
|
1458
|
+
sign, num := tnIntlRenderNumber(g, digits, dpoint, dfrac, negative, negativeZero)
|
|
1459
|
+
tpl := tnIntlTemplate(f.loc.data, "dec")
|
|
1460
|
+
if negative || (negativeZero && (f.sign == "auto" || f.sign == "always" || f.sign == "exceptZero")) {
|
|
1461
|
+
if neg := tnIntlNegTemplate(tpl); neg != nil {
|
|
1462
|
+
tpl = neg
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
return tnIntlNumberEmit(f, sign, num, tpl, "", f.sign == "never" || (f.sign == "negative" && !negative && !negativeZero))
|
|
1466
|
+
}
|
|
1467
|
+
// the mantissa: the digits divided by 10^divisor
|
|
1468
|
+
mantPoint := point - divisor
|
|
1469
|
+
mant := value
|
|
1470
|
+
if mantPoint <= 0 {
|
|
1471
|
+
mant = strings.Repeat("0", 1-mantPoint) + mant
|
|
1472
|
+
mantPoint = 1
|
|
1473
|
+
}
|
|
1474
|
+
mantFracLen := len(mant) - mantPoint
|
|
1475
|
+
if mantFracLen < 0 {
|
|
1476
|
+
mant += strings.Repeat("0", -mantFracLen)
|
|
1477
|
+
mantFracLen = 0
|
|
1478
|
+
}
|
|
1479
|
+
g := rounder(len(strings.TrimLeft(mant[:mantPoint], "0")))
|
|
1480
|
+
md, mpoint, mfrac := tnIntlRoundStandard(g, mant, mantFracLen)
|
|
1481
|
+
// the mantissa's grouping is min2 unless turned off (beyond the pattern
|
|
1482
|
+
// table ICU keeps grouping off until two groups fit: "1000T", "10,000T")
|
|
1483
|
+
f2 := *g
|
|
1484
|
+
if f2.grouping != "false" {
|
|
1485
|
+
f2.grouping = "min2"
|
|
1486
|
+
}
|
|
1487
|
+
sign, num := tnIntlRenderNumber(&f2, md, mpoint, mfrac, negative, negativeZero)
|
|
1488
|
+
cat := tnIntlPluralOfDigits(f.loc.tag, tnIntlShown(md, mpoint, mfrac))
|
|
1489
|
+
tpl := tnIntlNumParts(f.loc.data)["cmp:"+styleKey+":"+strconv.Itoa(p)+":"+cat]
|
|
1490
|
+
if tpl == nil {
|
|
1491
|
+
tpl = tnIntlNumParts(f.loc.data)["cmp:"+styleKey+":"+strconv.Itoa(p)+":other"]
|
|
1492
|
+
}
|
|
1493
|
+
if tpl == nil {
|
|
1494
|
+
tpl = tnIntlTemplate(f.loc.data, "dec")
|
|
1495
|
+
}
|
|
1496
|
+
// (the compact templates are the positive ones: a minus goes in front)
|
|
1497
|
+
if negative || (negativeZero && (f.sign == "auto" || f.sign == "always" || f.sign == "exceptZero")) {
|
|
1498
|
+
if neg := tnIntlNegTemplate(tpl); neg != nil {
|
|
1499
|
+
tpl = neg
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
out := []interface{}{}
|
|
1503
|
+
skipSign := f.sign == "never" || (f.sign == "negative" && !negative && !negativeZero)
|
|
1504
|
+
if (f.sign == "always" || f.sign == "exceptZero") && !skipSign && sign != "" && (len(tpl) == 0 || tpl[0].kind != 'M') {
|
|
1505
|
+
out = append(out, tnIntlObj("type", "plusSign", "value", sign))
|
|
1506
|
+
skipSign = true
|
|
1507
|
+
}
|
|
1508
|
+
for _, p2 := range tpl {
|
|
1509
|
+
switch p2.kind {
|
|
1510
|
+
case 'N':
|
|
1511
|
+
out = append(out, tnIntlNumJSParts(num, "")...)
|
|
1512
|
+
case 'M':
|
|
1513
|
+
if !skipSign && sign != "" {
|
|
1514
|
+
out = append(out, tnIntlObj("type", "minusSign", "value", sign))
|
|
1515
|
+
}
|
|
1516
|
+
case 'P':
|
|
1517
|
+
if !skipSign && sign != "" {
|
|
1518
|
+
out = append(out, tnIntlObj("type", "plusSign", "value", sign))
|
|
1519
|
+
}
|
|
1520
|
+
case 'K':
|
|
1521
|
+
out = append(out, tnIntlObj("type", "compact", "value", p2.text))
|
|
1522
|
+
default:
|
|
1523
|
+
if p2.text != "" {
|
|
1524
|
+
out = append(out, tnIntlObj("type", "literal", "value", p2.text))
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return out
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
// The dispatch: the notation decides the shape (ICU renders every finite
|
|
1532
|
+
// double in full: 1e21 is 1,000,000,000,000,000,000,000)
|
|
1533
|
+
func TnIntlNumberFormatAny(f *TnIntlNumberFormat, x interface{}) []interface{} {
|
|
1534
|
+
switch f.notation {
|
|
1535
|
+
case "scientific", "engineering":
|
|
1536
|
+
return TnIntlNumberFormatSci(f, x)
|
|
1537
|
+
case "compact":
|
|
1538
|
+
return TnIntlNumberFormatCompact(f, x)
|
|
1539
|
+
}
|
|
1540
|
+
return TnIntlNumberFormatParts(f, x)
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
func TnIntlNumberFormatAnyStr(f *TnIntlNumberFormat, x interface{}) string {
|
|
1544
|
+
var b strings.Builder
|
|
1545
|
+
for _, p := range TnIntlNumberFormatAny(f, x) {
|
|
1546
|
+
b.WriteString(TnJSString(tnIntlGet(p, "value")))
|
|
1547
|
+
}
|
|
1548
|
+
return b.String()
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
// Intl.NumberFormat#format
|
|
1552
|
+
func TnIntlFormatNumber(f *TnIntlNumberFormat, x interface{}) string {
|
|
1553
|
+
return TnIntlNumberFormatAnyStr(f, x)
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
// Intl.NumberFormat#formatRange: the merged template when the two rounded
|
|
1557
|
+
// values are of one magnitude and sign (one shared currency symbol, as de's
|
|
1558
|
+
// "1,20–5,70 €"), else the plain concatenation
|
|
1559
|
+
func TnIntlNumberFormatRangeParts(f *TnIntlNumberFormat, a interface{}, b interface{}) []interface{} {
|
|
1560
|
+
data := f.loc.data
|
|
1561
|
+
va, fa, na, za, iA, infA := tnIntlNumberDigits(f, a)
|
|
1562
|
+
vb, fb, nb, zb, iB, infB := tnIntlNumberDigits(f, b)
|
|
1563
|
+
if iA || iB || infA || infB {
|
|
1564
|
+
out := TnIntlNumberFormatAny(f, a)
|
|
1565
|
+
out = append(out, tnIntlObj("type", "literal", "value", " – "))
|
|
1566
|
+
return append(out, TnIntlNumberFormatAny(f, b)...)
|
|
1567
|
+
}
|
|
1568
|
+
da, pa, sa := tnIntlRoundStandard(f, va, fa)
|
|
1569
|
+
db, pb, sb := tnIntlRoundStandard(f, vb, fb)
|
|
1570
|
+
sameMag := na == nb && tnIntlMagnitude(da, pa) == tnIntlMagnitude(db, pb)
|
|
1571
|
+
key := "rngOther"
|
|
1572
|
+
if f.style == "currency" {
|
|
1573
|
+
key = "rngOtherCur"
|
|
1574
|
+
} else if f.style == "percent" {
|
|
1575
|
+
key = "rngOtherPct"
|
|
1576
|
+
}
|
|
1577
|
+
if sameMag {
|
|
1578
|
+
key = "rngSame"
|
|
1579
|
+
if f.style == "currency" {
|
|
1580
|
+
key = "rngSameCur"
|
|
1581
|
+
} else if f.style == "percent" {
|
|
1582
|
+
key = "rngSamePct"
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
tpl := tnIntlNumParts(data)[key]
|
|
1586
|
+
if tpl == nil {
|
|
1587
|
+
tpl = tnIntlNumParts(data)["rngOther"]
|
|
1588
|
+
}
|
|
1589
|
+
signA, numA := tnIntlRenderNumber(f, da, pa, sa, na, za)
|
|
1590
|
+
signB, numB := tnIntlRenderNumber(f, db, pb, sb, nb, zb)
|
|
1591
|
+
cat := tnIntlPluralOfDigits(f.loc.tag, tnIntlShown(da, pa, sa))
|
|
1592
|
+
out := []interface{}{}
|
|
1593
|
+
for _, p := range tpl {
|
|
1594
|
+
switch p.kind {
|
|
1595
|
+
case 'N':
|
|
1596
|
+
num := numA
|
|
1597
|
+
if p.src == 'e' {
|
|
1598
|
+
num = numB
|
|
1599
|
+
}
|
|
1600
|
+
out = append(out, tnIntlNumJSParts(num, "")...)
|
|
1601
|
+
case 'M':
|
|
1602
|
+
sign := signA
|
|
1603
|
+
if p.src == 'e' {
|
|
1604
|
+
sign = signB
|
|
1605
|
+
}
|
|
1606
|
+
if sign != "" {
|
|
1607
|
+
out = append(out, tnIntlObj("type", "minusSign", "value", sign))
|
|
1608
|
+
}
|
|
1609
|
+
case 'P':
|
|
1610
|
+
sign := signA
|
|
1611
|
+
if p.src == 'e' {
|
|
1612
|
+
sign = signB
|
|
1613
|
+
}
|
|
1614
|
+
if sign != "" {
|
|
1615
|
+
out = append(out, tnIntlObj("type", "plusSign", "value", sign))
|
|
1616
|
+
}
|
|
1617
|
+
case 'C':
|
|
1618
|
+
v := tnIntlCurrencySymbol(f)
|
|
1619
|
+
if f.currencyDisplay == "name" {
|
|
1620
|
+
v = tnIntlNumSym(data, "curName:"+f.currency+":"+cat)
|
|
1621
|
+
}
|
|
1622
|
+
out = append(out, tnIntlObj("type", "currency", "value", v))
|
|
1623
|
+
case 'p':
|
|
1624
|
+
out = append(out, tnIntlObj("type", "percentSign", "value", p.text))
|
|
1625
|
+
default:
|
|
1626
|
+
if p.text != "" {
|
|
1627
|
+
out = append(out, tnIntlObj("type", "literal", "value", p.text))
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
return out
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
func tnIntlMagnitude(digits string, point int) int {
|
|
1635
|
+
if point > 0 {
|
|
1636
|
+
return point - 1
|
|
1637
|
+
}
|
|
1638
|
+
for i := 0; i < len(digits); i++ {
|
|
1639
|
+
if digits[i] != '0' {
|
|
1640
|
+
return -(i + 1)
|
|
1641
|
+
}
|
|
1642
|
+
}
|
|
1643
|
+
return 0
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
func TnIntlNumberFormatRange(f *TnIntlNumberFormat, a interface{}, b interface{}) string {
|
|
1647
|
+
var bld strings.Builder
|
|
1648
|
+
for _, p := range TnIntlNumberFormatRangeParts(f, a, b) {
|
|
1649
|
+
bld.WriteString(TnJSString(tnIntlGet(p, "value")))
|
|
1650
|
+
}
|
|
1651
|
+
return bld.String()
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
// resolvedOptions
|
|
1655
|
+
// (keys in Node's order)
|
|
1656
|
+
func (f *TnIntlNumberFormat) resolvedOptions() interface{} {
|
|
1657
|
+
return f.tnResolved()
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
// The format method as a value ([1, 2].map(nf.format))
|
|
1661
|
+
func (f *TnIntlNumberFormat) Get_format() func(interface{}) string {
|
|
1662
|
+
return func(x interface{}) string { return TnIntlNumberFormatAnyStr(f, x) }
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
func (f *TnIntlNumberFormat) tnResolved() interface{} {
|
|
1666
|
+
out := tnIntlObj()
|
|
1667
|
+
out.Set("locale", f.loc.id)
|
|
1668
|
+
nu := f.loc.tag.TypeForKey("nu")
|
|
1669
|
+
if nu == "" {
|
|
1670
|
+
nu = "latn"
|
|
1671
|
+
}
|
|
1672
|
+
out.Set("numberingSystem", nu)
|
|
1673
|
+
out.Set("style", f.style)
|
|
1674
|
+
if f.style == "currency" {
|
|
1675
|
+
out.Set("currency", f.currency)
|
|
1676
|
+
out.Set("currencyDisplay", f.currencyDisplay)
|
|
1677
|
+
out.Set("currencySign", "standard")
|
|
1678
|
+
}
|
|
1679
|
+
if f.style == "unit" {
|
|
1680
|
+
out.Set("unit", f.unit)
|
|
1681
|
+
out.Set("unitDisplay", f.unitDisplay)
|
|
1682
|
+
}
|
|
1683
|
+
out.Set("minimumIntegerDigits", float64(f.minInt))
|
|
1684
|
+
if f.useSD {
|
|
1685
|
+
out.Set("minimumSignificantDigits", float64(f.minSD))
|
|
1686
|
+
out.Set("maximumSignificantDigits", float64(f.maxSD))
|
|
1687
|
+
} else {
|
|
1688
|
+
out.Set("minimumFractionDigits", float64(f.minFD))
|
|
1689
|
+
out.Set("maximumFractionDigits", float64(f.maxFD))
|
|
1690
|
+
}
|
|
1691
|
+
switch f.grouping {
|
|
1692
|
+
case "false":
|
|
1693
|
+
out.Set("useGrouping", false)
|
|
1694
|
+
case "true":
|
|
1695
|
+
out.Set("useGrouping", "always")
|
|
1696
|
+
default:
|
|
1697
|
+
out.Set("useGrouping", f.grouping)
|
|
1698
|
+
}
|
|
1699
|
+
out.Set("notation", f.notation)
|
|
1700
|
+
if f.notation == "compact" {
|
|
1701
|
+
out.Set("compactDisplay", f.compactDisplay)
|
|
1702
|
+
}
|
|
1703
|
+
out.Set("signDisplay", f.sign)
|
|
1704
|
+
out.Set("roundingIncrement", float64(f.increment))
|
|
1705
|
+
out.Set("roundingMode", f.mode)
|
|
1706
|
+
out.Set("roundingPriority", "auto")
|
|
1707
|
+
out.Set("trailingZeroDisplay", f.trailing)
|
|
1708
|
+
return out
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
// n.toLocaleString(locales, options)
|
|
1712
|
+
func TnIntlNumLocale(x interface{}, locales interface{}, options interface{}) string {
|
|
1713
|
+
f := TnNewIntlNumberFormat(locales, options)
|
|
1714
|
+
return TnIntlNumberFormatAnyStr(f, x)
|
|
1715
|
+
}`;
|
|
1716
|
+
const intlDateGo = `// Intl.DateTimeFormat: the generated patterns probed by example, with every
|
|
1717
|
+
// field substituted at run time
|
|
1718
|
+
|
|
1719
|
+
// The date name and pattern tables (en as the guard)
|
|
1720
|
+
func tnIntlName(data string, key string) string {
|
|
1721
|
+
if m := tnIntlDateNames[data]; m != nil {
|
|
1722
|
+
if v, ok := m[key]; ok {
|
|
1723
|
+
return v
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
if m := tnIntlDateNames["en"]; m != nil {
|
|
1727
|
+
return m[key]
|
|
1728
|
+
}
|
|
1729
|
+
return ""
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
func tnIntlDatePartsOf(data string) map[string][]tnIntlPart {
|
|
1733
|
+
if m := tnIntlDateParts[data]; m != nil {
|
|
1734
|
+
return m
|
|
1735
|
+
}
|
|
1736
|
+
return tnIntlDateParts["en"]
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
type TnIntlDateTimeFormat struct {
|
|
1740
|
+
loc *TnIntlLoc
|
|
1741
|
+
zoneID string
|
|
1742
|
+
zone *time.Location
|
|
1743
|
+
pattern []tnIntlPart
|
|
1744
|
+
id string
|
|
1745
|
+
dateStyle string
|
|
1746
|
+
timeStyle string
|
|
1747
|
+
opts map[string]string
|
|
1748
|
+
hc string
|
|
1749
|
+
frac int
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
// A time zone: the canonical IANA id (matched case-insensitively, spaces for
|
|
1753
|
+
// underscores, as Node's ids are) and its location (UTC, a fixed offset or
|
|
1754
|
+
// time.LoadLocation's, with time/tzdata embedded)
|
|
1755
|
+
var tnIntlZoneCache sync.Map
|
|
1756
|
+
|
|
1757
|
+
func tnIntlZoneOf(id string) (string, *time.Location) {
|
|
1758
|
+
id = strings.TrimSpace(id)
|
|
1759
|
+
if strings.EqualFold(id, "UTC") {
|
|
1760
|
+
return "UTC", time.UTC
|
|
1761
|
+
}
|
|
1762
|
+
// a fixed offset: ±HH[:MM[:SS]]
|
|
1763
|
+
if len(id) >= 3 && (id[0] == '+' || id[0] == '-') {
|
|
1764
|
+
rest := strings.ReplaceAll(id[1:], ":", "")
|
|
1765
|
+
if len(rest) == 2 || len(rest) == 4 || len(rest) == 6 {
|
|
1766
|
+
digits := true
|
|
1767
|
+
for _, c := range rest {
|
|
1768
|
+
if c < '0' || c > '9' {
|
|
1769
|
+
digits = false
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
if digits {
|
|
1773
|
+
h, _ := strconv.Atoi(rest[0:2])
|
|
1774
|
+
m, s := 0, 0
|
|
1775
|
+
if len(rest) >= 4 {
|
|
1776
|
+
m, _ = strconv.Atoi(rest[2:4])
|
|
1777
|
+
}
|
|
1778
|
+
if len(rest) == 6 {
|
|
1779
|
+
s, _ = strconv.Atoi(rest[4:6])
|
|
1780
|
+
}
|
|
1781
|
+
if h <= 23 && m <= 59 && s <= 59 {
|
|
1782
|
+
off := h*3600 + m*60 + s
|
|
1783
|
+
if id[0] == '-' {
|
|
1784
|
+
off = -off
|
|
1785
|
+
}
|
|
1786
|
+
return id, time.FixedZone("", off)
|
|
1787
|
+
}
|
|
1788
|
+
tnIntlRangeError("Invalid time zone")
|
|
1789
|
+
}
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
// an IANA id, matched case-insensitively against the supported list
|
|
1793
|
+
key := strings.ToLower(strings.ReplaceAll(id, " ", "_"))
|
|
1794
|
+
for _, zone := range tnIntlTimeZones {
|
|
1795
|
+
if strings.ToLower(zone) == key {
|
|
1796
|
+
loc, err := time.LoadLocation(zone)
|
|
1797
|
+
if err != nil {
|
|
1798
|
+
tnIntlRangeError("Invalid time zone specified: " + id)
|
|
1799
|
+
}
|
|
1800
|
+
return zone, loc
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
// a link or a renamed zone: the id ICU reports (Asia/Kolkata → Asia/Calcutta)
|
|
1804
|
+
if canonical, ok := tnIntlZoneAliases[key]; ok {
|
|
1805
|
+
if canonical == "UTC" {
|
|
1806
|
+
return "UTC", time.UTC
|
|
1807
|
+
}
|
|
1808
|
+
if loc, err := time.LoadLocation(canonical); err == nil {
|
|
1809
|
+
return canonical, loc
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
tnIntlRangeError("Invalid time zone specified: " + id)
|
|
1813
|
+
return "", nil
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
// The system zone's IANA id, for the default timeZone option
|
|
1817
|
+
func tnIntlLocalZoneID() string {
|
|
1818
|
+
if id := tnTemporalSystemZoneID(); id != "" {
|
|
1819
|
+
return id
|
|
1820
|
+
}
|
|
1821
|
+
return "UTC"
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
func TnNewIntlDateTimeFormat(locales interface{}, options interface{}) *TnIntlDateTimeFormat {
|
|
1825
|
+
loc := TnIntlResolve(locales)
|
|
1826
|
+
f := &TnIntlDateTimeFormat{loc: loc, opts: map[string]string{}, frac: 0}
|
|
1827
|
+
// the time zone: an IANA id (case-insensitive) or a fixed offset; the
|
|
1828
|
+
// system zone when absent, as Node's are
|
|
1829
|
+
zoneID := ""
|
|
1830
|
+
if v, ok := tnIntlOptStr(options, "timeZone"); ok {
|
|
1831
|
+
zoneID = v
|
|
1832
|
+
} else {
|
|
1833
|
+
zoneID = tnIntlLocalZoneID()
|
|
1834
|
+
}
|
|
1835
|
+
canonical, zone := tnIntlZoneOf(zoneID)
|
|
1836
|
+
if cached, ok := tnIntlZoneCache.Load(canonical); ok {
|
|
1837
|
+
f.zoneID, f.zone = canonical, cached.(*time.Location)
|
|
1838
|
+
} else {
|
|
1839
|
+
tnIntlZoneCache.Store(canonical, zone)
|
|
1840
|
+
f.zoneID, f.zone = canonical, zone
|
|
1841
|
+
}
|
|
1842
|
+
// hour cycle: the options, then the -u-hc- extension, then the locale's
|
|
1843
|
+
if v, ok := tnIntlOptStr(options, "hourCycle"); ok {
|
|
1844
|
+
f.hc = v
|
|
1845
|
+
} else if hc := loc.tag.TypeForKey("hc"); hc != "" {
|
|
1846
|
+
f.hc = hc
|
|
1847
|
+
}
|
|
1848
|
+
// (hour12 is a boolean: it overrides hourCycle; true keeps an h11 locale's h11)
|
|
1849
|
+
if options != nil {
|
|
1850
|
+
if v := TnGetValue(options, "hour12"); v != nil {
|
|
1851
|
+
def := tnIntlName(loc.data, "hc")
|
|
1852
|
+
if TnTruthy(v) {
|
|
1853
|
+
f.hc = "h12"
|
|
1854
|
+
if def == "h11" {
|
|
1855
|
+
f.hc = "h11"
|
|
1856
|
+
}
|
|
1857
|
+
} else {
|
|
1858
|
+
f.hc = "h23"
|
|
1859
|
+
if def == "h24" {
|
|
1860
|
+
f.hc = "h24"
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
if v, ok := tnIntlOptFloat(options, "fractionalSecondDigits"); ok {
|
|
1866
|
+
n := int(v)
|
|
1867
|
+
if v != math.Trunc(v) || n < 1 || n > 3 {
|
|
1868
|
+
tnIntlRangeError("fractionalSecondDigits value is out of range.")
|
|
1869
|
+
}
|
|
1870
|
+
f.frac = n
|
|
1871
|
+
}
|
|
1872
|
+
f.dateStyle, _ = tnIntlOptStr(options, "dateStyle")
|
|
1873
|
+
f.timeStyle, _ = tnIntlOptStr(options, "timeStyle")
|
|
1874
|
+
if f.dateStyle != "" && !tnIntlHasString([]string{"full", "long", "medium", "short"}, f.dateStyle) {
|
|
1875
|
+
tnIntlRangeError("Invalid dateStyle: " + f.dateStyle)
|
|
1876
|
+
}
|
|
1877
|
+
if f.timeStyle != "" && !tnIntlHasString([]string{"full", "long", "medium", "short"}, f.timeStyle) {
|
|
1878
|
+
tnIntlRangeError("Invalid timeStyle: " + f.timeStyle)
|
|
1879
|
+
}
|
|
1880
|
+
f.opts = tnIntlDateOptFields(options)
|
|
1881
|
+
// styles exclude the field options; without either, the date's numeric
|
|
1882
|
+
// fields (ToDateTimeOptions "any", "date")
|
|
1883
|
+
if f.dateStyle != "" || f.timeStyle != "" {
|
|
1884
|
+
style := "dateStyle"
|
|
1885
|
+
if f.dateStyle == "" {
|
|
1886
|
+
style = "timeStyle"
|
|
1887
|
+
}
|
|
1888
|
+
for _, k := range []string{"weekday", "era", "year", "month", "day", "dayPeriod", "hour", "minute", "second", "timeZoneName"} {
|
|
1889
|
+
if _, ok := f.opts[k]; ok {
|
|
1890
|
+
panic(TnNodeError("TypeError", "", "Can't set option "+k+" when "+style+" is used"))
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
if f.frac > 0 {
|
|
1894
|
+
panic(TnNodeError("TypeError", "", "Can't set option fractionalSecondDigits when "+style+" is used"))
|
|
1895
|
+
}
|
|
1896
|
+
} else {
|
|
1897
|
+
named := false
|
|
1898
|
+
for _, k := range []string{"weekday", "year", "month", "day", "dayPeriod", "hour", "minute", "second"} {
|
|
1899
|
+
if _, ok := f.opts[k]; ok {
|
|
1900
|
+
named = true
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
if !named && f.frac == 0 {
|
|
1904
|
+
f.opts["year"], f.opts["month"], f.opts["day"] = "numeric", "numeric", "numeric"
|
|
1905
|
+
}
|
|
1906
|
+
}
|
|
1907
|
+
f.pattern, f.id = tnIntlDatePattern(f)
|
|
1908
|
+
return f
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
// The date/time fields the options name, with their widths
|
|
1912
|
+
func tnIntlDateOptFields(options interface{}) map[string]string {
|
|
1913
|
+
out := map[string]string{}
|
|
1914
|
+
for _, key := range []string{"weekday", "era", "year", "month", "day", "hour", "minute", "second", "timeZoneName", "dayPeriod"} {
|
|
1915
|
+
if v, ok := tnIntlOptStr(options, key); ok {
|
|
1916
|
+
out[key] = v
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
return out
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
// The pattern for the options: the styles' ids, else the skeleton nearest the
|
|
1923
|
+
// requested fields (the same field set first, then a composition of the date
|
|
1924
|
+
// and time halves)
|
|
1925
|
+
func tnIntlDatePattern(f *TnIntlDateTimeFormat) ([]tnIntlPart, string) {
|
|
1926
|
+
data := f.loc.data
|
|
1927
|
+
twelve := ""
|
|
1928
|
+
if f.hc == "h11" || f.hc == "h12" {
|
|
1929
|
+
twelve = "12"
|
|
1930
|
+
} else if f.hc == "h23" || f.hc == "h24" {
|
|
1931
|
+
twelve = "24"
|
|
1932
|
+
}
|
|
1933
|
+
if f.dateStyle != "" && f.timeStyle != "" {
|
|
1934
|
+
if f.dateStyle == f.timeStyle {
|
|
1935
|
+
if twelve != "" {
|
|
1936
|
+
if p := tnIntlDatePartsOf(data)["ft"+f.dateStyle+twelve]; p != nil {
|
|
1937
|
+
return p, "ft" + f.dateStyle + twelve
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
return tnIntlDatePartsOf(data)["ft"+f.dateStyle], "ft" + f.dateStyle
|
|
1941
|
+
}
|
|
1942
|
+
// different styles: the date style's pattern, its joiner (" at " for
|
|
1943
|
+
// full / long), then the time style's pattern
|
|
1944
|
+
tid := "t" + f.timeStyle
|
|
1945
|
+
timeParts := tnIntlDatePartsOf(data)[tid+twelve]
|
|
1946
|
+
if timeParts == nil {
|
|
1947
|
+
timeParts = tnIntlDatePartsOf(data)[tid]
|
|
1948
|
+
}
|
|
1949
|
+
out := append([]tnIntlPart{}, tnIntlDatePartsOf(data)["d"+f.dateStyle]...)
|
|
1950
|
+
out = append(out, tnIntlPart{kind: 'l', text: tnIntlStyleJoiner(f.loc, f.dateStyle)})
|
|
1951
|
+
return append(out, timeParts...), "ft" + f.dateStyle + "|" + f.timeStyle
|
|
1952
|
+
}
|
|
1953
|
+
if f.dateStyle != "" {
|
|
1954
|
+
return tnIntlDatePartsOf(data)["d"+f.dateStyle], "d" + f.dateStyle
|
|
1955
|
+
}
|
|
1956
|
+
if f.timeStyle != "" {
|
|
1957
|
+
id := "t" + f.timeStyle
|
|
1958
|
+
if twelve != "" {
|
|
1959
|
+
if p := tnIntlDatePartsOf(data)[id+twelve]; p != nil {
|
|
1960
|
+
return p, id + twelve
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
return tnIntlDatePartsOf(data)[id], id
|
|
1964
|
+
}
|
|
1965
|
+
fields := map[string]string{}
|
|
1966
|
+
for k, v := range f.opts {
|
|
1967
|
+
fields[k] = v
|
|
1968
|
+
}
|
|
1969
|
+
ren := map[string]string{"numeric": "n", "2-digit": "2", "long": "l", "short": "s", "narrow": "r", "shortOffset": "o", "longOffset": "O", "shortGeneric": "g", "longGeneric": "G"}
|
|
1970
|
+
for k, v := range fields {
|
|
1971
|
+
if w, ok := ren[v]; ok {
|
|
1972
|
+
fields[k] = w
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
if _, ok := fields["second"]; !ok && f.frac > 0 {
|
|
1976
|
+
fields["second"] = "numeric"
|
|
1977
|
+
}
|
|
1978
|
+
for k, v := range fields {
|
|
1979
|
+
if w, ok := ren[v]; ok {
|
|
1980
|
+
fields[k] = w
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
for _, sk := range tnIntlSkeletons {
|
|
1984
|
+
if tnIntlSkeletonMatches(sk, fields, f, true) {
|
|
1985
|
+
if p := tnIntlDatePartsOf(data)[sk.id]; p != nil {
|
|
1986
|
+
return p, sk.id
|
|
1987
|
+
}
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
// the same field set with other widths: the closest (equal widths count
|
|
1991
|
+
// most; a numeric field must not get a name, nor the reverse)
|
|
1992
|
+
best, bestScore := "", 0
|
|
1993
|
+
for _, sk := range tnIntlSkeletons {
|
|
1994
|
+
if !tnIntlSkeletonMatches(sk, fields, f, false) || tnIntlDatePartsOf(data)[sk.id] == nil {
|
|
1995
|
+
continue
|
|
1996
|
+
}
|
|
1997
|
+
score := 1
|
|
1998
|
+
for _, f2 := range sk.fields {
|
|
1999
|
+
kv := strings.SplitN(f2, ":", 2)
|
|
2000
|
+
w := fields[kv[0]]
|
|
2001
|
+
numericWant, numericHas := w == "n" || w == "2", kv[1] == "n" || kv[1] == "2"
|
|
2002
|
+
switch {
|
|
2003
|
+
case w == kv[1]:
|
|
2004
|
+
score += 2
|
|
2005
|
+
case numericWant == numericHas:
|
|
2006
|
+
score++
|
|
2007
|
+
default:
|
|
2008
|
+
score -= 100
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
if score > bestScore {
|
|
2012
|
+
best, bestScore = sk.id, score
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
if best != "" {
|
|
2016
|
+
return tnIntlAdjustWidths(tnIntlDatePartsOf(data)[best], fields), best
|
|
2017
|
+
}
|
|
2018
|
+
parts, id := tnIntlComposed(f, fields)
|
|
2019
|
+
return tnIntlAdjustWidths(parts, fields), id
|
|
2020
|
+
}
|
|
2021
|
+
|
|
2022
|
+
// A pattern's parts with the requested widths where they differ only within
|
|
2023
|
+
// a kind (numeric vs 2-digit, long vs short vs narrow), as ICU adjusts a
|
|
2024
|
+
// skeleton's best pattern
|
|
2025
|
+
func tnIntlAdjustWidths(parts []tnIntlPart, fields map[string]string) []tnIntlPart {
|
|
2026
|
+
keyOf := map[byte]string{'w': "weekday", 'e': "era", 'y': "year", 'M': "month", 'd': "day", 'm': "minute", 's': "second", 'h': "hour", 'H': "hour", '1': "hour", 'z': "timeZoneName"}
|
|
2027
|
+
numeric := func(w byte) bool { return w == 'n' || w == '2' }
|
|
2028
|
+
out := make([]tnIntlPart, len(parts))
|
|
2029
|
+
copy(out, parts)
|
|
2030
|
+
for i, p := range out {
|
|
2031
|
+
key, ok := keyOf[p.kind]
|
|
2032
|
+
if !ok {
|
|
2033
|
+
continue
|
|
2034
|
+
}
|
|
2035
|
+
want, ok := fields[key]
|
|
2036
|
+
if !ok || len(want) != 1 {
|
|
2037
|
+
continue
|
|
2038
|
+
}
|
|
2039
|
+
w := want[0]
|
|
2040
|
+
// (minutes and seconds stay 2-digit inside a time, as in ICU)
|
|
2041
|
+
if (p.kind == 'm' || p.kind == 's') && w == 'n' {
|
|
2042
|
+
continue
|
|
2043
|
+
}
|
|
2044
|
+
if p.kind == 'z' || numeric(w) == numeric(p.width) {
|
|
2045
|
+
out[i].width = w
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
return out
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
type tnIntlSkeleton struct {
|
|
2052
|
+
id string
|
|
2053
|
+
fields []string // "key:width"
|
|
2054
|
+
cycle string // "" default, "12", "24"
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
var tnIntlSkeletons = []tnIntlSkeleton{
|
|
2058
|
+
{"yMMMMd", []string{"year:n", "month:l", "day:n"}, ""},
|
|
2059
|
+
{"yMMMd", []string{"year:n", "month:s", "day:n"}, ""},
|
|
2060
|
+
{"yMMMEd", []string{"year:n", "month:s", "day:n", "weekday:s"}, ""},
|
|
2061
|
+
{"yMMMMEEEEd", []string{"year:n", "month:l", "day:n", "weekday:l"}, ""},
|
|
2062
|
+
{"yMEd", []string{"year:n", "month:n", "day:n", "weekday:s"}, ""},
|
|
2063
|
+
{"yMd", []string{"year:n", "month:n", "day:n"}, ""},
|
|
2064
|
+
{"yM", []string{"year:n", "month:n"}, ""},
|
|
2065
|
+
{"yMMM", []string{"year:n", "month:s"}, ""},
|
|
2066
|
+
{"yMMMM", []string{"year:n", "month:l"}, ""},
|
|
2067
|
+
{"y", []string{"year:n"}, ""},
|
|
2068
|
+
{"y2", []string{"year:2"}, ""},
|
|
2069
|
+
{"MMMMd", []string{"month:l", "day:n"}, ""},
|
|
2070
|
+
{"MMMEd", []string{"month:s", "day:n", "weekday:s"}, ""},
|
|
2071
|
+
{"Md", []string{"month:n", "day:n"}, ""},
|
|
2072
|
+
{"Ed", []string{"weekday:s", "day:n"}, ""},
|
|
2073
|
+
{"d", []string{"day:n"}, ""},
|
|
2074
|
+
{"M", []string{"month:n"}, ""},
|
|
2075
|
+
{"MMMM", []string{"month:l"}, ""},
|
|
2076
|
+
{"MMM", []string{"month:s"}, ""},
|
|
2077
|
+
{"hms", []string{"hour:n", "minute:n", "second:n"}, ""},
|
|
2078
|
+
{"hms12", []string{"hour:n", "minute:n", "second:n"}, "12"},
|
|
2079
|
+
{"hms24", []string{"hour:n", "minute:n", "second:n"}, "24"},
|
|
2080
|
+
{"hm", []string{"hour:n", "minute:n"}, ""},
|
|
2081
|
+
{"hm12", []string{"hour:n", "minute:n"}, "12"},
|
|
2082
|
+
{"hm24", []string{"hour:n", "minute:n"}, "24"},
|
|
2083
|
+
{"h", []string{"hour:n"}, ""},
|
|
2084
|
+
{"h12", []string{"hour:n"}, "12"},
|
|
2085
|
+
{"H24", []string{"hour:n"}, "24"},
|
|
2086
|
+
{"ms", []string{"minute:n", "second:n"}, ""},
|
|
2087
|
+
{"hmdpS", []string{"hour:n", "minute:n", "dayPeriod:s"}, ""},
|
|
2088
|
+
{"hmdpL", []string{"hour:n", "minute:n", "dayPeriod:l"}, ""},
|
|
2089
|
+
{"hmF", []string{"hour:n", "minute:n", "second:n"}, ""},
|
|
2090
|
+
{"hmF12", []string{"hour:n", "minute:n", "second:n"}, "12"},
|
|
2091
|
+
{"yMdHms", []string{"year:n", "month:n", "day:n", "hour:n", "minute:n", "second:n"}, ""},
|
|
2092
|
+
{"yMdHms12", []string{"year:n", "month:n", "day:n", "hour:n", "minute:n", "second:n"}, "12"},
|
|
2093
|
+
{"yMdHms24", []string{"year:n", "month:n", "day:n", "hour:n", "minute:n", "second:n"}, "24"},
|
|
2094
|
+
{"yMMMdzS", []string{"year:n", "month:s", "day:n", "timeZoneName:s"}, ""},
|
|
2095
|
+
{"yMMMdzL", []string{"year:n", "month:s", "day:n", "timeZoneName:l"}, ""},
|
|
2096
|
+
{"hmzS", []string{"hour:n", "minute:n", "timeZoneName:s"}, ""},
|
|
2097
|
+
{"hmzO", []string{"hour:n", "minute:n", "timeZoneName:O"}, ""},
|
|
2098
|
+
{"yMdzS", []string{"year:n", "month:n", "day:n", "timeZoneName:s"}, ""},
|
|
2099
|
+
{"yMdzL", []string{"year:n", "month:n", "day:n", "timeZoneName:l"}, ""},
|
|
2100
|
+
{"yMdHmszS", []string{"year:n", "month:n", "day:n", "hour:n", "minute:n", "second:n", "timeZoneName:s"}, ""},
|
|
2101
|
+
{"yMdHmszS12", []string{"year:n", "month:n", "day:n", "hour:n", "minute:n", "second:n", "timeZoneName:s"}, "12"},
|
|
2102
|
+
{"yMdHmszS24", []string{"year:n", "month:n", "day:n", "hour:n", "minute:n", "second:n", "timeZoneName:s"}, "24"},
|
|
2103
|
+
{"hmszS", []string{"hour:n", "minute:n", "second:n", "timeZoneName:s"}, ""},
|
|
2104
|
+
{"yMdHm", []string{"year:n", "month:n", "day:n", "hour:n", "minute:n"}, ""},
|
|
2105
|
+
{"yMdHm12", []string{"year:n", "month:n", "day:n", "hour:n", "minute:n"}, "12"},
|
|
2106
|
+
{"yMdHm24", []string{"year:n", "month:n", "day:n", "hour:n", "minute:n"}, "24"},
|
|
2107
|
+
{"E", []string{"weekday:s"}, ""},
|
|
2108
|
+
{"EEEE", []string{"weekday:l"}, ""},
|
|
2109
|
+
{"Eh", []string{"weekday:s", "hour:n"}, ""},
|
|
2110
|
+
{"Ehm", []string{"weekday:s", "hour:n", "minute:2"}, ""},
|
|
2111
|
+
{"EEEEhm", []string{"weekday:l", "hour:n", "minute:2"}, ""},
|
|
2112
|
+
{"yMMMdHm", []string{"year:n", "month:s", "day:n", "hour:n", "minute:n"}, ""},
|
|
2113
|
+
{"yMMMMdHm", []string{"year:n", "month:l", "day:n", "hour:n", "minute:n"}, ""},
|
|
2114
|
+
{"yMMMMdEraS", []string{"year:n", "month:l", "day:n", "era:s"}, ""},
|
|
2115
|
+
{"yMMMMdEraL", []string{"year:n", "month:l", "day:n", "era:l"}, ""},
|
|
2116
|
+
{"yMMMdEraS", []string{"year:n", "month:s", "day:n", "era:s"}, ""},
|
|
2117
|
+
}
|
|
2118
|
+
|
|
2119
|
+
// Whether a skeleton matches the requested fields (exact also compares the
|
|
2120
|
+
// widths; the skeleton's cycle must match the requested one)
|
|
2121
|
+
func tnIntlSkeletonMatches(sk tnIntlSkeleton, fields map[string]string, f *TnIntlDateTimeFormat, exact bool) bool {
|
|
2122
|
+
want := map[string]bool{}
|
|
2123
|
+
for _, f2 := range sk.fields {
|
|
2124
|
+
kv := strings.SplitN(f2, ":", 2)
|
|
2125
|
+
want[kv[0]] = true
|
|
2126
|
+
// (the same field set: a skeleton with a field not asked for doesn't fit)
|
|
2127
|
+
if _, asked := fields[kv[0]]; !asked {
|
|
2128
|
+
return false
|
|
2129
|
+
}
|
|
2130
|
+
if exact {
|
|
2131
|
+
w, ok := fields[kv[0]]
|
|
2132
|
+
if !ok || w != kv[1] {
|
|
2133
|
+
return false
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
for k := range fields {
|
|
2138
|
+
if !want[k] {
|
|
2139
|
+
return false
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
// the skeleton's hour cycle must match the requested one
|
|
2143
|
+
hasHour := want["hour"]
|
|
2144
|
+
if sk.cycle == "12" && (!hasHour || (f.hc != "h11" && f.hc != "h12")) {
|
|
2145
|
+
return false
|
|
2146
|
+
}
|
|
2147
|
+
if sk.cycle == "24" && (!hasHour || (f.hc != "h23" && f.hc != "h24")) {
|
|
2148
|
+
return false
|
|
2149
|
+
}
|
|
2150
|
+
if sk.cycle == "" && hasHour && (f.hc == "h11" || f.hc == "h12" || f.hc == "h23" || f.hc == "h24") {
|
|
2151
|
+
return false
|
|
2152
|
+
}
|
|
2153
|
+
// the fractionalSecondDigits option: hmF keeps the plain shapes out
|
|
2154
|
+
if f.frac > 0 && !want["second"] {
|
|
2155
|
+
return false
|
|
2156
|
+
}
|
|
2157
|
+
if f.frac == 0 && sk.id == "hmF" || f.frac == 0 && sk.id == "hmF12" {
|
|
2158
|
+
if _, hasSec := fields["second"]; !hasSec {
|
|
2159
|
+
return false
|
|
2160
|
+
}
|
|
2161
|
+
}
|
|
2162
|
+
return true
|
|
2163
|
+
}
|
|
2164
|
+
|
|
2165
|
+
// A pattern composed of the closest date and time patterns (with the literal
|
|
2166
|
+
// the combined styles put between the halves)
|
|
2167
|
+
func tnIntlComposed(f *TnIntlDateTimeFormat, fields map[string]string) ([]tnIntlPart, string) {
|
|
2168
|
+
dateFields := map[string]string{}
|
|
2169
|
+
timeFields := map[string]string{}
|
|
2170
|
+
for k, v := range fields {
|
|
2171
|
+
if k == "hour" || k == "minute" || k == "second" || k == "dayPeriod" {
|
|
2172
|
+
timeFields[k] = v
|
|
2173
|
+
} else {
|
|
2174
|
+
dateFields[k] = v
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
var dateParts, timeParts []tnIntlPart
|
|
2178
|
+
if len(dateFields) > 0 {
|
|
2179
|
+
best, bestScore := "", -1
|
|
2180
|
+
for _, sk := range tnIntlSkeletons {
|
|
2181
|
+
if sk.cycle != "" || tnIntlSkeletonHasTime(sk) || strings.Contains(sk.id, "z") || strings.Contains(sk.id, "Era") {
|
|
2182
|
+
continue
|
|
2183
|
+
}
|
|
2184
|
+
// (no field the request doesn't name: {weekday} is "Tue", not a date)
|
|
2185
|
+
extra := false
|
|
2186
|
+
for _, f2 := range sk.fields {
|
|
2187
|
+
if _, ok := dateFields[strings.SplitN(f2, ":", 2)[0]]; !ok {
|
|
2188
|
+
extra = true
|
|
2189
|
+
}
|
|
2190
|
+
}
|
|
2191
|
+
if extra {
|
|
2192
|
+
continue
|
|
2193
|
+
}
|
|
2194
|
+
if score := tnIntlSkeletonScore(sk, dateFields); score > bestScore {
|
|
2195
|
+
best, bestScore = sk.id, score
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
if best != "" {
|
|
2199
|
+
dateParts = tnIntlDatePartsOf(f.loc.data)[best]
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
if len(timeFields) > 0 {
|
|
2203
|
+
best, bestScore := "", -1
|
|
2204
|
+
twelve := f.hc == "h11" || f.hc == "h12"
|
|
2205
|
+
for _, sk := range tnIntlSkeletons {
|
|
2206
|
+
if !tnIntlSkeletonHasTime(sk) || strings.Contains(sk.id, "z") || sk.id == "hmF" || sk.id == "hmF12" || sk.id == "hmdpS" || sk.id == "hmdpL" {
|
|
2207
|
+
continue
|
|
2208
|
+
}
|
|
2209
|
+
score := tnIntlSkeletonScore(sk, timeFields)
|
|
2210
|
+
if sk.cycle == "12" && !twelve {
|
|
2211
|
+
score--
|
|
2212
|
+
}
|
|
2213
|
+
if sk.cycle == "24" && (twelve || f.hc == "") {
|
|
2214
|
+
score--
|
|
2215
|
+
}
|
|
2216
|
+
if sk.cycle == "" && twelve {
|
|
2217
|
+
score--
|
|
2218
|
+
}
|
|
2219
|
+
if score > bestScore {
|
|
2220
|
+
best, bestScore = sk.id, score
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
if best != "" {
|
|
2224
|
+
timeParts = tnIntlDatePartsOf(f.loc.data)[best]
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
if dateParts == nil {
|
|
2228
|
+
return timeParts, "composed"
|
|
2229
|
+
}
|
|
2230
|
+
if timeParts == nil {
|
|
2231
|
+
return dateParts, "composed"
|
|
2232
|
+
}
|
|
2233
|
+
out := append([]tnIntlPart{}, dateParts...)
|
|
2234
|
+
out = append(out, tnIntlPart{kind: 'l', text: tnIntlDateJoiner(f.loc)})
|
|
2235
|
+
out = append(out, timeParts...)
|
|
2236
|
+
return out, "composed"
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
func tnIntlSkeletonHasTime(sk tnIntlSkeleton) bool {
|
|
2240
|
+
for _, f := range sk.fields {
|
|
2241
|
+
kv := strings.SplitN(f, ":", 2)
|
|
2242
|
+
if kv[0] == "hour" || kv[0] == "minute" {
|
|
2243
|
+
return true
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2246
|
+
return false
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
// How many of the skeleton's fields the request names, +1 per equal width
|
|
2250
|
+
func tnIntlSkeletonScore(sk tnIntlSkeleton, fields map[string]string) int {
|
|
2251
|
+
score := 0
|
|
2252
|
+
for _, f := range sk.fields {
|
|
2253
|
+
kv := strings.SplitN(f, ":", 2)
|
|
2254
|
+
if w, ok := fields[kv[0]]; ok {
|
|
2255
|
+
score++
|
|
2256
|
+
if w == kv[1] {
|
|
2257
|
+
score++
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
return score
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
// The literal a locale's combined date-time patterns put between the halves
|
|
2265
|
+
// (the dmedium parts are a prefix of ftmedium; the next literal is the joiner)
|
|
2266
|
+
func tnIntlDateJoiner(loc *TnIntlLoc) string {
|
|
2267
|
+
return tnIntlStyleJoiner(loc, "medium")
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
// The literal a date style's combined pattern puts between date and time
|
|
2271
|
+
func tnIntlStyleJoiner(loc *TnIntlLoc, style string) string {
|
|
2272
|
+
dp := tnIntlDatePartsOf(loc.data)["ft"+style]
|
|
2273
|
+
d := tnIntlDatePartsOf(loc.data)["d"+style]
|
|
2274
|
+
if dp == nil || d == nil {
|
|
2275
|
+
return ", "
|
|
2276
|
+
}
|
|
2277
|
+
for i := 0; i < len(dp); i++ {
|
|
2278
|
+
if i < len(d) {
|
|
2279
|
+
if dp[i] != d[i] {
|
|
2280
|
+
return ", "
|
|
2281
|
+
}
|
|
2282
|
+
continue
|
|
2283
|
+
}
|
|
2284
|
+
if dp[i].kind == 'l' {
|
|
2285
|
+
return dp[i].text
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
return ", "
|
|
2289
|
+
}
|
|
2290
|
+
|
|
2291
|
+
// The date's fields in its zone
|
|
2292
|
+
type tnIntlDateFields struct {
|
|
2293
|
+
year, month, day, hour, minute, second, ms int
|
|
2294
|
+
weekday int // Sunday=0
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
func tnIntlFieldsOf(t time.Time, loc *time.Location) tnIntlDateFields {
|
|
2298
|
+
lt := t.In(loc)
|
|
2299
|
+
return tnIntlDateFields{
|
|
2300
|
+
year: lt.Year(), month: int(lt.Month()), day: lt.Day(),
|
|
2301
|
+
hour: lt.Hour(), minute: lt.Minute(), second: lt.Second(),
|
|
2302
|
+
ms: lt.Nanosecond() / 1000000, weekday: int(lt.Weekday()),
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
// The zone name a width renders: the generated tables for the named zones
|
|
2307
|
+
// (the winter W / summer S variants by the offset), generic offsets otherwise
|
|
2308
|
+
func tnIntlZoneName(f *TnIntlDateTimeFormat, t time.Time, width byte, fields tnIntlDateFields) string {
|
|
2309
|
+
table := tnIntlZoneNames[f.zoneID]
|
|
2310
|
+
widths := map[byte]string{'s': "short", 'l': "long", 'g': "shortG", 'G': "longG", 'o': "short", 'O': "long"}
|
|
2311
|
+
key := widths[width]
|
|
2312
|
+
if table != nil {
|
|
2313
|
+
_, off := t.In(f.zone).Zone()
|
|
2314
|
+
_, offJan := time.Date(fields.year, 1, 15, 12, 0, 0, 0, f.zone).Zone()
|
|
2315
|
+
suffix := "S"
|
|
2316
|
+
if off == offJan {
|
|
2317
|
+
suffix = "W"
|
|
2318
|
+
}
|
|
2319
|
+
if v, ok := table[key+suffix]; ok && v != "" {
|
|
2320
|
+
return v
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
// the generic offsets: GMT+9 / GMT+5:30 / GMT-08:00
|
|
2324
|
+
_, off := t.In(f.zone).Zone()
|
|
2325
|
+
sign := "+"
|
|
2326
|
+
if off < 0 {
|
|
2327
|
+
sign, off = "-", -off
|
|
2328
|
+
}
|
|
2329
|
+
h, m := off/3600, (off%3600)/60
|
|
2330
|
+
switch width {
|
|
2331
|
+
case 's', 'g', 'o':
|
|
2332
|
+
if m == 0 {
|
|
2333
|
+
return "GMT" + sign + strconv.Itoa(h)
|
|
2334
|
+
}
|
|
2335
|
+
return "GMT" + sign + strconv.Itoa(h) + ":" + strconv.Itoa(m)
|
|
2336
|
+
}
|
|
2337
|
+
return "GMT" + sign + fmt.Sprintf("%02d:%02d", h, m)
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
// The value of one date pattern part, from the fields (of a or b, for range
|
|
2341
|
+
// patterns' endRange parts)
|
|
2342
|
+
func tnIntlDateValue(f *TnIntlDateTimeFormat, p tnIntlPart, fields tnIntlDateFields) string {
|
|
2343
|
+
data := f.loc.data
|
|
2344
|
+
switch p.kind {
|
|
2345
|
+
case 'y':
|
|
2346
|
+
digits := strconv.Itoa(tnIntlAbs(fields.year))
|
|
2347
|
+
if fields.year < 0 {
|
|
2348
|
+
digits = "-" + digits
|
|
2349
|
+
}
|
|
2350
|
+
if p.width == '2' {
|
|
2351
|
+
digits = fmt.Sprintf("%02d", tnIntlAbs(fields.year)%100)
|
|
2352
|
+
if fields.year < 0 {
|
|
2353
|
+
digits = "-" + digits
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
return tnIntlMapDigits(digits, tnIntlDigitsFor(f.loc))
|
|
2357
|
+
case 'M':
|
|
2358
|
+
if p.width == 'n' || p.width == '2' {
|
|
2359
|
+
d := strconv.Itoa(fields.month)
|
|
2360
|
+
if p.width == '2' {
|
|
2361
|
+
d = fmt.Sprintf("%02d", fields.month)
|
|
2362
|
+
}
|
|
2363
|
+
return tnIntlMapDigits(d, tnIntlDigitsFor(f.loc))
|
|
2364
|
+
}
|
|
2365
|
+
// standalone names belong to month-only patterns
|
|
2366
|
+
form := "F"
|
|
2367
|
+
if !tnIntlPatternHasDateFields(f) {
|
|
2368
|
+
form = ""
|
|
2369
|
+
}
|
|
2370
|
+
w := "L"
|
|
2371
|
+
if p.width == 's' {
|
|
2372
|
+
w = "S"
|
|
2373
|
+
} else if p.width == 'r' {
|
|
2374
|
+
w = "N"
|
|
2375
|
+
}
|
|
2376
|
+
return tnIntlName(data, "M"+form+strconv.Itoa(fields.month)+w)
|
|
2377
|
+
case 'd':
|
|
2378
|
+
d := strconv.Itoa(fields.day)
|
|
2379
|
+
if p.width == '2' {
|
|
2380
|
+
d = fmt.Sprintf("%02d", fields.day)
|
|
2381
|
+
}
|
|
2382
|
+
return tnIntlMapDigits(d, tnIntlDigitsFor(f.loc))
|
|
2383
|
+
case 'w':
|
|
2384
|
+
w := "L"
|
|
2385
|
+
if p.width == 's' {
|
|
2386
|
+
w = "S"
|
|
2387
|
+
} else if p.width == 'r' {
|
|
2388
|
+
w = "N"
|
|
2389
|
+
}
|
|
2390
|
+
return tnIntlName(data, "W"+strconv.Itoa(fields.weekday+1)+w)
|
|
2391
|
+
case 'h':
|
|
2392
|
+
v := (fields.hour+11)%12 + 1
|
|
2393
|
+
return tnIntlPadNum(v, p.width, f)
|
|
2394
|
+
case '1':
|
|
2395
|
+
return tnIntlPadNum(fields.hour%12, p.width, f)
|
|
2396
|
+
case 'H':
|
|
2397
|
+
return tnIntlPadNum(fields.hour, p.width, f)
|
|
2398
|
+
case 'm':
|
|
2399
|
+
return tnIntlPadNum(fields.minute, p.width, f)
|
|
2400
|
+
case 's':
|
|
2401
|
+
return tnIntlPadNum(fields.second, p.width, f)
|
|
2402
|
+
case 'p':
|
|
2403
|
+
minute := 30
|
|
2404
|
+
if fields.minute == 0 {
|
|
2405
|
+
minute = 0
|
|
2406
|
+
}
|
|
2407
|
+
w := "S"
|
|
2408
|
+
if p.width == 'l' {
|
|
2409
|
+
w = "L"
|
|
2410
|
+
} else if p.width == 'r' {
|
|
2411
|
+
w = "N"
|
|
2412
|
+
}
|
|
2413
|
+
if v := tnIntlName(data, fmt.Sprintf("p%d|%d", fields.hour, minute)+w); v != "" {
|
|
2414
|
+
return v
|
|
2415
|
+
}
|
|
2416
|
+
if fields.hour < 12 {
|
|
2417
|
+
return tnIntlName(data, "ampmAM")
|
|
2418
|
+
}
|
|
2419
|
+
return tnIntlName(data, "ampmPM")
|
|
2420
|
+
case 'P':
|
|
2421
|
+
if fields.hour < 12 {
|
|
2422
|
+
return tnIntlName(data, "ampmAM")
|
|
2423
|
+
}
|
|
2424
|
+
return tnIntlName(data, "ampmPM")
|
|
2425
|
+
case 'e':
|
|
2426
|
+
w := "S"
|
|
2427
|
+
if p.width == 'l' {
|
|
2428
|
+
w = "L"
|
|
2429
|
+
} else if p.width == 'r' {
|
|
2430
|
+
w = "N"
|
|
2431
|
+
}
|
|
2432
|
+
if fields.year < 1 {
|
|
2433
|
+
return tnIntlName(data, "eraBC"+w)
|
|
2434
|
+
}
|
|
2435
|
+
return tnIntlName(data, "eraAD"+w)
|
|
2436
|
+
case 'z':
|
|
2437
|
+
return tnIntlZoneName(f, time.Date(fields.year, time.Month(fields.month), fields.day, fields.hour, fields.minute, fields.second, 0, f.zone), p.width, fields)
|
|
2438
|
+
case 'f':
|
|
2439
|
+
d := strconv.Itoa(fields.ms)
|
|
2440
|
+
for len(d) < int(p.width) {
|
|
2441
|
+
d = "0" + d
|
|
2442
|
+
}
|
|
2443
|
+
return d
|
|
2444
|
+
}
|
|
2445
|
+
return p.text
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
func tnIntlPadNum(v int, width byte, f *TnIntlDateTimeFormat) string {
|
|
2449
|
+
d := strconv.Itoa(v)
|
|
2450
|
+
if width == '2' {
|
|
2451
|
+
d = fmt.Sprintf("%02d", v)
|
|
2452
|
+
}
|
|
2453
|
+
return tnIntlMapDigits(d, tnIntlDigitsFor(f.loc))
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
func tnIntlAbs(v int) int {
|
|
2457
|
+
if v < 0 {
|
|
2458
|
+
return -v
|
|
2459
|
+
}
|
|
2460
|
+
return v
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
// Whether the pattern has other date fields besides the month (the standalone
|
|
2464
|
+
// month names belong to month-only patterns)
|
|
2465
|
+
func tnIntlPatternHasDateFields(f *TnIntlDateTimeFormat) bool {
|
|
2466
|
+
for _, q := range f.pattern {
|
|
2467
|
+
if q.kind == 'y' || q.kind == 'd' || q.kind == 'w' {
|
|
2468
|
+
return true
|
|
2469
|
+
}
|
|
2470
|
+
}
|
|
2471
|
+
return false
|
|
2472
|
+
}
|
|
2473
|
+
|
|
2474
|
+
// The parts of a formatted date (the fractionalSecondDigits option appends
|
|
2475
|
+
// the fraction after the seconds, as ICU renders it)
|
|
2476
|
+
func TnIntlDateFormatParts(f *TnIntlDateTimeFormat, t time.Time) []interface{} {
|
|
2477
|
+
if t.IsZero() {
|
|
2478
|
+
panic(TnNodeError("RangeError", "", "Invalid time value"))
|
|
2479
|
+
}
|
|
2480
|
+
fields := tnIntlFieldsOf(t, f.zone)
|
|
2481
|
+
out := []interface{}{}
|
|
2482
|
+
appendedFrac := false
|
|
2483
|
+
for _, p := range f.pattern {
|
|
2484
|
+
if p.kind == 'f' {
|
|
2485
|
+
appendedFrac = true
|
|
2486
|
+
out = append(out, tnIntlObj("type", "fractionalSecond", "value", tnIntlDateValue(f, p, fields)))
|
|
2487
|
+
continue
|
|
2488
|
+
}
|
|
2489
|
+
if p.kind == 'z' {
|
|
2490
|
+
out = append(out, tnIntlObj("type", "timeZoneName", "value", tnIntlDateValue(f, p, fields)))
|
|
2491
|
+
continue
|
|
2492
|
+
}
|
|
2493
|
+
if p.kind == 'l' {
|
|
2494
|
+
if p.text != "" {
|
|
2495
|
+
out = append(out, tnIntlObj("type", "literal", "value", p.text))
|
|
2496
|
+
}
|
|
2497
|
+
continue
|
|
2498
|
+
}
|
|
2499
|
+
if v := tnIntlDateValue(f, p, fields); v != "" {
|
|
2500
|
+
out = append(out, tnIntlObj("type", tnIntlDatePartType(p.kind), "value", v))
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
if f.frac > 0 && !appendedFrac {
|
|
2504
|
+
// after the last second part: the decimal separator and the digits
|
|
2505
|
+
idx := -1
|
|
2506
|
+
for i, pp := range out {
|
|
2507
|
+
if tnIntlGet(pp, "type") == "second" {
|
|
2508
|
+
idx = i
|
|
2509
|
+
}
|
|
2510
|
+
}
|
|
2511
|
+
ins := []interface{}{
|
|
2512
|
+
tnIntlObj("type", "literal", "value", tnIntlNumSym(f.loc.data, "dec")),
|
|
2513
|
+
tnIntlObj("type", "fractionalSecond", "value", fmt.Sprintf("%03d", fields.ms)[:f.frac]),
|
|
2514
|
+
}
|
|
2515
|
+
if idx >= 0 {
|
|
2516
|
+
rest := append([]interface{}{}, out[idx+1:]...)
|
|
2517
|
+
out = append(out[:idx+1], append(ins, rest...)...)
|
|
2518
|
+
} else {
|
|
2519
|
+
out = append(out, ins...)
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
return out
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2525
|
+
func tnIntlDatePartType(kind byte) string {
|
|
2526
|
+
switch kind {
|
|
2527
|
+
case 'y':
|
|
2528
|
+
return "year"
|
|
2529
|
+
case 'M':
|
|
2530
|
+
return "month"
|
|
2531
|
+
case 'd':
|
|
2532
|
+
return "day"
|
|
2533
|
+
case 'w':
|
|
2534
|
+
return "weekday"
|
|
2535
|
+
case 'h', 'H', '1':
|
|
2536
|
+
return "hour"
|
|
2537
|
+
case 'm':
|
|
2538
|
+
return "minute"
|
|
2539
|
+
case 's':
|
|
2540
|
+
return "second"
|
|
2541
|
+
case 'p', 'P':
|
|
2542
|
+
return "dayPeriod"
|
|
2543
|
+
case 'e':
|
|
2544
|
+
return "era"
|
|
2545
|
+
}
|
|
2546
|
+
return "literal"
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
func TnIntlDateFormat(f *TnIntlDateTimeFormat, t time.Time) string {
|
|
2550
|
+
var b strings.Builder
|
|
2551
|
+
for _, p := range TnIntlDateFormatParts(f, t) {
|
|
2552
|
+
b.WriteString(TnJSString(tnIntlGet(p, "value")))
|
|
2553
|
+
}
|
|
2554
|
+
return b.String()
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
// Intl.DateTimeFormat#formatRange: the captured range pattern for the
|
|
2558
|
+
// greatest difference between the two dates
|
|
2559
|
+
func tnIntlDateGreatestDiff(f *TnIntlDateTimeFormat, a, b time.Time) string {
|
|
2560
|
+
patternFields := map[byte]bool{}
|
|
2561
|
+
for _, p := range f.pattern {
|
|
2562
|
+
patternFields[p.kind] = true
|
|
2563
|
+
}
|
|
2564
|
+
fa, fb := tnIntlFieldsOf(a, f.zone), tnIntlFieldsOf(b, f.zone)
|
|
2565
|
+
for _, d := range []struct {
|
|
2566
|
+
kind byte
|
|
2567
|
+
diff bool
|
|
2568
|
+
field bool
|
|
2569
|
+
}{{'y', fa.year != fb.year, patternFields['y']}, {'M', fa.month != fb.month, patternFields['M']}, {'d', fa.day != fb.day, patternFields['d']}, {'h', fa.hour != fb.hour, patternFields['h'] || patternFields['H'] || patternFields['1']}, {'m', fa.minute != fb.minute, patternFields['m']}, {'s', fa.second != fb.second, patternFields['s']}} {
|
|
2570
|
+
if d.diff {
|
|
2571
|
+
if d.field {
|
|
2572
|
+
return string(d.kind)
|
|
2573
|
+
}
|
|
2574
|
+
return "other"
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
return ""
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
func tnIntlDateRangePattern(f *TnIntlDateTimeFormat, a, b time.Time) []tnIntlPart {
|
|
2581
|
+
diff := tnIntlDateGreatestDiff(f, a, b)
|
|
2582
|
+
if diff == "" {
|
|
2583
|
+
return nil
|
|
2584
|
+
}
|
|
2585
|
+
p := tnIntlDatePartsOf(f.loc.data)["R:"+f.id+":"+diff]
|
|
2586
|
+
if p == nil && diff != "other" {
|
|
2587
|
+
p = tnIntlDatePartsOf(f.loc.data)["R:"+f.id+":other"]
|
|
2588
|
+
}
|
|
2589
|
+
return p
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
func TnIntlDateFormatRangeParts(f *TnIntlDateTimeFormat, a time.Time, b time.Time) []interface{} {
|
|
2593
|
+
if a.IsZero() || b.IsZero() {
|
|
2594
|
+
panic(TnNodeError("RangeError", "", "Invalid time value"))
|
|
2595
|
+
}
|
|
2596
|
+
// nothing shown differs: one date, its parts shared
|
|
2597
|
+
if TnIntlDateFormat(f, a) == TnIntlDateFormat(f, b) {
|
|
2598
|
+
out := TnIntlDateFormatParts(f, a)
|
|
2599
|
+
for _, p := range out {
|
|
2600
|
+
p.(*TnMap[string, interface{}]).Set("source", "shared")
|
|
2601
|
+
}
|
|
2602
|
+
return out
|
|
2603
|
+
}
|
|
2604
|
+
pattern := tnIntlDateRangePattern(f, a, b)
|
|
2605
|
+
if pattern == nil {
|
|
2606
|
+
// no range data: both formatted, joined by the dash ICU uses
|
|
2607
|
+
out := []interface{}{}
|
|
2608
|
+
for _, p := range TnIntlDateFormatParts(f, a) {
|
|
2609
|
+
p.(*TnMap[string, interface{}]).Set("source", "startRange")
|
|
2610
|
+
out = append(out, p)
|
|
2611
|
+
}
|
|
2612
|
+
out = append(out, tnIntlObj("type", "literal", "value", " – ", "source", "shared"))
|
|
2613
|
+
for _, p := range TnIntlDateFormatParts(f, b) {
|
|
2614
|
+
p.(*TnMap[string, interface{}]).Set("source", "endRange")
|
|
2615
|
+
out = append(out, p)
|
|
2616
|
+
}
|
|
2617
|
+
return out
|
|
2618
|
+
}
|
|
2619
|
+
out := []interface{}{}
|
|
2620
|
+
for _, p := range pattern {
|
|
2621
|
+
fields := tnIntlFieldsOf(a, f.zone)
|
|
2622
|
+
source := "shared"
|
|
2623
|
+
if p.src == 'e' {
|
|
2624
|
+
fields = tnIntlFieldsOf(b, f.zone)
|
|
2625
|
+
source = "endRange"
|
|
2626
|
+
} else if p.src == 's' {
|
|
2627
|
+
source = "startRange"
|
|
2628
|
+
}
|
|
2629
|
+
if p.kind == 'l' {
|
|
2630
|
+
if p.text != "" {
|
|
2631
|
+
out = append(out, tnIntlObj("type", "literal", "value", p.text, "source", source))
|
|
2632
|
+
}
|
|
2633
|
+
continue
|
|
2634
|
+
}
|
|
2635
|
+
if v := tnIntlDateValue(f, p, fields); v != "" {
|
|
2636
|
+
out = append(out, tnIntlObj("type", tnIntlDatePartType(p.kind), "value", v, "source", source))
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
return out
|
|
2640
|
+
}
|
|
2641
|
+
|
|
2642
|
+
func TnIntlDateFormatRange(f *TnIntlDateTimeFormat, a time.Time, b time.Time) string {
|
|
2643
|
+
var bld strings.Builder
|
|
2644
|
+
for _, p := range TnIntlDateFormatRangeParts(f, a, b) {
|
|
2645
|
+
bld.WriteString(TnJSString(tnIntlGet(p, "value")))
|
|
2646
|
+
}
|
|
2647
|
+
return bld.String()
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
// resolvedOptions
|
|
2651
|
+
// (keys in Node's order: the hour cycle only with an hour, the components
|
|
2652
|
+
// only without dateStyle / timeStyle)
|
|
2653
|
+
func (f *TnIntlDateTimeFormat) resolvedOptions() interface{} {
|
|
2654
|
+
return f.tnResolved()
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
// The format method as a value (dates.map(dtf.format); no argument: now)
|
|
2658
|
+
func (f *TnIntlDateTimeFormat) Get_format() func(interface{}) string {
|
|
2659
|
+
return func(x interface{}) string { return TnIntlDateFormat(f, TnNewDate(x)) }
|
|
2660
|
+
}
|
|
2661
|
+
|
|
2662
|
+
func (f *TnIntlDateTimeFormat) tnResolved() interface{} {
|
|
2663
|
+
out := tnIntlObj()
|
|
2664
|
+
out.Set("locale", f.loc.id)
|
|
2665
|
+
out.Set("calendar", "gregory")
|
|
2666
|
+
nu := f.loc.tag.TypeForKey("nu")
|
|
2667
|
+
if nu == "" {
|
|
2668
|
+
nu = "latn"
|
|
2669
|
+
}
|
|
2670
|
+
out.Set("numberingSystem", nu)
|
|
2671
|
+
out.Set("timeZone", f.zoneID)
|
|
2672
|
+
widths := map[byte]string{'n': "numeric", '2': "2-digit", 'l': "long", 's': "short", 'r': "narrow", 'o': "shortOffset", 'O': "longOffset", 'g': "shortGeneric", 'G': "longGeneric"}
|
|
2673
|
+
found := map[string]string{}
|
|
2674
|
+
hasHour := false
|
|
2675
|
+
for _, p := range f.pattern {
|
|
2676
|
+
name := ""
|
|
2677
|
+
switch p.kind {
|
|
2678
|
+
case 'w':
|
|
2679
|
+
name = "weekday"
|
|
2680
|
+
case 'e':
|
|
2681
|
+
name = "era"
|
|
2682
|
+
case 'y':
|
|
2683
|
+
name = "year"
|
|
2684
|
+
case 'M':
|
|
2685
|
+
name = "month"
|
|
2686
|
+
case 'd':
|
|
2687
|
+
name = "day"
|
|
2688
|
+
case 'p':
|
|
2689
|
+
name = "dayPeriod"
|
|
2690
|
+
case 'h', 'H', '1':
|
|
2691
|
+
name = "hour"
|
|
2692
|
+
hasHour = true
|
|
2693
|
+
case 'm':
|
|
2694
|
+
name = "minute"
|
|
2695
|
+
case 's':
|
|
2696
|
+
name = "second"
|
|
2697
|
+
case 'z':
|
|
2698
|
+
name = "timeZoneName"
|
|
2699
|
+
}
|
|
2700
|
+
if name == "" {
|
|
2701
|
+
continue
|
|
2702
|
+
}
|
|
2703
|
+
if _, seen := found[name]; !seen {
|
|
2704
|
+
w := widths[p.width]
|
|
2705
|
+
if name == "hour" && w != "2-digit" {
|
|
2706
|
+
w = "numeric"
|
|
2707
|
+
}
|
|
2708
|
+
found[name] = w
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
if hasHour {
|
|
2712
|
+
hc := f.hc
|
|
2713
|
+
if hc == "" {
|
|
2714
|
+
hc = tnIntlName(f.loc.data, "hc")
|
|
2715
|
+
}
|
|
2716
|
+
if hc != "" {
|
|
2717
|
+
out.Set("hourCycle", hc)
|
|
2718
|
+
out.Set("hour12", hc == "h11" || hc == "h12")
|
|
2719
|
+
}
|
|
2720
|
+
}
|
|
2721
|
+
if f.dateStyle != "" || f.timeStyle != "" {
|
|
2722
|
+
if f.dateStyle != "" {
|
|
2723
|
+
out.Set("dateStyle", f.dateStyle)
|
|
2724
|
+
}
|
|
2725
|
+
if f.timeStyle != "" {
|
|
2726
|
+
out.Set("timeStyle", f.timeStyle)
|
|
2727
|
+
}
|
|
2728
|
+
return out
|
|
2729
|
+
}
|
|
2730
|
+
for _, name := range []string{"weekday", "era", "year", "month", "day", "dayPeriod", "hour", "minute", "second"} {
|
|
2731
|
+
if w, ok := found[name]; ok {
|
|
2732
|
+
out.Set(name, w)
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
if f.frac > 0 {
|
|
2736
|
+
out.Set("fractionalSecondDigits", float64(f.frac))
|
|
2737
|
+
}
|
|
2738
|
+
if w, ok := found["timeZoneName"]; ok {
|
|
2739
|
+
out.Set("timeZoneName", w)
|
|
2740
|
+
}
|
|
2741
|
+
return out
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
// The wrapper the Date methods use: kind "locale" / "localeDate" /
|
|
2745
|
+
// "localeTime" render with the Intl patterns (the default locale comes from
|
|
2746
|
+
// the OS, as Node's do)
|
|
2747
|
+
func TnIntlDateFmt(t time.Time, locales interface{}, options interface{}, kind string) string {
|
|
2748
|
+
if t.IsZero() {
|
|
2749
|
+
return "Invalid Date"
|
|
2750
|
+
}
|
|
2751
|
+
// the options copied, then ToDateTimeOptions' defaults: only when none of
|
|
2752
|
+
// the required kind's fields (or a style) were given
|
|
2753
|
+
opts := tnIntlObj()
|
|
2754
|
+
if options != nil {
|
|
2755
|
+
for _, k := range TnKeys(options) {
|
|
2756
|
+
opts.Set(k, TnGetValue(options, k))
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
has := func(keys ...string) bool {
|
|
2760
|
+
for _, k := range keys {
|
|
2761
|
+
if opts.Get(k) != nil {
|
|
2762
|
+
return true
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
return false
|
|
2766
|
+
}
|
|
2767
|
+
dateFields := []string{"weekday", "year", "month", "day"}
|
|
2768
|
+
timeFields := []string{"dayPeriod", "hour", "minute", "second", "fractionalSecondDigits"}
|
|
2769
|
+
setDate := func() { opts.Set("year", "numeric"); opts.Set("month", "numeric"); opts.Set("day", "numeric") }
|
|
2770
|
+
setTime := func() { opts.Set("hour", "numeric"); opts.Set("minute", "numeric"); opts.Set("second", "numeric") }
|
|
2771
|
+
switch kind {
|
|
2772
|
+
case "localeDate":
|
|
2773
|
+
if has("timeStyle") {
|
|
2774
|
+
panic(TnNodeError("TypeError", "", "Invalid option : timeStyle"))
|
|
2775
|
+
}
|
|
2776
|
+
if !has(dateFields...) && !has("dateStyle") {
|
|
2777
|
+
setDate()
|
|
2778
|
+
}
|
|
2779
|
+
case "localeTime":
|
|
2780
|
+
if has("dateStyle") {
|
|
2781
|
+
panic(TnNodeError("TypeError", "", "Invalid option : dateStyle"))
|
|
2782
|
+
}
|
|
2783
|
+
if !has(timeFields...) && !has("timeStyle") {
|
|
2784
|
+
setTime()
|
|
2785
|
+
}
|
|
2786
|
+
default:
|
|
2787
|
+
if !has(dateFields...) && !has(timeFields...) && !has("dateStyle", "timeStyle") {
|
|
2788
|
+
setDate()
|
|
2789
|
+
setTime()
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
f := TnNewIntlDateTimeFormat(locales, opts)
|
|
2793
|
+
return TnIntlDateFormat(f, t)
|
|
2794
|
+
}`;
|
|
2795
|
+
const intlCollateGo = `// Intl.Collator: golang.org/x/text/collate (sensitivity via the ignore
|
|
2796
|
+
// options, numeric collation; caseFirst "upper" swaps case-only differences
|
|
2797
|
+
// — x/text has no caseFirst option — and ignorePunctuation strips punctuation)
|
|
2798
|
+
|
|
2799
|
+
type TnIntlCollator struct {
|
|
2800
|
+
loc *TnIntlLoc
|
|
2801
|
+
col *xcollate.Collator
|
|
2802
|
+
caseless *xcollate.Collator // caseFirst "upper": the case-blind order
|
|
2803
|
+
base *xcollate.Collator // sensitivity "case": the base letters' order
|
|
2804
|
+
usage string
|
|
2805
|
+
sensitivity string
|
|
2806
|
+
caseFirst string
|
|
2807
|
+
numeric bool
|
|
2808
|
+
ignorePunct bool
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
func TnNewIntlCollator(locales interface{}, options interface{}) *TnIntlCollator {
|
|
2812
|
+
c := &TnIntlCollator{loc: TnIntlResolve(locales), usage: "sort", sensitivity: "variant"}
|
|
2813
|
+
if v, ok := tnIntlOptStr(options, "usage"); ok {
|
|
2814
|
+
if v != "sort" && v != "search" {
|
|
2815
|
+
tnIntlRangeError("Invalid usage: " + v)
|
|
2816
|
+
}
|
|
2817
|
+
c.usage = v
|
|
2818
|
+
}
|
|
2819
|
+
if v, ok := tnIntlOptStr(options, "sensitivity"); ok {
|
|
2820
|
+
if v != "base" && v != "accent" && v != "case" && v != "variant" {
|
|
2821
|
+
tnIntlRangeError("Invalid sensitivity: " + v)
|
|
2822
|
+
}
|
|
2823
|
+
c.sensitivity = v
|
|
2824
|
+
}
|
|
2825
|
+
if v, ok := tnIntlOptStr(options, "caseFirst"); ok {
|
|
2826
|
+
if v != "upper" && v != "lower" && v != "false" {
|
|
2827
|
+
tnIntlRangeError("Invalid caseFirst: " + v)
|
|
2828
|
+
}
|
|
2829
|
+
c.caseFirst = v
|
|
2830
|
+
} else if kn := c.loc.tag.TypeForKey("kf"); kn == "upper" || kn == "lower" {
|
|
2831
|
+
c.caseFirst = kn
|
|
2832
|
+
} else {
|
|
2833
|
+
c.caseFirst = "false"
|
|
2834
|
+
}
|
|
2835
|
+
if kn := c.loc.tag.TypeForKey("kn"); kn == "true" || kn == "yes" {
|
|
2836
|
+
c.numeric = true
|
|
2837
|
+
}
|
|
2838
|
+
if options != nil {
|
|
2839
|
+
if v := TnGetValue(options, "numeric"); v != nil {
|
|
2840
|
+
c.numeric = TnTruthy(v)
|
|
2841
|
+
}
|
|
2842
|
+
if v := TnGetValue(options, "ignorePunctuation"); v != nil {
|
|
2843
|
+
c.ignorePunct = TnTruthy(v)
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
var opts []xcollate.Option
|
|
2847
|
+
switch c.sensitivity {
|
|
2848
|
+
case "base":
|
|
2849
|
+
opts = append(opts, xcollate.IgnoreCase, xcollate.IgnoreDiacritics)
|
|
2850
|
+
case "accent":
|
|
2851
|
+
opts = append(opts, xcollate.IgnoreCase)
|
|
2852
|
+
}
|
|
2853
|
+
if c.numeric {
|
|
2854
|
+
opts = append(opts, xcollate.Numeric)
|
|
2855
|
+
}
|
|
2856
|
+
c.col = xcollate.New(c.loc.tag, opts...)
|
|
2857
|
+
// sensitivity "case": base letters, then case alone (x/text's
|
|
2858
|
+
// IgnoreDiacritics still tells a from á at the tertiary level)
|
|
2859
|
+
if c.sensitivity == "case" {
|
|
2860
|
+
c.base = xcollate.New(c.loc.tag, append(opts, xcollate.IgnoreCase, xcollate.IgnoreDiacritics)...)
|
|
2861
|
+
}
|
|
2862
|
+
// caseFirst "upper" (x/text has no such option): strings that differ
|
|
2863
|
+
// only by case — equal to a case-blind collator — swap their order
|
|
2864
|
+
if c.caseFirst == "upper" && (c.sensitivity == "case" || c.sensitivity == "variant") {
|
|
2865
|
+
c.caseless = xcollate.New(c.loc.tag, append(opts, xcollate.IgnoreCase)...)
|
|
2866
|
+
}
|
|
2867
|
+
return c
|
|
2868
|
+
}
|
|
2869
|
+
|
|
2870
|
+
func tnIntlStripPunct(s string) string {
|
|
2871
|
+
var b strings.Builder
|
|
2872
|
+
for _, r := range s {
|
|
2873
|
+
if unicode.IsPunct(r) || unicode.IsSymbol(r) {
|
|
2874
|
+
continue
|
|
2875
|
+
}
|
|
2876
|
+
b.WriteRune(r)
|
|
2877
|
+
}
|
|
2878
|
+
return b.String()
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
func TnIntlCollatorCompare(c *TnIntlCollator, a string, b string) float64 {
|
|
2882
|
+
if c.ignorePunct {
|
|
2883
|
+
a, b = tnIntlStripPunct(a), tnIntlStripPunct(b)
|
|
2884
|
+
}
|
|
2885
|
+
if c.base != nil {
|
|
2886
|
+
if r := c.base.CompareString(a, b); r != 0 {
|
|
2887
|
+
return float64(r)
|
|
2888
|
+
}
|
|
2889
|
+
a, b = tnIntlStripMarks(a), tnIntlStripMarks(b)
|
|
2890
|
+
}
|
|
2891
|
+
r := c.col.CompareString(a, b)
|
|
2892
|
+
if r != 0 && c.caseless != nil && c.caseless.CompareString(a, b) == 0 {
|
|
2893
|
+
r = -r
|
|
2894
|
+
}
|
|
2895
|
+
return float64(r)
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2898
|
+
// A string without its combining marks (NFD, then the Mn runes dropped)
|
|
2899
|
+
func tnIntlStripMarks(s string) string {
|
|
2900
|
+
var b strings.Builder
|
|
2901
|
+
for _, r := range tnnorm.NFD.String(s) {
|
|
2902
|
+
if !unicode.Is(unicode.Mn, r) {
|
|
2903
|
+
b.WriteRune(r)
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
return b.String()
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
// The compare method as a value (arr.sort(new Intl.Collator('de').compare))
|
|
2910
|
+
func (c *TnIntlCollator) Get_compare() func(string, string) float64 {
|
|
2911
|
+
return func(a string, b string) float64 { return TnIntlCollatorCompare(c, a, b) }
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
func (c *TnIntlCollator) resolvedOptions() interface{} {
|
|
2915
|
+
return tnIntlObj("locale", c.loc.id, "usage", c.usage, "sensitivity", c.sensitivity, "ignorePunctuation", c.ignorePunct,
|
|
2916
|
+
"collation", "default", "numeric", c.numeric, "caseFirst", c.caseFirst)
|
|
2917
|
+
}
|
|
2918
|
+
|
|
2919
|
+
// s.localeCompare(b, locales, options) with a locale or options: the full
|
|
2920
|
+
// collator (the bare two-argument form keeps the light root collation)
|
|
2921
|
+
// (collators are cached by locales and options: a sort's comparator calls
|
|
2922
|
+
// this once per comparison)
|
|
2923
|
+
var tnIntlCollatorCache sync.Map
|
|
2924
|
+
|
|
2925
|
+
func TnIntlCompare(a string, b string, locales interface{}, options interface{}) float64 {
|
|
2926
|
+
key := strings.Join(TnIntlCanonicalList(locales), ",")
|
|
2927
|
+
for _, k := range []string{"usage", "sensitivity", "caseFirst", "numeric", "ignorePunctuation", "collation"} {
|
|
2928
|
+
if options != nil {
|
|
2929
|
+
key += "|" + TnJSString(TnGetValue(options, k))
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
if c, ok := tnIntlCollatorCache.Load(key); ok {
|
|
2933
|
+
return TnIntlCollatorCompare(c.(*TnIntlCollator), a, b)
|
|
2934
|
+
}
|
|
2935
|
+
c := TnNewIntlCollator(locales, options)
|
|
2936
|
+
tnIntlCollatorCache.Store(key, c)
|
|
2937
|
+
return TnIntlCollatorCompare(c, a, b)
|
|
2938
|
+
}`;
|
|
2939
|
+
const intlPluralGo = `// Intl.PluralRules: golang.org/x/text/feature/plural (the operands from the
|
|
2940
|
+
// rounded value, as the spec computes them)
|
|
2941
|
+
|
|
2942
|
+
type TnIntlPluralRules struct {
|
|
2943
|
+
loc *TnIntlLoc
|
|
2944
|
+
ordinal bool
|
|
2945
|
+
minFD int
|
|
2946
|
+
useSD bool
|
|
2947
|
+
minSD int
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
func TnNewIntlPluralRules(locales interface{}, options interface{}) *TnIntlPluralRules {
|
|
2951
|
+
p := &TnIntlPluralRules{loc: TnIntlResolve(locales)}
|
|
2952
|
+
if v, ok := tnIntlOptStr(options, "type"); ok {
|
|
2953
|
+
if v != "cardinal" && v != "ordinal" {
|
|
2954
|
+
tnIntlRangeError("Invalid type: " + v)
|
|
2955
|
+
}
|
|
2956
|
+
p.ordinal = v == "ordinal"
|
|
2957
|
+
}
|
|
2958
|
+
if v, ok := tnIntlOptFloat(options, "minimumFractionDigits"); ok {
|
|
2959
|
+
n := int(v)
|
|
2960
|
+
if v != math.Trunc(v) || n < 0 || n > 100 {
|
|
2961
|
+
tnIntlRangeError("minimumFractionDigits value is out of range.")
|
|
2962
|
+
}
|
|
2963
|
+
p.minFD = n
|
|
2964
|
+
}
|
|
2965
|
+
if v, ok := tnIntlOptFloat(options, "minimumSignificantDigits"); ok {
|
|
2966
|
+
n := int(v)
|
|
2967
|
+
if v != math.Trunc(v) || n < 1 || n > 21 {
|
|
2968
|
+
tnIntlRangeError("minimumSignificantDigits value is out of range.")
|
|
2969
|
+
}
|
|
2970
|
+
p.useSD, p.minSD = true, n
|
|
2971
|
+
}
|
|
2972
|
+
return p
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
// The rendered digits the operands come from: the value's, padded by the
|
|
2976
|
+
// options (minimumFractionDigits / minimumSignificantDigits)
|
|
2977
|
+
func (p *TnIntlPluralRules) digitsOf(x interface{}) string {
|
|
2978
|
+
n, ok := x.(float64)
|
|
2979
|
+
if !ok {
|
|
2980
|
+
n = TnNumber(x)
|
|
2981
|
+
}
|
|
2982
|
+
if math.IsNaN(n) || math.IsInf(n, 0) || math.Abs(n) >= 1e21 {
|
|
2983
|
+
return strconv.FormatFloat(math.Abs(n), 'e', -1, 64)
|
|
2984
|
+
}
|
|
2985
|
+
digits := strconv.FormatFloat(math.Abs(n), 'f', -1, 64)
|
|
2986
|
+
intPart, frac := digits, ""
|
|
2987
|
+
if dot := strings.IndexByte(digits, '.'); dot >= 0 {
|
|
2988
|
+
intPart, frac = digits[:dot], digits[dot+1:]
|
|
2989
|
+
}
|
|
2990
|
+
if p.useSD {
|
|
2991
|
+
sig := strings.TrimLeft(intPart+frac, "0")
|
|
2992
|
+
if len(sig) < p.minSD {
|
|
2993
|
+
return intPart + frac + strings.Repeat("0", p.minSD-len(sig))
|
|
2994
|
+
}
|
|
2995
|
+
return digits
|
|
2996
|
+
}
|
|
2997
|
+
if len(frac) < p.minFD {
|
|
2998
|
+
return intPart + frac + strings.Repeat("0", p.minFD-len(frac))
|
|
2999
|
+
}
|
|
3000
|
+
return digits
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
func TnIntlPluralSelect(p *TnIntlPluralRules, x interface{}) string {
|
|
3004
|
+
digits := p.digitsOf(x)
|
|
3005
|
+
i, v, w, f, t := tnIntlPluralOperands(digits)
|
|
3006
|
+
if p.ordinal {
|
|
3007
|
+
return tnIntlPluralName(xplural.Ordinal.MatchPlural(p.loc.tag, i, v, w, f, t))
|
|
3008
|
+
}
|
|
3009
|
+
return tnIntlCardinal(p.loc.tag, i, v, w, f, t)
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
// selectRange: the category the range selects (x/text has no range rules; the
|
|
3013
|
+
// end's category stands in)
|
|
3014
|
+
func TnIntlPluralSelectRange(p *TnIntlPluralRules, start interface{}, end interface{}) string {
|
|
3015
|
+
return TnIntlPluralSelect(p, end)
|
|
3016
|
+
}
|
|
3017
|
+
|
|
3018
|
+
// (keys in Node's order; the categories in CLDR's: zero one two few many other)
|
|
3019
|
+
func (p *TnIntlPluralRules) resolvedOptions() interface{} {
|
|
3020
|
+
out := tnIntlObj()
|
|
3021
|
+
out.Set("locale", p.loc.id)
|
|
3022
|
+
if p.ordinal {
|
|
3023
|
+
out.Set("type", "ordinal")
|
|
3024
|
+
} else {
|
|
3025
|
+
out.Set("type", "cardinal")
|
|
3026
|
+
}
|
|
3027
|
+
out.Set("notation", "standard")
|
|
3028
|
+
out.Set("minimumIntegerDigits", float64(1))
|
|
3029
|
+
if p.useSD {
|
|
3030
|
+
out.Set("minimumSignificantDigits", float64(p.minSD))
|
|
3031
|
+
out.Set("maximumSignificantDigits", float64(21))
|
|
3032
|
+
} else {
|
|
3033
|
+
out.Set("minimumFractionDigits", float64(p.minFD))
|
|
3034
|
+
out.Set("maximumFractionDigits", float64(max(3, p.minFD)))
|
|
3035
|
+
}
|
|
3036
|
+
// the plural categories: what the rules select over values covering
|
|
3037
|
+
// every CLDR rule's operands
|
|
3038
|
+
seen := map[string]bool{}
|
|
3039
|
+
samples := []float64{0.5, 1.5, 100, 101, 102, 103, 111, 1000, 100000, 1000000, 1e7}
|
|
3040
|
+
for i := 0; i <= 30; i++ {
|
|
3041
|
+
samples = append(samples, float64(i))
|
|
3042
|
+
}
|
|
3043
|
+
for _, v := range samples {
|
|
3044
|
+
seen[TnIntlPluralSelect(p, v)] = true
|
|
3045
|
+
}
|
|
3046
|
+
cats := []interface{}{}
|
|
3047
|
+
for _, cat := range []string{"zero", "one", "two", "few", "many", "other"} {
|
|
3048
|
+
if seen[cat] {
|
|
3049
|
+
cats = append(cats, cat)
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
out.Set("pluralCategories", cats)
|
|
3053
|
+
out.Set("roundingIncrement", float64(1))
|
|
3054
|
+
out.Set("roundingMode", "halfExpand")
|
|
3055
|
+
out.Set("roundingPriority", "auto")
|
|
3056
|
+
out.Set("trailingZeroDisplay", "auto")
|
|
3057
|
+
return out
|
|
3058
|
+
}`;
|
|
3059
|
+
const intlListRelGo = `// Intl.ListFormat and Intl.RelativeTimeFormat: the generated patterns
|
|
3060
|
+
|
|
3061
|
+
func tnIntlListParts(data string) map[string]string {
|
|
3062
|
+
if m := tnIntlList[data]; m != nil {
|
|
3063
|
+
return m
|
|
3064
|
+
}
|
|
3065
|
+
return tnIntlList["en"]
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
func tnIntlRelParts(data string) map[string]string {
|
|
3069
|
+
if m := tnIntlRel[data]; m != nil {
|
|
3070
|
+
return m
|
|
3071
|
+
}
|
|
3072
|
+
return tnIntlRel["en"]
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
type TnIntlListFormat struct {
|
|
3076
|
+
loc *TnIntlLoc
|
|
3077
|
+
type_ string
|
|
3078
|
+
style string
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3081
|
+
func TnNewIntlListFormat(locales interface{}, options interface{}) *TnIntlListFormat {
|
|
3082
|
+
l := &TnIntlListFormat{loc: TnIntlResolve(locales), type_: "conjunction", style: "long"}
|
|
3083
|
+
if v, ok := tnIntlOptStr(options, "type"); ok {
|
|
3084
|
+
if v != "conjunction" && v != "disjunction" && v != "unit" {
|
|
3085
|
+
tnIntlRangeError("Invalid type: " + v)
|
|
3086
|
+
}
|
|
3087
|
+
l.type_ = v
|
|
3088
|
+
}
|
|
3089
|
+
if v, ok := tnIntlOptStr(options, "style"); ok {
|
|
3090
|
+
if v != "long" && v != "short" && v != "narrow" {
|
|
3091
|
+
tnIntlRangeError("Invalid style: " + v)
|
|
3092
|
+
}
|
|
3093
|
+
l.style = v
|
|
3094
|
+
}
|
|
3095
|
+
return l
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
// The elements as strings (any array)
|
|
3099
|
+
func tnIntlItemList(items interface{}) []string {
|
|
3100
|
+
var in []interface{}
|
|
3101
|
+
switch v := items.(type) {
|
|
3102
|
+
case []interface{}:
|
|
3103
|
+
in = v
|
|
3104
|
+
case []string:
|
|
3105
|
+
out := make([]string, len(v))
|
|
3106
|
+
for i, s := range v {
|
|
3107
|
+
out[i] = s
|
|
3108
|
+
}
|
|
3109
|
+
return out
|
|
3110
|
+
default:
|
|
3111
|
+
in = TnToArray(items)
|
|
3112
|
+
}
|
|
3113
|
+
out := make([]string, len(in))
|
|
3114
|
+
for i, e := range in {
|
|
3115
|
+
out[i] = TnJSString(e)
|
|
3116
|
+
}
|
|
3117
|
+
return out
|
|
3118
|
+
}
|
|
3119
|
+
|
|
3120
|
+
// The pair separator, or (sep "end") the last one: the contextual variant
|
|
3121
|
+
// ("e" before i-initial words) when the next element starts with one of the
|
|
3122
|
+
// variant's triggers. In the last separator the pair word is swapped for the
|
|
3123
|
+
// variant's (es "a, b e inglés")
|
|
3124
|
+
func tnIntlPairSep(l *TnIntlListFormat, second string) string {
|
|
3125
|
+
return tnIntlContextSep(l, second, "pair")
|
|
3126
|
+
}
|
|
3127
|
+
|
|
3128
|
+
func tnIntlContextSep(l *TnIntlListFormat, second string, sep string) string {
|
|
3129
|
+
data := tnIntlListParts(l.loc.data)
|
|
3130
|
+
key := tnIntlListKey(l)
|
|
3131
|
+
pair := data[key+":pair"]
|
|
3132
|
+
base := data[key+":"+sep]
|
|
3133
|
+
if alt, ok := data[key+":pairAlt"]; ok {
|
|
3134
|
+
parts := strings.SplitN(alt, "\\u0001", 2)
|
|
3135
|
+
if len(parts) == 2 {
|
|
3136
|
+
lower := strings.ToLower(second)
|
|
3137
|
+
for _, trigger := range strings.Split(parts[0], ",") {
|
|
3138
|
+
if trigger != "" && strings.HasPrefix(lower, trigger) {
|
|
3139
|
+
variants := strings.Split(parts[1], "\\u0001")
|
|
3140
|
+
if len(variants) == 0 {
|
|
3141
|
+
break
|
|
3142
|
+
}
|
|
3143
|
+
if sep == "pair" {
|
|
3144
|
+
return variants[0]
|
|
3145
|
+
}
|
|
3146
|
+
word, variant := strings.TrimSpace(pair), strings.TrimSpace(variants[0])
|
|
3147
|
+
if word != "" && strings.Contains(base, word) {
|
|
3148
|
+
return strings.Replace(base, word, variant, 1)
|
|
3149
|
+
}
|
|
3150
|
+
return base
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3155
|
+
return base
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
func tnIntlListKey(l *TnIntlListFormat) string {
|
|
3159
|
+
return map[string]string{"conjunction": "conj", "disjunction": "disj", "unit": "unit"}[l.type_] + ":" + l.style
|
|
3160
|
+
}
|
|
3161
|
+
|
|
3162
|
+
func TnIntlListFormatParts(l *TnIntlListFormat, items interface{}) []interface{} {
|
|
3163
|
+
data := tnIntlListParts(l.loc.data)
|
|
3164
|
+
key := tnIntlListKey(l)
|
|
3165
|
+
list := tnIntlItemList(items)
|
|
3166
|
+
out := []interface{}{}
|
|
3167
|
+
if len(list) == 0 {
|
|
3168
|
+
return out
|
|
3169
|
+
}
|
|
3170
|
+
if len(list) == 1 {
|
|
3171
|
+
out = append(out, tnIntlObj("type", "element", "value", list[0]))
|
|
3172
|
+
return out
|
|
3173
|
+
}
|
|
3174
|
+
for i, e := range list {
|
|
3175
|
+
if i > 0 {
|
|
3176
|
+
sep := ""
|
|
3177
|
+
if len(list) == 2 {
|
|
3178
|
+
sep = tnIntlPairSep(l, e)
|
|
3179
|
+
} else if i == 1 {
|
|
3180
|
+
sep = data[key+":start"]
|
|
3181
|
+
} else if i == len(list)-1 {
|
|
3182
|
+
sep = tnIntlContextSep(l, e, "end")
|
|
3183
|
+
} else {
|
|
3184
|
+
sep = data[key+":middle"]
|
|
3185
|
+
}
|
|
3186
|
+
if sep != "" {
|
|
3187
|
+
out = append(out, tnIntlObj("type", "literal", "value", sep))
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
out = append(out, tnIntlObj("type", "element", "value", e))
|
|
3191
|
+
}
|
|
3192
|
+
return out
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3195
|
+
func TnIntlListFormatFormat(l *TnIntlListFormat, items interface{}) string {
|
|
3196
|
+
var b strings.Builder
|
|
3197
|
+
for _, p := range TnIntlListFormatParts(l, items) {
|
|
3198
|
+
b.WriteString(TnJSString(tnIntlGet(p, "value")))
|
|
3199
|
+
}
|
|
3200
|
+
return b.String()
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
func (l *TnIntlListFormat) resolvedOptions() interface{} {
|
|
3204
|
+
return tnIntlObj("locale", l.loc.id, "type", l.type_, "style", l.style)
|
|
3205
|
+
}
|
|
3206
|
+
|
|
3207
|
+
// --- Intl.RelativeTimeFormat
|
|
3208
|
+
|
|
3209
|
+
type TnIntlRelativeTimeFormat struct {
|
|
3210
|
+
loc *TnIntlLoc
|
|
3211
|
+
numeric string
|
|
3212
|
+
style string
|
|
3213
|
+
}
|
|
3214
|
+
|
|
3215
|
+
var tnIntlRelUnits = map[string]bool{"second": true, "minute": true, "hour": true, "day": true, "week": true, "month": true, "quarter": true, "year": true}
|
|
3216
|
+
|
|
3217
|
+
func tnIntlRelUnit(unit string) string {
|
|
3218
|
+
if tnIntlRelUnits[unit] {
|
|
3219
|
+
return unit
|
|
3220
|
+
}
|
|
3221
|
+
if strings.HasSuffix(unit, "s") && tnIntlRelUnits[unit[:len(unit)-1]] {
|
|
3222
|
+
return unit[:len(unit)-1]
|
|
3223
|
+
}
|
|
3224
|
+
tnIntlRangeError("Invalid unit: " + unit)
|
|
3225
|
+
return ""
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
func TnNewIntlRelativeTimeFormat(locales interface{}, options interface{}) *TnIntlRelativeTimeFormat {
|
|
3229
|
+
r := &TnIntlRelativeTimeFormat{loc: TnIntlResolve(locales), numeric: "always", style: "long"}
|
|
3230
|
+
if v, ok := tnIntlOptStr(options, "numeric"); ok {
|
|
3231
|
+
if v != "always" && v != "auto" {
|
|
3232
|
+
tnIntlRangeError("Invalid numeric: " + v)
|
|
3233
|
+
}
|
|
3234
|
+
r.numeric = v
|
|
3235
|
+
}
|
|
3236
|
+
if v, ok := tnIntlOptStr(options, "style"); ok {
|
|
3237
|
+
if v != "long" && v != "short" && v != "narrow" {
|
|
3238
|
+
tnIntlRangeError("Invalid style: " + v)
|
|
3239
|
+
}
|
|
3240
|
+
r.style = v
|
|
3241
|
+
}
|
|
3242
|
+
return r
|
|
3243
|
+
}
|
|
3244
|
+
|
|
3245
|
+
// The pattern for a value and unit, with the {n} placeholder
|
|
3246
|
+
func (r *TnIntlRelativeTimeFormat) patternFor(value float64, unit string) string {
|
|
3247
|
+
data := tnIntlRelParts(r.loc.data)
|
|
3248
|
+
unit = tnIntlRelUnit(unit)
|
|
3249
|
+
style := map[string]string{"long": "l", "short": "s", "narrow": "n"}[r.style]
|
|
3250
|
+
if r.numeric == "auto" && value == math.Trunc(value) && value >= -2 && value <= 2 {
|
|
3251
|
+
if v, ok := data["relauto:"+unit+":"+style+":"+strconv.Itoa(int(value))]; ok {
|
|
3252
|
+
return v
|
|
3253
|
+
}
|
|
3254
|
+
}
|
|
3255
|
+
cat := tnIntlPluralOfNumber(r.loc.tag, math.Abs(value))
|
|
3256
|
+
sign := "f"
|
|
3257
|
+
if value < 0 {
|
|
3258
|
+
sign = "p"
|
|
3259
|
+
}
|
|
3260
|
+
nk := "N"
|
|
3261
|
+
if r.numeric == "auto" {
|
|
3262
|
+
nk = "A"
|
|
3263
|
+
}
|
|
3264
|
+
key := "rel:" + unit + ":" + style + ":" + nk + ":" + cat + ":" + sign
|
|
3265
|
+
if v, ok := data[key]; ok {
|
|
3266
|
+
return v
|
|
3267
|
+
}
|
|
3268
|
+
if v, ok := data["rel:"+unit+":"+style+":N:other:"+sign]; ok {
|
|
3269
|
+
return v
|
|
3270
|
+
}
|
|
3271
|
+
if v, ok := data["rel:"+unit+":l:N:other:"+sign]; ok {
|
|
3272
|
+
return v
|
|
3273
|
+
}
|
|
3274
|
+
return strconv.FormatFloat(math.Abs(value), 'f', -1, 64) + " " + unit
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3277
|
+
// The number inside the pattern: the locale's decimal formatting with three
|
|
3278
|
+
// fraction digits at most (as ICU renders it)
|
|
3279
|
+
func (r *TnIntlRelativeTimeFormat) numberFor(value float64) string {
|
|
3280
|
+
f := TnNewIntlNumberFormat(r.loc.id, map[string]interface{}{"maximumFractionDigits": float64(3)})
|
|
3281
|
+
return TnIntlNumberFormatAnyStr(f, math.Abs(value))
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3284
|
+
func TnIntlRelativeFormat(r *TnIntlRelativeTimeFormat, value interface{}, unit string) string {
|
|
3285
|
+
v := TnNumber(value)
|
|
3286
|
+
s := r.patternFor(v, tnIntlRelUnit(unit))
|
|
3287
|
+
return strings.ReplaceAll(s, "{n}", r.numberFor(v))
|
|
3288
|
+
}
|
|
3289
|
+
|
|
3290
|
+
func TnIntlRelativeParts(r *TnIntlRelativeTimeFormat, value interface{}, unit string) []interface{} {
|
|
3291
|
+
v := TnNumber(value)
|
|
3292
|
+
unit = tnIntlRelUnit(unit)
|
|
3293
|
+
s := r.patternFor(v, unit)
|
|
3294
|
+
out := []interface{}{}
|
|
3295
|
+
before, after, found := strings.Cut(s, "{n}")
|
|
3296
|
+
if !found {
|
|
3297
|
+
out = append(out, tnIntlObj("type", "literal", "value", s))
|
|
3298
|
+
return out
|
|
3299
|
+
}
|
|
3300
|
+
if before != "" {
|
|
3301
|
+
out = append(out, tnIntlObj("type", "literal", "value", before))
|
|
3302
|
+
}
|
|
3303
|
+
f := TnNewIntlNumberFormat(r.loc.id, map[string]interface{}{"maximumFractionDigits": float64(3)})
|
|
3304
|
+
out = append(out, tnIntlNumJSParts2(TnIntlNumberFormatAny(f, math.Abs(v)), unit)...)
|
|
3305
|
+
if after != "" {
|
|
3306
|
+
out = append(out, tnIntlObj("type", "literal", "value", after))
|
|
3307
|
+
}
|
|
3308
|
+
return out
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
// A number's parts with the unit tag added (RelativeTimeFormat's parts carry it)
|
|
3312
|
+
func tnIntlNumJSParts2(parts []interface{}, unit string) []interface{} {
|
|
3313
|
+
out := []interface{}{}
|
|
3314
|
+
for _, p := range parts {
|
|
3315
|
+
m := p.(*TnMap[string, interface{}])
|
|
3316
|
+
switch m.Get("type") {
|
|
3317
|
+
case "integer", "group", "decimal", "fraction", "minusSign", "plusSign":
|
|
3318
|
+
m.Set("unit", unit)
|
|
3319
|
+
}
|
|
3320
|
+
out = append(out, m)
|
|
3321
|
+
}
|
|
3322
|
+
return out
|
|
3323
|
+
}
|
|
3324
|
+
|
|
3325
|
+
func (r *TnIntlRelativeTimeFormat) resolvedOptions() interface{} {
|
|
3326
|
+
nu := r.loc.tag.TypeForKey("nu")
|
|
3327
|
+
if nu == "" {
|
|
3328
|
+
nu = "latn"
|
|
3329
|
+
}
|
|
3330
|
+
return tnIntlObj("locale", r.loc.id, "style", r.style, "numeric", r.numeric, "numberingSystem", nu)
|
|
3331
|
+
}`;
|
|
3332
|
+
const intlSegGo = `// Intl.Segmenter: the UAX #29 rules (grapheme clusters, words with their
|
|
3333
|
+
// isWordLike flag, sentences). CJK words break per ideograph — ICU's
|
|
3334
|
+
// dictionary-based word breaks are not implemented.
|
|
3335
|
+
|
|
3336
|
+
type TnIntlSegmenter struct {
|
|
3337
|
+
loc *TnIntlLoc
|
|
3338
|
+
granularity string
|
|
3339
|
+
}
|
|
3340
|
+
|
|
3341
|
+
func TnNewIntlSegmenter(locales interface{}, options interface{}) *TnIntlSegmenter {
|
|
3342
|
+
s := &TnIntlSegmenter{loc: TnIntlResolve(locales), granularity: "grapheme"}
|
|
3343
|
+
if v, ok := tnIntlOptStr(options, "granularity"); ok {
|
|
3344
|
+
if v != "grapheme" && v != "word" && v != "sentence" {
|
|
3345
|
+
tnIntlRangeError("Invalid granularity: " + v)
|
|
3346
|
+
}
|
|
3347
|
+
s.granularity = v
|
|
3348
|
+
}
|
|
3349
|
+
return s
|
|
3350
|
+
}
|
|
3351
|
+
|
|
3352
|
+
// The grapheme-break property of a rune: 1 CR, 2 LF, 3 Control, 4 Extend, 5
|
|
3353
|
+
// ZWJ, 6 Regional_Indicator, 7 Prepend, 8 SpacingMark, 9/10/11 Hangul L/V/T,
|
|
3354
|
+
// 12/13 LV/LVT, 14 Extended_Pictographic
|
|
3355
|
+
func tnIntlGBProp(r rune) int {
|
|
3356
|
+
switch {
|
|
3357
|
+
case r == 0x0D:
|
|
3358
|
+
return 1
|
|
3359
|
+
case r == 0x0A:
|
|
3360
|
+
return 2
|
|
3361
|
+
case r == 0x200D:
|
|
3362
|
+
return 5
|
|
3363
|
+
case r >= 0x1F1E6 && r <= 0x1F1FF:
|
|
3364
|
+
return 6
|
|
3365
|
+
case r >= 0x1100 && r <= 0x115F, r >= 0xA960 && r <= 0xA97C:
|
|
3366
|
+
return 9
|
|
3367
|
+
case r >= 0x1160 && r <= 0x11A7, r >= 0xD7B0 && r <= 0xD7C6:
|
|
3368
|
+
return 10
|
|
3369
|
+
case r >= 0x11A8 && r <= 0x11FF, r >= 0xD7CB && r <= 0xD7FB:
|
|
3370
|
+
return 11
|
|
3371
|
+
case r >= 0x1F3FB && r <= 0x1F3FF:
|
|
3372
|
+
return 4 // emoji modifiers behave as Extend
|
|
3373
|
+
case r >= 0x0600 && r <= 0x0605, r == 0x06DD, r == 0x070F, r >= 0x0890 && r <= 0x0891, r == 0x08E2, r == 0x0D4E, r == 0x110BD, r == 0x110CD, r >= 0x111C2 && r <= 0x111C3, r == 0x11A3A, r >= 0x11A84 && r <= 0x11A89, r == 0x11D46, r == 0x11F02:
|
|
3374
|
+
return 7
|
|
3375
|
+
case r == 0x200C, r >= 0xE0020 && r <= 0xE007F:
|
|
3376
|
+
return 4
|
|
3377
|
+
case unicode.Is(unicode.Cc, r), unicode.Is(unicode.Zl, r), unicode.Is(unicode.Zp, r), unicode.Is(unicode.Cf, r):
|
|
3378
|
+
return 3
|
|
3379
|
+
case unicode.Is(unicode.Mn, r), unicode.Is(unicode.Me, r), r == 0x200C:
|
|
3380
|
+
return 4
|
|
3381
|
+
case unicode.Is(unicode.Mc, r):
|
|
3382
|
+
return 8
|
|
3383
|
+
}
|
|
3384
|
+
if r >= 0xAC00 && r <= 0xD7A3 {
|
|
3385
|
+
if (r-0xAC00)%28 == 0 {
|
|
3386
|
+
return 12
|
|
3387
|
+
}
|
|
3388
|
+
return 13
|
|
3389
|
+
}
|
|
3390
|
+
if tnIntlIsExtPict(r) {
|
|
3391
|
+
return 14
|
|
3392
|
+
}
|
|
3393
|
+
return 0
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
// Extended_Pictographic (the emoji planes' common ranges)
|
|
3397
|
+
func tnIntlIsExtPict(r rune) bool {
|
|
3398
|
+
switch {
|
|
3399
|
+
case r == 0x00A9 || r == 0x00AE || r == 0x203C || r == 0x2049 || r == 0x2122 || r == 0x2139:
|
|
3400
|
+
return true
|
|
3401
|
+
case r >= 0x2194 && r <= 0x21AA, r >= 0x231A && r <= 0x231B, r >= 0x2328 && r <= 0x23FA:
|
|
3402
|
+
return true
|
|
3403
|
+
case r >= 0x25AA && r <= 0x25FE, r >= 0x2600 && r <= 0x27BF, r >= 0x2934 && r <= 0x2935:
|
|
3404
|
+
return true
|
|
3405
|
+
case r >= 0x2B05 && r <= 0x2B55, r >= 0x3030 && r <= 0x303D, r >= 0x3297 && r <= 0x3299:
|
|
3406
|
+
return true
|
|
3407
|
+
case r >= 0x1F000 && r <= 0x1FAFF, r >= 0x1FC00 && r <= 0x1FFFD:
|
|
3408
|
+
return true
|
|
3409
|
+
}
|
|
3410
|
+
return false
|
|
3411
|
+
}
|
|
3412
|
+
|
|
3413
|
+
// The grapheme clusters of a string (UAX #29 GB3-GB13), as [start, end) byte
|
|
3414
|
+
// offsets
|
|
3415
|
+
func tnIntlGraphemes(s string, cb func(start, end int)) {
|
|
3416
|
+
start := 0
|
|
3417
|
+
prev := -1
|
|
3418
|
+
riCount := 0 // regional indicators in a row, before this rune
|
|
3419
|
+
inPict := false // inside ExtPict Extend*
|
|
3420
|
+
pictZWJ := false // right after ExtPict Extend* ZWJ
|
|
3421
|
+
for pos := 0; pos < len(s); {
|
|
3422
|
+
r, size := utf8.DecodeRuneInString(s[pos:])
|
|
3423
|
+
p := tnIntlGBProp(r)
|
|
3424
|
+
if pos > 0 && tnIntlGBBreak(prev, p, riCount, pictZWJ) {
|
|
3425
|
+
cb(start, pos)
|
|
3426
|
+
start = pos
|
|
3427
|
+
}
|
|
3428
|
+
if p == 6 {
|
|
3429
|
+
riCount++
|
|
3430
|
+
} else {
|
|
3431
|
+
riCount = 0
|
|
3432
|
+
}
|
|
3433
|
+
switch p {
|
|
3434
|
+
case 14:
|
|
3435
|
+
inPict, pictZWJ = true, false
|
|
3436
|
+
case 5:
|
|
3437
|
+
pictZWJ, inPict = inPict, false
|
|
3438
|
+
case 4:
|
|
3439
|
+
pictZWJ = false
|
|
3440
|
+
default:
|
|
3441
|
+
inPict, pictZWJ = false, false
|
|
3442
|
+
}
|
|
3443
|
+
prev = p
|
|
3444
|
+
pos += size
|
|
3445
|
+
}
|
|
3446
|
+
if start < len(s) {
|
|
3447
|
+
cb(start, len(s))
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
// Whether a grapheme cluster ends between runes of properties a and b
|
|
3452
|
+
func tnIntlGBBreak(a, b, riCount int, pictZWJ bool) bool {
|
|
3453
|
+
switch {
|
|
3454
|
+
case a == 1 && b == 2:
|
|
3455
|
+
return false // GB3 CR × LF
|
|
3456
|
+
case a == 1 || a == 2 || a == 3, b == 1 || b == 2 || b == 3:
|
|
3457
|
+
return true // GB4/5 around controls
|
|
3458
|
+
case a == 9 && (b == 9 || b == 10 || b == 12 || b == 13):
|
|
3459
|
+
return false // GB6 L × (L | V | LV | LVT)
|
|
3460
|
+
case (a == 12 || a == 10) && (b == 10 || b == 11):
|
|
3461
|
+
return false // GB7 (LV | V) × (V | T)
|
|
3462
|
+
case (a == 13 || a == 11) && b == 11:
|
|
3463
|
+
return false // GB8 (LVT | T) × T
|
|
3464
|
+
case b == 4 || b == 5 || b == 8:
|
|
3465
|
+
return false // GB9/9a × (Extend | ZWJ | SpacingMark)
|
|
3466
|
+
case a == 7:
|
|
3467
|
+
return false // GB9b Prepend ×
|
|
3468
|
+
case a == 5 && b == 14 && pictZWJ:
|
|
3469
|
+
return false // GB11 ExtPict Extend* ZWJ × ExtPict
|
|
3470
|
+
case a == 6 && b == 6:
|
|
3471
|
+
return riCount%2 == 0 // GB12/13 regional-indicator pairs
|
|
3472
|
+
}
|
|
3473
|
+
return true
|
|
3474
|
+
}
|
|
3475
|
+
|
|
3476
|
+
// Word break classes (UAX #29, as ICU 78 applies them)
|
|
3477
|
+
const (
|
|
3478
|
+
tnWBOther = iota
|
|
3479
|
+
tnWBCR
|
|
3480
|
+
tnWBLF
|
|
3481
|
+
tnWBNewline
|
|
3482
|
+
tnWBExtend
|
|
3483
|
+
tnWBZWJ
|
|
3484
|
+
tnWBRI
|
|
3485
|
+
tnWBKatakana
|
|
3486
|
+
tnWBHiragana
|
|
3487
|
+
tnWBIdeo
|
|
3488
|
+
tnWBALetter
|
|
3489
|
+
tnWBSingleQuote
|
|
3490
|
+
tnWBMidNumLet
|
|
3491
|
+
tnWBMidLetter
|
|
3492
|
+
tnWBMidNum
|
|
3493
|
+
tnWBNumeric
|
|
3494
|
+
tnWBExtendNumLet
|
|
3495
|
+
tnWBSpace
|
|
3496
|
+
)
|
|
3497
|
+
|
|
3498
|
+
func tnIntlWBClass(r rune) int {
|
|
3499
|
+
switch {
|
|
3500
|
+
case r == 13:
|
|
3501
|
+
return tnWBCR
|
|
3502
|
+
case r == 10:
|
|
3503
|
+
return tnWBLF
|
|
3504
|
+
case r == 11 || r == 12 || r == 0x85 || r == 0x2028 || r == 0x2029:
|
|
3505
|
+
return tnWBNewline
|
|
3506
|
+
case r == 0x200D:
|
|
3507
|
+
return tnWBZWJ
|
|
3508
|
+
case r >= 0x1F1E6 && r <= 0x1F1FF:
|
|
3509
|
+
return tnWBRI
|
|
3510
|
+
case r == 39:
|
|
3511
|
+
return tnWBSingleQuote
|
|
3512
|
+
case r == 46 || r == 0x2018 || r == 0x2019 || r == 0x2024 || r == 0xFE52 || r == 0xFF07 || r == 0xFF0E:
|
|
3513
|
+
return tnWBMidNumLet
|
|
3514
|
+
case r == 58 || r == 0xB7 || r == 0x387 || r == 0x55F || r == 0x5F4 || r == 0x2027 || r == 0xFE13 || r == 0xFE55 || r == 0xFF1A:
|
|
3515
|
+
return tnWBMidLetter
|
|
3516
|
+
case r == 44 || r == 59 || r == 0x37E || r == 0x589 || r == 0x60C || r == 0x60D || r == 0x66C || r == 0x7F8 || r == 0x2044 || r == 0xFE10 || r == 0xFE14 || r == 0xFE50 || r == 0xFE54 || r == 0xFF0C || r == 0xFF1B:
|
|
3517
|
+
return tnWBMidNum
|
|
3518
|
+
case r == 95 || r == 0x203F || r == 0x2040 || r == 0x2054 || r == 0xFE33 || r == 0xFE34 || (r >= 0xFE4D && r <= 0xFE4F) || r == 0xFF3F:
|
|
3519
|
+
return tnWBExtendNumLet
|
|
3520
|
+
case unicode.Is(unicode.Mn, r), unicode.Is(unicode.Me, r), unicode.Is(unicode.Mc, r), r == 0x200C:
|
|
3521
|
+
return tnWBExtend
|
|
3522
|
+
case r >= 0x1F3FB && r <= 0x1F3FF, r >= 0xE0020 && r <= 0xE007F:
|
|
3523
|
+
return tnWBExtend
|
|
3524
|
+
case unicode.Is(unicode.Cf, r) && r != 0x200B:
|
|
3525
|
+
return tnWBExtend
|
|
3526
|
+
case r == 32 || r == 0x1680 || (r >= 0x2000 && r <= 0x2006) || (r >= 0x2008 && r <= 0x200A) || r == 0x205F || r == 0x3000:
|
|
3527
|
+
return tnWBSpace
|
|
3528
|
+
case r == 0x30FB:
|
|
3529
|
+
return tnWBOther
|
|
3530
|
+
case (r >= 0x30A0 && r <= 0x30FF) || (r >= 0x31F0 && r <= 0x31FF) || (r >= 0x32D0 && r <= 0x32FE) || (r >= 0x3300 && r <= 0x3357) || (r >= 0xFF66 && r <= 0xFF9D) || (r >= 0x3031 && r <= 0x3035) || r == 0x309B || r == 0x309C:
|
|
3531
|
+
return tnWBKatakana
|
|
3532
|
+
case r >= 0x3040 && r <= 0x309F:
|
|
3533
|
+
return tnWBHiragana
|
|
3534
|
+
case unicode.Is(unicode.Han, r):
|
|
3535
|
+
return tnWBIdeo
|
|
3536
|
+
case unicode.IsDigit(r):
|
|
3537
|
+
return tnWBNumeric
|
|
3538
|
+
case unicode.IsLetter(r):
|
|
3539
|
+
return tnWBALetter
|
|
3540
|
+
}
|
|
3541
|
+
return tnWBOther
|
|
3542
|
+
}
|
|
3543
|
+
|
|
3544
|
+
type tnIntlWBUnit struct {
|
|
3545
|
+
cls, start, end int
|
|
3546
|
+
zwj bool // ends with a ZWJ
|
|
3547
|
+
pict bool // starts with an Extended_Pictographic
|
|
3548
|
+
}
|
|
3549
|
+
|
|
3550
|
+
// The words of a string (UAX #29 WB1-WB16) with ICU's isWordLike (letters,
|
|
3551
|
+
// numbers, kana, ideographs, connector runs). Without ICU's dictionaries,
|
|
3552
|
+
// hiragana runs stay together and each ideograph is its own word; Thai, Lao,
|
|
3553
|
+
// Khmer and Myanmar runs are one word each
|
|
3554
|
+
func tnIntlWords(s string, cb func(start, end int, wordLike bool)) {
|
|
3555
|
+
units := []tnIntlWBUnit{}
|
|
3556
|
+
for pos := 0; pos < len(s); {
|
|
3557
|
+
r, size := utf8.DecodeRuneInString(s[pos:])
|
|
3558
|
+
c := tnIntlWBClass(r)
|
|
3559
|
+
n := len(units)
|
|
3560
|
+
// WB4: Extend / Format / ZWJ belong to the unit before (not after a newline)
|
|
3561
|
+
if (c == tnWBExtend || c == tnWBZWJ) && n > 0 && units[n-1].cls != tnWBCR && units[n-1].cls != tnWBLF && units[n-1].cls != tnWBNewline {
|
|
3562
|
+
units[n-1].end = pos + size
|
|
3563
|
+
units[n-1].zwj = c == tnWBZWJ
|
|
3564
|
+
pos += size
|
|
3565
|
+
continue
|
|
3566
|
+
}
|
|
3567
|
+
units = append(units, tnIntlWBUnit{cls: c, start: pos, end: pos + size, zwj: c == tnWBZWJ, pict: tnIntlIsExtPict(r)})
|
|
3568
|
+
pos += size
|
|
3569
|
+
}
|
|
3570
|
+
if len(units) == 0 {
|
|
3571
|
+
return
|
|
3572
|
+
}
|
|
3573
|
+
cls := func(i int) int {
|
|
3574
|
+
if i < 0 || i >= len(units) {
|
|
3575
|
+
return -1
|
|
3576
|
+
}
|
|
3577
|
+
return units[i].cls
|
|
3578
|
+
}
|
|
3579
|
+
isAH := func(c int) bool { return c == tnWBALetter }
|
|
3580
|
+
isMidLetter := func(c int) bool { return c == tnWBMidLetter || c == tnWBMidNumLet || c == tnWBSingleQuote }
|
|
3581
|
+
isMidNum := func(c int) bool { return c == tnWBMidNum || c == tnWBMidNumLet || c == tnWBSingleQuote }
|
|
3582
|
+
wordish := func(c int) bool {
|
|
3583
|
+
return c == tnWBALetter || c == tnWBNumeric || c == tnWBKatakana || c == tnWBHiragana || c == tnWBIdeo || c == tnWBExtendNumLet
|
|
3584
|
+
}
|
|
3585
|
+
riRun := 0
|
|
3586
|
+
joins := func(i int) bool {
|
|
3587
|
+
a, b := cls(i-1), cls(i)
|
|
3588
|
+
switch {
|
|
3589
|
+
case a == tnWBCR && b == tnWBLF:
|
|
3590
|
+
return true // WB3
|
|
3591
|
+
case a == tnWBCR || a == tnWBLF || a == tnWBNewline || b == tnWBCR || b == tnWBLF || b == tnWBNewline:
|
|
3592
|
+
return false // WB3a/3b
|
|
3593
|
+
case units[i-1].zwj && units[i].pict:
|
|
3594
|
+
return true // WB3c ZWJ × ExtPict
|
|
3595
|
+
case a == tnWBSpace && b == tnWBSpace:
|
|
3596
|
+
return true // WB3d
|
|
3597
|
+
case isAH(a) && isAH(b):
|
|
3598
|
+
return true // WB5
|
|
3599
|
+
case isAH(a) && isMidLetter(b) && isAH(cls(i+1)):
|
|
3600
|
+
return true // WB6
|
|
3601
|
+
case isMidLetter(a) && isAH(cls(i-2)) && isAH(b):
|
|
3602
|
+
return true // WB7
|
|
3603
|
+
case a == tnWBNumeric && b == tnWBNumeric, isAH(a) && b == tnWBNumeric, a == tnWBNumeric && isAH(b):
|
|
3604
|
+
return true // WB8-10
|
|
3605
|
+
case isMidNum(a) && cls(i-2) == tnWBNumeric && b == tnWBNumeric:
|
|
3606
|
+
return true // WB11
|
|
3607
|
+
case a == tnWBNumeric && isMidNum(b) && cls(i+1) == tnWBNumeric:
|
|
3608
|
+
return true // WB12
|
|
3609
|
+
case a == tnWBKatakana && b == tnWBKatakana:
|
|
3610
|
+
return true // WB13
|
|
3611
|
+
case (isAH(a) || a == tnWBNumeric || a == tnWBKatakana || a == tnWBExtendNumLet) && b == tnWBExtendNumLet:
|
|
3612
|
+
return true // WB13a
|
|
3613
|
+
case a == tnWBExtendNumLet && (isAH(b) || b == tnWBNumeric || b == tnWBKatakana):
|
|
3614
|
+
return true // WB13b
|
|
3615
|
+
case a == tnWBRI && b == tnWBRI:
|
|
3616
|
+
return riRun%2 == 1 // WB15/16
|
|
3617
|
+
}
|
|
3618
|
+
return false
|
|
3619
|
+
}
|
|
3620
|
+
start := 0
|
|
3621
|
+
wordLike := wordish(units[0].cls)
|
|
3622
|
+
if units[0].cls == tnWBRI {
|
|
3623
|
+
riRun = 1
|
|
3624
|
+
}
|
|
3625
|
+
for i := 1; i < len(units); i++ {
|
|
3626
|
+
if !joins(i) {
|
|
3627
|
+
cb(units[start].start, units[i].start, wordLike)
|
|
3628
|
+
start = i
|
|
3629
|
+
wordLike = false
|
|
3630
|
+
}
|
|
3631
|
+
if wordish(units[i].cls) {
|
|
3632
|
+
wordLike = true
|
|
3633
|
+
}
|
|
3634
|
+
if units[i].cls == tnWBRI {
|
|
3635
|
+
riRun++
|
|
3636
|
+
} else {
|
|
3637
|
+
riRun = 0
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
cb(units[start].start, len(s), wordLike)
|
|
3641
|
+
}
|
|
3642
|
+
|
|
3643
|
+
// Sentence break classes (UAX #29)
|
|
3644
|
+
const (
|
|
3645
|
+
tnSBOther = iota
|
|
3646
|
+
tnSBSep
|
|
3647
|
+
tnSBSp
|
|
3648
|
+
tnSBLower
|
|
3649
|
+
tnSBUpper
|
|
3650
|
+
tnSBOLetter
|
|
3651
|
+
tnSBNumeric
|
|
3652
|
+
tnSBATerm
|
|
3653
|
+
tnSBSTerm
|
|
3654
|
+
tnSBClose
|
|
3655
|
+
tnSBSContinue
|
|
3656
|
+
tnSBExtend
|
|
3657
|
+
)
|
|
3658
|
+
|
|
3659
|
+
func tnIntlSBClass(r rune) int {
|
|
3660
|
+
switch {
|
|
3661
|
+
case r == 10 || r == 13 || r == 0x85 || r == 0x2028 || r == 0x2029:
|
|
3662
|
+
return tnSBSep
|
|
3663
|
+
case r == 46 || r == 0x2024 || r == 0xFE52 || r == 0xFF0E:
|
|
3664
|
+
return tnSBATerm
|
|
3665
|
+
case r == 33 || r == 63 || r == 0x589 || (r >= 0x61D && r <= 0x61F) || r == 0x6D4 || (r >= 0x700 && r <= 0x702) || r == 0x7F9 || r == 0x964 || r == 0x965 || r == 0x104A || r == 0x104B || r == 0x1362 || r == 0x1367 || r == 0x1368 || r == 0x166E || r == 0x1803 || r == 0x1809 || r == 0x1944 || r == 0x1945 || r == 0x203C || r == 0x203D || (r >= 0x2047 && r <= 0x2049) || r == 0x2E2E || r == 0x3002 || r == 0xFE56 || r == 0xFE57 || r == 0xFF01 || r == 0xFF1F || r == 0xFF61:
|
|
3666
|
+
return tnSBSTerm
|
|
3667
|
+
case r == 44 || r == 45 || r == 58 || r == 59 || r == 0x55D || r == 0x60C || r == 0x60D || r == 0x7F8 || r == 0x1802 || r == 0x1808 || r == 0x2013 || r == 0x2014 || r == 0x3001 || r == 0xFE10 || r == 0xFE11 || r == 0xFE13 || r == 0xFE31 || r == 0xFE32 || r == 0xFE50 || r == 0xFE51 || r == 0xFE55 || r == 0xFE58 || r == 0xFE63 || r == 0xFF0C || r == 0xFF0D || r == 0xFF1A || r == 0xFF1B || r == 0xFF64:
|
|
3668
|
+
return tnSBSContinue
|
|
3669
|
+
case unicode.Is(unicode.Mn, r), unicode.Is(unicode.Me, r), unicode.Is(unicode.Mc, r), r == 0x200C, r == 0x200D:
|
|
3670
|
+
return tnSBExtend
|
|
3671
|
+
case unicode.Is(unicode.Cf, r) && r != 0x200B:
|
|
3672
|
+
return tnSBExtend
|
|
3673
|
+
case unicode.IsSpace(r):
|
|
3674
|
+
return tnSBSp
|
|
3675
|
+
case unicode.IsLower(r):
|
|
3676
|
+
return tnSBLower
|
|
3677
|
+
case unicode.IsUpper(r) || unicode.IsTitle(r):
|
|
3678
|
+
return tnSBUpper
|
|
3679
|
+
case unicode.IsDigit(r):
|
|
3680
|
+
return tnSBNumeric
|
|
3681
|
+
case unicode.IsLetter(r):
|
|
3682
|
+
return tnSBOLetter
|
|
3683
|
+
case r == 34 || r == 39 || unicode.Is(unicode.Ps, r) || unicode.Is(unicode.Pe, r) || unicode.Is(unicode.Pi, r) || unicode.Is(unicode.Pf, r):
|
|
3684
|
+
return tnSBClose
|
|
3685
|
+
}
|
|
3686
|
+
return tnSBOther
|
|
3687
|
+
}
|
|
3688
|
+
|
|
3689
|
+
// The sentences of a string (UAX #29 SB1-SB11, without ICU's suppressions:
|
|
3690
|
+
// "Mr. Smith" breaks after "Mr. ", as in Node)
|
|
3691
|
+
func tnIntlSentences(s string, cb func(start, end int)) {
|
|
3692
|
+
type unit struct {
|
|
3693
|
+
cls, start int
|
|
3694
|
+
r rune
|
|
3695
|
+
}
|
|
3696
|
+
units := []unit{}
|
|
3697
|
+
for pos := 0; pos < len(s); {
|
|
3698
|
+
r, size := utf8.DecodeRuneInString(s[pos:])
|
|
3699
|
+
c := tnIntlSBClass(r)
|
|
3700
|
+
pos += size
|
|
3701
|
+
// SB5: Extend / Format belong to the unit before (not after a separator)
|
|
3702
|
+
if c == tnSBExtend && len(units) > 0 && units[len(units)-1].cls != tnSBSep {
|
|
3703
|
+
continue
|
|
3704
|
+
}
|
|
3705
|
+
units = append(units, unit{cls: c, start: pos - size, r: r})
|
|
3706
|
+
}
|
|
3707
|
+
n := len(units)
|
|
3708
|
+
cls := func(i int) int {
|
|
3709
|
+
if i < 0 || i >= n {
|
|
3710
|
+
return -1
|
|
3711
|
+
}
|
|
3712
|
+
return units[i].cls
|
|
3713
|
+
}
|
|
3714
|
+
// a separator: CR LF counts as one
|
|
3715
|
+
sepEnd := func(j int) int {
|
|
3716
|
+
if units[j].r == 13 && j+1 < n && units[j+1].r == 10 {
|
|
3717
|
+
return j + 2
|
|
3718
|
+
}
|
|
3719
|
+
return j + 1
|
|
3720
|
+
}
|
|
3721
|
+
start := 0
|
|
3722
|
+
for i := 0; i < n; {
|
|
3723
|
+
c := units[i].cls
|
|
3724
|
+
if c == tnSBSep {
|
|
3725
|
+
j := sepEnd(i) // SB4: break after a paragraph separator
|
|
3726
|
+
if j < n {
|
|
3727
|
+
cb(units[start].start, units[j].start)
|
|
3728
|
+
start = j
|
|
3729
|
+
}
|
|
3730
|
+
i = j
|
|
3731
|
+
continue
|
|
3732
|
+
}
|
|
3733
|
+
if c != tnSBATerm && c != tnSBSTerm {
|
|
3734
|
+
i++
|
|
3735
|
+
continue
|
|
3736
|
+
}
|
|
3737
|
+
j := i + 1
|
|
3738
|
+
if c == tnSBATerm && cls(j) == tnSBNumeric {
|
|
3739
|
+
i = j // SB6 ATerm × Numeric
|
|
3740
|
+
continue
|
|
3741
|
+
}
|
|
3742
|
+
if c == tnSBATerm && (cls(i-1) == tnSBUpper || cls(i-1) == tnSBLower) && cls(j) == tnSBUpper {
|
|
3743
|
+
i = j // SB7 (Upper | Lower) ATerm × Upper
|
|
3744
|
+
continue
|
|
3745
|
+
}
|
|
3746
|
+
for cls(j) == tnSBClose {
|
|
3747
|
+
j++
|
|
3748
|
+
}
|
|
3749
|
+
for cls(j) == tnSBSp {
|
|
3750
|
+
j++
|
|
3751
|
+
}
|
|
3752
|
+
if cls(j) == tnSBSContinue || cls(j) == tnSBATerm || cls(j) == tnSBSTerm {
|
|
3753
|
+
i = j // SB8a
|
|
3754
|
+
continue
|
|
3755
|
+
}
|
|
3756
|
+
if c == tnSBATerm {
|
|
3757
|
+
// SB8: ATerm Close* Sp* × (¬(OLetter | Upper | Lower | Sep | SATerm))* Lower
|
|
3758
|
+
k := j
|
|
3759
|
+
for k < n {
|
|
3760
|
+
ck := units[k].cls
|
|
3761
|
+
if ck == tnSBOLetter || ck == tnSBUpper || ck == tnSBLower || ck == tnSBSep || ck == tnSBATerm || ck == tnSBSTerm {
|
|
3762
|
+
break
|
|
3763
|
+
}
|
|
3764
|
+
k++
|
|
3765
|
+
}
|
|
3766
|
+
if cls(k) == tnSBLower {
|
|
3767
|
+
i = k
|
|
3768
|
+
continue
|
|
3769
|
+
}
|
|
3770
|
+
}
|
|
3771
|
+
if cls(j) == tnSBSep {
|
|
3772
|
+
j = sepEnd(j) // SB9-11: the separator stays with the sentence
|
|
3773
|
+
}
|
|
3774
|
+
if j >= n {
|
|
3775
|
+
break
|
|
3776
|
+
}
|
|
3777
|
+
cb(units[start].start, units[j].start)
|
|
3778
|
+
start = j
|
|
3779
|
+
i = j
|
|
3780
|
+
}
|
|
3781
|
+
if start < n {
|
|
3782
|
+
cb(units[start].start, len(s))
|
|
3783
|
+
}
|
|
3784
|
+
}
|
|
3785
|
+
|
|
3786
|
+
// segment(): the segments of a string; index and containing() count UTF-16
|
|
3787
|
+
// code units, as JS strings do
|
|
3788
|
+
type TnIntlSegmentIter struct {
|
|
3789
|
+
seg *TnIntlSegmenter
|
|
3790
|
+
input string
|
|
3791
|
+
segs []tnIntlSpan
|
|
3792
|
+
}
|
|
3793
|
+
|
|
3794
|
+
type tnIntlSpan struct {
|
|
3795
|
+
start, end int // bytes
|
|
3796
|
+
index, index16 int // UTF-16 offsets of the start and the end
|
|
3797
|
+
wordLike bool
|
|
3798
|
+
}
|
|
3799
|
+
|
|
3800
|
+
func (s *TnIntlSegmenter) segment(input string) *TnIntlSegmentIter {
|
|
3801
|
+
it := &TnIntlSegmentIter{seg: s, input: input}
|
|
3802
|
+
// byte offset → UTF-16 offset
|
|
3803
|
+
u16 := make([]int, len(input)+1)
|
|
3804
|
+
u := 0
|
|
3805
|
+
for i, r := range input {
|
|
3806
|
+
u16[i] = u
|
|
3807
|
+
if r >= 0x10000 {
|
|
3808
|
+
u += 2
|
|
3809
|
+
} else {
|
|
3810
|
+
u++
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
u16[len(input)] = u
|
|
3814
|
+
add := func(start, end int, wordLike bool) {
|
|
3815
|
+
it.segs = append(it.segs, tnIntlSpan{start: start, end: end, index: u16[start], index16: u16[end], wordLike: wordLike})
|
|
3816
|
+
}
|
|
3817
|
+
switch s.granularity {
|
|
3818
|
+
case "word":
|
|
3819
|
+
tnIntlWords(input, add)
|
|
3820
|
+
case "sentence":
|
|
3821
|
+
tnIntlSentences(input, func(start, end int) { add(start, end, false) })
|
|
3822
|
+
default:
|
|
3823
|
+
tnIntlGraphemes(input, func(start, end int) { add(start, end, false) })
|
|
3824
|
+
}
|
|
3825
|
+
return it
|
|
3826
|
+
}
|
|
3827
|
+
|
|
3828
|
+
// for..of / spread: the segments as records ({segment, index, input, isWordLike})
|
|
3829
|
+
func (it *TnIntlSegmentIter) tnItems() []interface{} {
|
|
3830
|
+
out := make([]interface{}, 0, len(it.segs))
|
|
3831
|
+
for _, sp := range it.segs {
|
|
3832
|
+
out = append(out, it.spanAt(sp))
|
|
3833
|
+
}
|
|
3834
|
+
return out
|
|
3835
|
+
}
|
|
3836
|
+
|
|
3837
|
+
func (it *TnIntlSegmentIter) spanAt(sp tnIntlSpan) *TnMap[string, interface{}] {
|
|
3838
|
+
m := tnIntlObj("segment", it.input[sp.start:sp.end], "index", float64(sp.index), "input", it.input)
|
|
3839
|
+
if it.seg.granularity == "word" {
|
|
3840
|
+
m.Set("isWordLike", sp.wordLike)
|
|
3841
|
+
}
|
|
3842
|
+
return m
|
|
3843
|
+
}
|
|
3844
|
+
|
|
3845
|
+
// containing(index): the segment covering a UTF-16 index (0 by default;
|
|
3846
|
+
// undefined outside the string)
|
|
3847
|
+
func (it *TnIntlSegmentIter) containing(index ...interface{}) interface{} {
|
|
3848
|
+
idx := 0.0
|
|
3849
|
+
if len(index) > 0 && index[0] != nil {
|
|
3850
|
+
idx = math.Trunc(TnNumber(index[0]))
|
|
3851
|
+
if math.IsNaN(idx) {
|
|
3852
|
+
idx = 0
|
|
3853
|
+
}
|
|
3854
|
+
}
|
|
3855
|
+
for _, sp := range it.segs {
|
|
3856
|
+
if idx >= float64(sp.index) && idx < float64(sp.index16) {
|
|
3857
|
+
return it.spanAt(sp)
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
return nil
|
|
3861
|
+
}
|
|
3862
|
+
|
|
3863
|
+
func (s *TnIntlSegmenter) resolvedOptions() interface{} {
|
|
3864
|
+
return tnIntlObj("locale", s.loc.id, "granularity", s.granularity)
|
|
3865
|
+
}
|
|
3866
|
+
`;
|
|
3867
|
+
const intlDisplayGo = `// Intl.DisplayNames: the generated tables (the names Node renders), falling
|
|
3868
|
+
// back to golang.org/x/text/language/display for codes they don't list
|
|
3869
|
+
|
|
3870
|
+
func tnIntlDisplayNames(data string) map[string]string {
|
|
3871
|
+
if m := tnIntlDisplay[data]; m != nil {
|
|
3872
|
+
return m
|
|
3873
|
+
}
|
|
3874
|
+
return tnIntlDisplay["en"]
|
|
3875
|
+
}
|
|
3876
|
+
|
|
3877
|
+
type TnIntlDisplayNames struct {
|
|
3878
|
+
loc *TnIntlLoc
|
|
3879
|
+
type_ string
|
|
3880
|
+
fallback string
|
|
3881
|
+
style string
|
|
3882
|
+
languageDisplay string
|
|
3883
|
+
}
|
|
3884
|
+
|
|
3885
|
+
func TnNewIntlDisplayNames(locales interface{}, options interface{}) *TnIntlDisplayNames {
|
|
3886
|
+
d := &TnIntlDisplayNames{loc: TnIntlResolve(locales), fallback: "code", style: "long", languageDisplay: "dialect"}
|
|
3887
|
+
if v, ok := tnIntlOptStr(options, "style"); ok {
|
|
3888
|
+
if v != "long" && v != "short" && v != "narrow" {
|
|
3889
|
+
tnIntlRangeError("Value " + v + " out of range for Intl.DisplayNames options property style")
|
|
3890
|
+
}
|
|
3891
|
+
d.style = v
|
|
3892
|
+
}
|
|
3893
|
+
t, ok := tnIntlOptStr(options, "type")
|
|
3894
|
+
if !ok {
|
|
3895
|
+
panic(TnNodeError("TypeError", "", "Required option 'type' is missing"))
|
|
3896
|
+
}
|
|
3897
|
+
if !tnIntlHasString([]string{"language", "region", "script", "currency", "calendar", "dateTimeField"}, t) {
|
|
3898
|
+
tnIntlRangeError("Value " + t + " out of range for Intl.DisplayNames options property type")
|
|
3899
|
+
}
|
|
3900
|
+
d.type_ = t
|
|
3901
|
+
if v, ok := tnIntlOptStr(options, "fallback"); ok {
|
|
3902
|
+
if v != "code" && v != "none" {
|
|
3903
|
+
tnIntlRangeError("Value " + v + " out of range for Intl.DisplayNames options property fallback")
|
|
3904
|
+
}
|
|
3905
|
+
d.fallback = v
|
|
3906
|
+
}
|
|
3907
|
+
if v, ok := tnIntlOptStr(options, "languageDisplay"); ok {
|
|
3908
|
+
if v != "dialect" && v != "standard" {
|
|
3909
|
+
tnIntlRangeError("Value " + v + " out of range for Intl.DisplayNames options property languageDisplay")
|
|
3910
|
+
}
|
|
3911
|
+
d.languageDisplay = v
|
|
3912
|
+
}
|
|
3913
|
+
return d
|
|
3914
|
+
}
|
|
3915
|
+
|
|
3916
|
+
func tnIntlCapitalize(s string) string {
|
|
3917
|
+
if s == "" {
|
|
3918
|
+
return s
|
|
3919
|
+
}
|
|
3920
|
+
return strings.ToUpper(s[:1]) + s[1:]
|
|
3921
|
+
}
|
|
3922
|
+
|
|
3923
|
+
// A language's name: the generated dialect combos ("Brazilian Portuguese"),
|
|
3924
|
+
// else the script as a parenthetical ("Chinese (Simplified)"), else x/text
|
|
3925
|
+
func tnIntlLanguageName(d *TnIntlDisplayNames, target xlanguage.Tag) string {
|
|
3926
|
+
data := tnIntlDisplayNames(d.loc.data)
|
|
3927
|
+
code := target.String()
|
|
3928
|
+
if v, ok := data["dn:language:"+d.style+":"+code]; ok {
|
|
3929
|
+
return v
|
|
3930
|
+
}
|
|
3931
|
+
base := strings.SplitN(tnIntlBaseOf(code), "-", 2)[0]
|
|
3932
|
+
_, script, _ := target.Raw()
|
|
3933
|
+
if script.String() != "Zzzz" {
|
|
3934
|
+
bName := ""
|
|
3935
|
+
if v, ok := data["dn:language:"+d.style+":"+base]; ok {
|
|
3936
|
+
bName = v
|
|
3937
|
+
} else {
|
|
3938
|
+
bName = xdisplay.Languages(d.loc.tag).Name(xlanguage.MustParse(base))
|
|
3939
|
+
}
|
|
3940
|
+
sName := ""
|
|
3941
|
+
if v, ok := data["dn:script:"+d.style+":"+script.String()]; ok {
|
|
3942
|
+
sName = v
|
|
3943
|
+
} else {
|
|
3944
|
+
sName = xdisplay.Scripts(d.loc.tag).Name(xlanguage.MustParse("und-" + script.String()))
|
|
3945
|
+
}
|
|
3946
|
+
if bName != "" && sName != "" {
|
|
3947
|
+
return bName + " (" + sName + ")"
|
|
3948
|
+
}
|
|
3949
|
+
}
|
|
3950
|
+
if n := xdisplay.Languages(d.loc.tag).Name(target); n != "" {
|
|
3951
|
+
return n
|
|
3952
|
+
}
|
|
3953
|
+
return ""
|
|
3954
|
+
}
|
|
3955
|
+
|
|
3956
|
+
// of(code): the name, else the canonical code (fallback "code") or
|
|
3957
|
+
// undefined (fallback "none"); a malformed code is a RangeError
|
|
3958
|
+
func (d *TnIntlDisplayNames) of(code string) interface{} {
|
|
3959
|
+
data := tnIntlDisplayNames(d.loc.data)
|
|
3960
|
+
invalid := func() { tnIntlRangeError("invalid_argument") }
|
|
3961
|
+
name, canonical := "", code
|
|
3962
|
+
switch d.type_ {
|
|
3963
|
+
case "language":
|
|
3964
|
+
c, ok := tnIntlCanonicalTag(code)
|
|
3965
|
+
if !ok {
|
|
3966
|
+
invalid()
|
|
3967
|
+
}
|
|
3968
|
+
canonical = c
|
|
3969
|
+
if d.languageDisplay == "standard" {
|
|
3970
|
+
name = tnIntlStandardLanguageName(d, c)
|
|
3971
|
+
} else if v, ok := data["dn:language:"+d.style+":"+c]; ok {
|
|
3972
|
+
name = v
|
|
3973
|
+
} else if tag, err := xlanguage.Parse(c); err == nil {
|
|
3974
|
+
name = tnIntlLanguageName(d, tag)
|
|
3975
|
+
}
|
|
3976
|
+
case "region":
|
|
3977
|
+
region := strings.ToUpper(code)
|
|
3978
|
+
if !tnIntlTagRE.MatchString("und-" + region) || (len(region) != 2 && len(region) != 3) {
|
|
3979
|
+
invalid()
|
|
3980
|
+
}
|
|
3981
|
+
canonical = region
|
|
3982
|
+
name = tnIntlRegionName(d, region)
|
|
3983
|
+
case "script":
|
|
3984
|
+
script := tnIntlCapitalize(strings.ToLower(code))
|
|
3985
|
+
if len(script) != 4 || !tnIntlTagRE.MatchString("und-"+script) {
|
|
3986
|
+
invalid()
|
|
3987
|
+
}
|
|
3988
|
+
canonical = script
|
|
3989
|
+
if v, ok := data["dn:script:"+d.style+":"+script]; ok {
|
|
3990
|
+
name = v
|
|
3991
|
+
} else if v, ok := data["dn:script:long:"+script]; ok {
|
|
3992
|
+
name = v
|
|
3993
|
+
} else if t, err := xlanguage.Parse("und-" + script); err == nil {
|
|
3994
|
+
name = xdisplay.Scripts(d.loc.tag).Name(t)
|
|
3995
|
+
}
|
|
3996
|
+
case "currency":
|
|
3997
|
+
cur := strings.ToUpper(code)
|
|
3998
|
+
if len(cur) != 3 {
|
|
3999
|
+
invalid()
|
|
4000
|
+
}
|
|
4001
|
+
canonical = cur
|
|
4002
|
+
if v, ok := data["dn:currency:"+d.style+":"+cur]; ok {
|
|
4003
|
+
name = v
|
|
4004
|
+
} else if v, ok := data["dn:currency:long:"+cur]; ok {
|
|
4005
|
+
name = v
|
|
4006
|
+
}
|
|
4007
|
+
case "calendar", "dateTimeField":
|
|
4008
|
+
canonical = code
|
|
4009
|
+
if v, ok := data["dn:"+d.type_+":"+d.style+":"+code]; ok {
|
|
4010
|
+
name = v
|
|
4011
|
+
} else if v, ok := data["dn:"+d.type_+":long:"+code]; ok {
|
|
4012
|
+
name = v
|
|
4013
|
+
} else if d.type_ == "dateTimeField" && !tnIntlHasString([]string{"era", "year", "quarter", "month", "weekOfYear", "weekday", "day", "dayPeriod", "hour", "minute", "second", "timeZoneName"}, code) {
|
|
4014
|
+
invalid()
|
|
4015
|
+
}
|
|
4016
|
+
}
|
|
4017
|
+
if name != "" && name != canonical {
|
|
4018
|
+
return name
|
|
4019
|
+
}
|
|
4020
|
+
if d.fallback == "none" {
|
|
4021
|
+
return nil
|
|
4022
|
+
}
|
|
4023
|
+
return canonical
|
|
4024
|
+
}
|
|
4025
|
+
|
|
4026
|
+
// A region's name: the generated tables, then golang.org/x/text
|
|
4027
|
+
func tnIntlRegionName(d *TnIntlDisplayNames, region string) string {
|
|
4028
|
+
data := tnIntlDisplayNames(d.loc.data)
|
|
4029
|
+
if v, ok := data["dn:region:"+d.style+":"+region]; ok {
|
|
4030
|
+
return v
|
|
4031
|
+
}
|
|
4032
|
+
if v, ok := data["dn:region:long:"+region]; ok {
|
|
4033
|
+
return v
|
|
4034
|
+
}
|
|
4035
|
+
if t, err := xlanguage.Parse("und-" + region); err == nil {
|
|
4036
|
+
if n := xdisplay.Regions(d.loc.tag).Name(t); n != "" {
|
|
4037
|
+
return n
|
|
4038
|
+
}
|
|
4039
|
+
}
|
|
4040
|
+
return ""
|
|
4041
|
+
}
|
|
4042
|
+
|
|
4043
|
+
// languageDisplay "standard": the language's name with its script and
|
|
4044
|
+
// region names in the locale's pattern ("English (United States)")
|
|
4045
|
+
func tnIntlStandardLanguageName(d *TnIntlDisplayNames, code string) string {
|
|
4046
|
+
data := tnIntlDisplayNames(d.loc.data)
|
|
4047
|
+
tag, err := xlanguage.Parse(code)
|
|
4048
|
+
if err != nil {
|
|
4049
|
+
return ""
|
|
4050
|
+
}
|
|
4051
|
+
base, script, region := tag.Raw()
|
|
4052
|
+
name := ""
|
|
4053
|
+
if v, ok := data["dn:language:"+d.style+":"+base.String()]; ok {
|
|
4054
|
+
name = v
|
|
4055
|
+
} else {
|
|
4056
|
+
name = xdisplay.Languages(d.loc.tag).Name(xlanguage.Make(base.String()))
|
|
4057
|
+
}
|
|
4058
|
+
if name == "" {
|
|
4059
|
+
return ""
|
|
4060
|
+
}
|
|
4061
|
+
extras := []string{}
|
|
4062
|
+
if s := script.String(); s != "Zzzz" && strings.Contains(code, "-"+s) {
|
|
4063
|
+
if v, ok := data["dn:script:long:"+s]; ok {
|
|
4064
|
+
extras = append(extras, v)
|
|
4065
|
+
} else if t, err := xlanguage.Parse("und-" + s); err == nil {
|
|
4066
|
+
extras = append(extras, xdisplay.Scripts(d.loc.tag).Name(t))
|
|
4067
|
+
}
|
|
4068
|
+
}
|
|
4069
|
+
if r := region.String(); r != "ZZ" && strings.Contains(code, "-"+r) {
|
|
4070
|
+
if v := tnIntlRegionName(d, r); v != "" {
|
|
4071
|
+
extras = append(extras, v)
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
if len(extras) == 0 {
|
|
4075
|
+
return name
|
|
4076
|
+
}
|
|
4077
|
+
pattern := data["dn:pattern"]
|
|
4078
|
+
if pattern == "" {
|
|
4079
|
+
pattern = "{0} ({1})"
|
|
4080
|
+
}
|
|
4081
|
+
sep := data["dn:separator"]
|
|
4082
|
+
if sep == "" {
|
|
4083
|
+
sep = ", "
|
|
4084
|
+
}
|
|
4085
|
+
return strings.Replace(strings.Replace(pattern, "{0}", name, 1), "{1}", strings.Join(extras, sep), 1)
|
|
4086
|
+
}
|
|
4087
|
+
|
|
4088
|
+
func (d *TnIntlDisplayNames) resolvedOptions() interface{} {
|
|
4089
|
+
out := tnIntlObj("locale", d.loc.id, "style", d.style, "type", d.type_, "fallback", d.fallback)
|
|
4090
|
+
if d.type_ == "language" {
|
|
4091
|
+
out.Set("languageDisplay", d.languageDisplay)
|
|
4092
|
+
}
|
|
4093
|
+
return out
|
|
4094
|
+
}`;
|
|
4095
|
+
const intlLocaleGo = `// Intl.Locale: a language tag and its parts (golang.org/x/text/language's
|
|
4096
|
+
// parsing, the generated likely-subtags for maximize / minimize)
|
|
4097
|
+
|
|
4098
|
+
type TnIntlLocale struct {
|
|
4099
|
+
id string
|
|
4100
|
+
tag xlanguage.Tag
|
|
4101
|
+
}
|
|
4102
|
+
|
|
4103
|
+
func TnNewIntlLocale(tagStr string, options interface{}) *TnIntlLocale {
|
|
4104
|
+
if _, ok := tnIntlCanonicalTag(tagStr); !ok {
|
|
4105
|
+
panic(TnNodeError("RangeError", "", "Incorrect locale information provided"))
|
|
4106
|
+
}
|
|
4107
|
+
tag, err := xlanguage.Parse(tagStr)
|
|
4108
|
+
if err != nil {
|
|
4109
|
+
tag = xlanguage.Make(tagStr)
|
|
4110
|
+
}
|
|
4111
|
+
// the options replace the tag's parts
|
|
4112
|
+
if options != nil {
|
|
4113
|
+
if v, ok := tnIntlOptStr(options, "language"); ok {
|
|
4114
|
+
if !tnIntlValidLanguage(v) {
|
|
4115
|
+
panic(TnNodeError("RangeError", "", "Invalid language tag: "+tagStr))
|
|
4116
|
+
}
|
|
4117
|
+
tag = tnIntlTagReplace(tag, v, "", "")
|
|
4118
|
+
}
|
|
4119
|
+
if v, ok := tnIntlOptStr(options, "script"); ok {
|
|
4120
|
+
if !tnIntlValidScript(v) {
|
|
4121
|
+
panic(TnNodeError("RangeError", "", "Invalid language tag: "+tagStr))
|
|
4122
|
+
}
|
|
4123
|
+
tag = tnIntlTagReplace(tag, "", tnIntlCapitalize(strings.ToLower(v)), "")
|
|
4124
|
+
}
|
|
4125
|
+
if v, ok := tnIntlOptStr(options, "region"); ok {
|
|
4126
|
+
if !tnIntlValidRegion(v) {
|
|
4127
|
+
panic(TnNodeError("RangeError", "", "Invalid language tag: "+tagStr))
|
|
4128
|
+
}
|
|
4129
|
+
tag = tnIntlTagReplace(tag, "", "", strings.ToUpper(v))
|
|
4130
|
+
}
|
|
4131
|
+
for _, pair := range [][2]string{{"numberingSystem", "nu"}, {"calendar", "ca"}, {"caseFirst", "kf"}} {
|
|
4132
|
+
if v, ok := tnIntlOptStr(options, pair[0]); ok {
|
|
4133
|
+
tag, _ = tag.SetTypeForKey(pair[1], v)
|
|
4134
|
+
}
|
|
4135
|
+
}
|
|
4136
|
+
if v, ok := tnIntlOptStr(options, "hourCycle"); ok {
|
|
4137
|
+
tag, _ = tag.SetTypeForKey("hc", v)
|
|
4138
|
+
}
|
|
4139
|
+
if v, ok := tnIntlOptStr(options, "hour12"); ok {
|
|
4140
|
+
if TnTruthy(v) {
|
|
4141
|
+
tag, _ = tag.SetTypeForKey("hc", "h12")
|
|
4142
|
+
} else {
|
|
4143
|
+
tag, _ = tag.SetTypeForKey("hc", "h23")
|
|
4144
|
+
}
|
|
4145
|
+
}
|
|
4146
|
+
if v, ok := tnIntlOptStr(options, "numeric"); ok {
|
|
4147
|
+
if v != "true" && v != "false" {
|
|
4148
|
+
panic(TnNodeError("RangeError", "", "Invalid numeric: "+v))
|
|
4149
|
+
}
|
|
4150
|
+
tag, _ = tag.SetTypeForKey("kn", v)
|
|
4151
|
+
}
|
|
4152
|
+
}
|
|
4153
|
+
return &TnIntlLocale{id: tag.String(), tag: tag}
|
|
4154
|
+
}
|
|
4155
|
+
|
|
4156
|
+
func tnIntlValidLanguage(s string) bool {
|
|
4157
|
+
if len(s) < 2 || len(s) > 8 {
|
|
4158
|
+
return false
|
|
4159
|
+
}
|
|
4160
|
+
for _, c := range s {
|
|
4161
|
+
if (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') {
|
|
4162
|
+
return false
|
|
4163
|
+
}
|
|
4164
|
+
}
|
|
4165
|
+
return true
|
|
4166
|
+
}
|
|
4167
|
+
|
|
4168
|
+
func tnIntlValidScript(s string) bool {
|
|
4169
|
+
return len(s) == 4 && tnIntlValidLanguage(s)
|
|
4170
|
+
}
|
|
4171
|
+
|
|
4172
|
+
func tnIntlValidRegion(s string) bool {
|
|
4173
|
+
if len(s) == 2 {
|
|
4174
|
+
return (s[0] >= 'a' && s[0] <= 'z' || s[0] >= 'A' && s[0] <= 'Z') && (s[1] >= 'a' && s[1] <= 'z' || s[1] >= 'A' && s[1] <= 'Z')
|
|
4175
|
+
}
|
|
4176
|
+
if len(s) == 3 {
|
|
4177
|
+
for i := 0; i < 3; i++ {
|
|
4178
|
+
if s[i] < '0' || s[i] > '9' {
|
|
4179
|
+
return false
|
|
4180
|
+
}
|
|
4181
|
+
}
|
|
4182
|
+
return true
|
|
4183
|
+
}
|
|
4184
|
+
return false
|
|
4185
|
+
}
|
|
4186
|
+
|
|
4187
|
+
// The tag with its language / script / region replaced
|
|
4188
|
+
func tnIntlTagReplace(tag xlanguage.Tag, language, script, region string) xlanguage.Tag {
|
|
4189
|
+
id := tag.String()
|
|
4190
|
+
base := tnIntlBaseOf(id)
|
|
4191
|
+
parts := strings.Split(base, "-")
|
|
4192
|
+
out := []string{}
|
|
4193
|
+
if language != "" {
|
|
4194
|
+
out = append(out, strings.ToLower(language))
|
|
4195
|
+
} else {
|
|
4196
|
+
out = append(out, parts[0])
|
|
4197
|
+
}
|
|
4198
|
+
if script != "" {
|
|
4199
|
+
out = append(out, tnIntlCapitalize(strings.ToLower(script)))
|
|
4200
|
+
} else if len(parts) > 1 && len(parts[1]) == 4 {
|
|
4201
|
+
out = append(out, parts[1])
|
|
4202
|
+
}
|
|
4203
|
+
if region != "" {
|
|
4204
|
+
out = append(out, strings.ToUpper(region))
|
|
4205
|
+
} else if r := tnIntlRegionOf(id); r != "" {
|
|
4206
|
+
out = append(out, r)
|
|
4207
|
+
}
|
|
4208
|
+
t, err := xlanguage.Parse(strings.Join(out, "-") + tnIntlExtensionOf(id))
|
|
4209
|
+
if err != nil {
|
|
4210
|
+
return tag
|
|
4211
|
+
}
|
|
4212
|
+
return t
|
|
4213
|
+
}
|
|
4214
|
+
|
|
4215
|
+
func (l *TnIntlLocale) Get_baseName() string { return tnIntlBaseOf(l.id) }
|
|
4216
|
+
func (l *TnIntlLocale) Get_language() string { return tnIntlLanguageOf(l.id) }
|
|
4217
|
+
|
|
4218
|
+
// The optional parts: undefined when the tag has none
|
|
4219
|
+
func tnIntlOptionalString(v string) interface{} {
|
|
4220
|
+
if v == "" {
|
|
4221
|
+
return nil
|
|
4222
|
+
}
|
|
4223
|
+
return v
|
|
4224
|
+
}
|
|
4225
|
+
|
|
4226
|
+
func (l *TnIntlLocale) Get_script() interface{} { return tnIntlOptionalString(tnIntlScriptOf(l.id)) }
|
|
4227
|
+
func (l *TnIntlLocale) Get_region() interface{} { return tnIntlOptionalString(tnIntlRegionOf(l.id)) }
|
|
4228
|
+
func (l *TnIntlLocale) Get_numberingSystem() interface{} {
|
|
4229
|
+
return tnIntlOptionalString(l.tag.TypeForKey("nu"))
|
|
4230
|
+
}
|
|
4231
|
+
func (l *TnIntlLocale) Get_calendar() interface{} {
|
|
4232
|
+
return tnIntlOptionalString(l.tag.TypeForKey("ca"))
|
|
4233
|
+
}
|
|
4234
|
+
func (l *TnIntlLocale) Get_collation() interface{} {
|
|
4235
|
+
return tnIntlOptionalString(l.tag.TypeForKey("co"))
|
|
4236
|
+
}
|
|
4237
|
+
func (l *TnIntlLocale) Get_caseFirst() interface{} {
|
|
4238
|
+
return tnIntlOptionalString(l.tag.TypeForKey("kf"))
|
|
4239
|
+
}
|
|
4240
|
+
|
|
4241
|
+
// numeric: -u-kn (or -u-kn-true) is true
|
|
4242
|
+
func (l *TnIntlLocale) Get_numeric() bool {
|
|
4243
|
+
return strings.Contains(l.id+"-", "-kn-") && l.tag.TypeForKey("kn") != "false"
|
|
4244
|
+
}
|
|
4245
|
+
func (l *TnIntlLocale) Get_hourCycle() interface{} {
|
|
4246
|
+
return tnIntlOptionalString(l.tag.TypeForKey("hc"))
|
|
4247
|
+
}
|
|
4248
|
+
|
|
4249
|
+
// maximize: the likely subtags fill the script and region in
|
|
4250
|
+
func (l *TnIntlLocale) maximize() *TnIntlLocale {
|
|
4251
|
+
id := l.id
|
|
4252
|
+
base := tnIntlBaseOf(id)
|
|
4253
|
+
parts := strings.Split(base, "-")
|
|
4254
|
+
lang := parts[0]
|
|
4255
|
+
full, ok := tnIntlLikely[lang]
|
|
4256
|
+
if !ok {
|
|
4257
|
+
return &TnIntlLocale{id: id, tag: l.tag}
|
|
4258
|
+
}
|
|
4259
|
+
fp := strings.Split(full, "-") // language, script, region
|
|
4260
|
+
haveScript := len(parts) > 1 && len(parts[1]) == 4
|
|
4261
|
+
region := tnIntlRegionOf(id)
|
|
4262
|
+
script := ""
|
|
4263
|
+
if haveScript {
|
|
4264
|
+
script = parts[1]
|
|
4265
|
+
} else {
|
|
4266
|
+
script = fp[1]
|
|
4267
|
+
if rules, ok := tnIntlScriptByRegion[lang]; ok && region != "" {
|
|
4268
|
+
for _, pair := range strings.Split(rules, ";") {
|
|
4269
|
+
kv := strings.SplitN(pair, "=", 2)
|
|
4270
|
+
if len(kv) == 2 && tnIntlHasString(strings.Split(kv[0], ","), region) {
|
|
4271
|
+
script = kv[1]
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
}
|
|
4275
|
+
}
|
|
4276
|
+
out := []string{lang, script}
|
|
4277
|
+
if region != "" {
|
|
4278
|
+
out = append(out, region)
|
|
4279
|
+
} else {
|
|
4280
|
+
out = append(out, fp[len(fp)-1])
|
|
4281
|
+
}
|
|
4282
|
+
t, err := xlanguage.Parse(strings.Join(out, "-") + tnIntlExtensionOf(id))
|
|
4283
|
+
if err != nil {
|
|
4284
|
+
return &TnIntlLocale{id: id, tag: l.tag}
|
|
4285
|
+
}
|
|
4286
|
+
return &TnIntlLocale{id: t.String(), tag: t}
|
|
4287
|
+
}
|
|
4288
|
+
|
|
4289
|
+
// minimize: the shortest tag with the same maximization
|
|
4290
|
+
func (l *TnIntlLocale) minimize() *TnIntlLocale {
|
|
4291
|
+
if v, ok := tnIntlMinimal[l.id]; ok {
|
|
4292
|
+
t, err := xlanguage.Parse(v)
|
|
4293
|
+
if err == nil {
|
|
4294
|
+
return &TnIntlLocale{id: t.String(), tag: t}
|
|
4295
|
+
}
|
|
4296
|
+
}
|
|
4297
|
+
max := l.maximize()
|
|
4298
|
+
base := tnIntlBaseOf(max.id)
|
|
4299
|
+
parts := strings.Split(base, "-")
|
|
4300
|
+
cands := []string{parts[0]}
|
|
4301
|
+
if len(parts) > 2 {
|
|
4302
|
+
cands = append(cands, parts[0]+"-"+parts[2])
|
|
4303
|
+
}
|
|
4304
|
+
cands = append(cands, base)
|
|
4305
|
+
for _, c := range cands {
|
|
4306
|
+
t, err := xlanguage.Parse(c + tnIntlExtensionOf(l.id))
|
|
4307
|
+
if err != nil {
|
|
4308
|
+
continue
|
|
4309
|
+
}
|
|
4310
|
+
m := &TnIntlLocale{id: t.String(), tag: t}
|
|
4311
|
+
if m.maximize().id == max.id {
|
|
4312
|
+
return m
|
|
4313
|
+
}
|
|
4314
|
+
}
|
|
4315
|
+
return &TnIntlLocale{id: max.id, tag: max.tag}
|
|
4316
|
+
}
|
|
4317
|
+
|
|
4318
|
+
func (l *TnIntlLocale) toString() string { return l.id }`;
|
|
4319
|
+
const intlCaseGo = `// s.toLocaleUpperCase(locales) / s.toLocaleLowerCase(locales): the locale's
|
|
4320
|
+
// case mapping (golang.org/x/text/cases — Turkish's İ/i, Lithuanian's dots)
|
|
4321
|
+
|
|
4322
|
+
// The locale whose case rules apply: the first requested one (case mapping
|
|
4323
|
+
// needs no formatting data: lt and az have rules but no generated tables)
|
|
4324
|
+
func TnIntlCaseLoc(locales interface{}) *TnIntlLoc {
|
|
4325
|
+
ids := TnIntlCanonicalList(locales)
|
|
4326
|
+
if len(ids) == 0 {
|
|
4327
|
+
ids = []string{tnIntlDefaultID()}
|
|
4328
|
+
}
|
|
4329
|
+
return &TnIntlLoc{id: ids[0], tag: tnIntlTagOf(ids[0]), data: ids[0]}
|
|
4330
|
+
}
|
|
4331
|
+
|
|
4332
|
+
func TnIntlToUpper(loc *TnIntlLoc, s string) string {
|
|
4333
|
+
// Lithuanian: a combining dot above after a soft-dotted letter (i, j, į)
|
|
4334
|
+
// goes away; the rest uppercases as the root locale (x/text's lt mapper
|
|
4335
|
+
// stops after the removal)
|
|
4336
|
+
if base, _ := loc.tag.Base(); base.String() == "lt" {
|
|
4337
|
+
var b strings.Builder
|
|
4338
|
+
prev := rune(0)
|
|
4339
|
+
for _, r := range s {
|
|
4340
|
+
if r == 0x307 && (prev == 'i' || prev == 'j' || prev == 0x12F) {
|
|
4341
|
+
continue
|
|
4342
|
+
}
|
|
4343
|
+
b.WriteRune(r)
|
|
4344
|
+
prev = r
|
|
4345
|
+
}
|
|
4346
|
+
return strings.ToUpper(b.String())
|
|
4347
|
+
}
|
|
4348
|
+
return xcases.Upper(loc.tag).String(s)
|
|
4349
|
+
}
|
|
4350
|
+
func TnIntlToLower(loc *TnIntlLoc, s string) string { return xcases.Lower(loc.tag).String(s) }`;
|
|
4351
|
+
const intlElemGo = `// Array#toLocaleString's element conversion: each element's toLocaleString
|
|
4352
|
+
// (numbers and bigints through the number formats, dates through the date
|
|
4353
|
+
// patterns, strings as themselves, anything else as its string form)
|
|
4354
|
+
|
|
4355
|
+
func TnIntlElemLocaleString(elem interface{}, locales interface{}, options interface{}) string {
|
|
4356
|
+
switch v := elem.(type) {
|
|
4357
|
+
case nil:
|
|
4358
|
+
return ""
|
|
4359
|
+
case string:
|
|
4360
|
+
return v
|
|
4361
|
+
case float64:
|
|
4362
|
+
return TnIntlNumLocale(v, locales, options)
|
|
4363
|
+
case *tnbig.Int:
|
|
4364
|
+
return TnIntlNumLocale(v, locales, options)
|
|
4365
|
+
case time.Time:
|
|
4366
|
+
return TnIntlDateFmt(v, locales, options, "locale")
|
|
4367
|
+
case *time.Time:
|
|
4368
|
+
if v != nil {
|
|
4369
|
+
return TnIntlDateFmt(*v, locales, options, "locale")
|
|
4370
|
+
}
|
|
4371
|
+
return ""
|
|
4372
|
+
}
|
|
4373
|
+
return TnJSString(elem)
|
|
4374
|
+
}`;
|
|
4375
|
+
export function registerIntl(r) {
|
|
4376
|
+
// the system zone detection (IANA ids, Windows' zone names mapped) shared
|
|
4377
|
+
// with Temporal: registering it twice redefines the same helpers
|
|
4378
|
+
registerTemporalZones(r);
|
|
4379
|
+
// DateTimeFormat's named time zones (time/tzdata embedded, so they work
|
|
4380
|
+
// without the OS's zoneinfo; the system zone id comes from the Temporal
|
|
4381
|
+
// local-zone helper, which shares the machinery)
|
|
4382
|
+
r.helperSideEffects['intlDate'] = ['time/tzdata'];
|
|
4383
|
+
defineHelper(r, 'intlCoreData', [], [], intlCoreData);
|
|
4384
|
+
defineHelper(r, 'intlNumberData', [], ['intlCoreData'], intlNumberData);
|
|
4385
|
+
defineHelper(r, 'intlDateData', [], ['intlCoreData'], intlDateData);
|
|
4386
|
+
defineHelper(r, 'intlListRelData', [], ['intlCoreData'], intlListRelData);
|
|
4387
|
+
defineHelper(r, 'intlDisplayData', [], ['intlCoreData'], intlDisplayData);
|
|
4388
|
+
defineHelper(r, 'intlLocaleOS@windows', ['os', 'strings', 'syscall', 'unsafe'], [], intlLocaleOSWindows);
|
|
4389
|
+
defineHelper(r, 'intlLocaleOS@other', ['os', 'strings'], [], intlLocaleOSOther);
|
|
4390
|
+
defineHelper(r, 'intlCore', ['math', 'regexp', 'strconv', 'strings', 'sync', 'golang.org/x/text/language', 'golang.org/x/text/feature/plural'], ['intlCoreData', 'intlLocaleOS@os', 'error', 'dynamic', 'arraySubclass', 'bigint'], intlCoreGo);
|
|
4391
|
+
defineHelper(r, 'intlNumberSyms', [], ['intlCore', 'intlNumberData'], intlNumberSymsGo);
|
|
4392
|
+
defineHelper(r, 'intlNumber', ['math', 'strconv', 'strings'], ['intlCore', 'intlNumberSyms'], intlNumberGo);
|
|
4393
|
+
defineHelper(r, 'intlDate', ['fmt', 'math', 'os', 'strconv', 'strings', 'sync', 'time'], ['intlCore', 'intlDateData', 'intlNumberSyms', 'nodeTemporalLocalZone@os'], intlDateGo);
|
|
4394
|
+
defineHelper(r, 'intlCollate', ['strings', 'sync', 'unicode', 'golang.org/x/text/collate', 'golang.org/x/text/unicode/norm'], ['intlCore'], intlCollateGo);
|
|
4395
|
+
defineHelper(r, 'intlPlural', ['math', 'strconv', 'strings', 'golang.org/x/text/feature/plural'], ['intlCore'], intlPluralGo);
|
|
4396
|
+
defineHelper(r, 'intlListRel', ['math', 'strconv', 'strings'], ['intlCore', 'intlListRelData', 'intlPlural', 'intlNumber'], intlListRelGo);
|
|
4397
|
+
defineHelper(r, 'intlSegmenter', ['math', 'unicode', 'unicode/utf8'], ['intlCore'], intlSegGo);
|
|
4398
|
+
defineHelper(r, 'intlDisplay', ['strings', 'golang.org/x/text/language/display', 'golang.org/x/text/language'], ['intlCore', 'intlDisplayData'], intlDisplayGo);
|
|
4399
|
+
defineHelper(r, 'intlLocale', ['strings', 'golang.org/x/text/language'], ['intlCore'], intlLocaleGo);
|
|
4400
|
+
defineHelper(r, 'intlCase', ['strings', 'golang.org/x/text/cases'], ['intlCore'], intlCaseGo);
|
|
4401
|
+
defineHelper(r, 'intlElemString', ['time'], ['intlCore', 'intlNumber', 'intlDate'], intlElemGo);
|
|
4402
|
+
const use = (id) => r.helper(id);
|
|
4403
|
+
r.globals['Intl'] = 'Intl';
|
|
4404
|
+
r.objects['Intl'] = true;
|
|
4405
|
+
// --- Intl.NumberFormat
|
|
4406
|
+
defineClass(r, 'Intl.NumberFormat', '*TnIntlNumberFormat', 'class', 'resolvedOptions=interface{}', '', 'format=func(interface{}) string', '');
|
|
4407
|
+
r.constructors['Intl.NumberFormat'] = (c) => {
|
|
4408
|
+
use('intlNumber');
|
|
4409
|
+
return `TnNewIntlNumberFormat(${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4410
|
+
};
|
|
4411
|
+
r.methods['Intl.NumberFormat#format'] = (c) => {
|
|
4412
|
+
use('intlNumber');
|
|
4413
|
+
return `TnIntlNumberFormatAnyStr(${c.recv}, ${c.args[0] ?? 'nil'})`;
|
|
4414
|
+
};
|
|
4415
|
+
r.methods['Intl.NumberFormat#formatToParts'] = (c) => {
|
|
4416
|
+
use('intlNumber');
|
|
4417
|
+
return `TnIntlNumberFormatAny(${c.recv}, ${c.args[0] ?? 'nil'})`;
|
|
4418
|
+
};
|
|
4419
|
+
r.methods['Intl.NumberFormat#formatRange'] = (c) => {
|
|
4420
|
+
use('intlNumber');
|
|
4421
|
+
return `TnIntlNumberFormatRange(${c.recv}, ${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4422
|
+
};
|
|
4423
|
+
r.methods['Intl.NumberFormat#formatRangeToParts'] = (c) => {
|
|
4424
|
+
use('intlNumber');
|
|
4425
|
+
return `TnIntlNumberFormatRangeParts(${c.recv}, ${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4426
|
+
};
|
|
4427
|
+
r.functions['Intl.NumberFormat.supportedLocalesOf'] = (c) => {
|
|
4428
|
+
use('intlCore');
|
|
4429
|
+
return `TnIntlSupportedLocalesOf(${c.args[0] ?? 'nil'})`;
|
|
4430
|
+
};
|
|
4431
|
+
setIntlResults(r, 'Intl.NumberFormat', 'formatToParts=[]interface{}; formatRangeToParts=[]interface{}; format=string; formatRange=string; supportedLocalesOf=[]string');
|
|
4432
|
+
// --- Intl.DateTimeFormat
|
|
4433
|
+
defineClass(r, 'Intl.DateTimeFormat', '*TnIntlDateTimeFormat', 'class', 'resolvedOptions=interface{}', '', 'format=func(interface{}) string', '');
|
|
4434
|
+
r.constructors['Intl.DateTimeFormat'] = (c) => {
|
|
4435
|
+
use('intlDate');
|
|
4436
|
+
return `TnNewIntlDateTimeFormat(${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4437
|
+
};
|
|
4438
|
+
r.methods['Intl.DateTimeFormat#format'] = (c) => {
|
|
4439
|
+
use('intlDate');
|
|
4440
|
+
return `TnIntlDateFormat(${c.recv}, TnNewDate(${c.args[0] ?? 'nil'}))`;
|
|
4441
|
+
};
|
|
4442
|
+
r.methods['Intl.DateTimeFormat#formatToParts'] = (c) => {
|
|
4443
|
+
use('intlDate');
|
|
4444
|
+
return `TnIntlDateFormatParts(${c.recv}, TnNewDate(${c.args[0] ?? 'nil'}))`;
|
|
4445
|
+
};
|
|
4446
|
+
r.methods['Intl.DateTimeFormat#formatRange'] = (c) => {
|
|
4447
|
+
use('intlDate');
|
|
4448
|
+
return `TnIntlDateFormatRange(${c.recv}, TnNewDate(${c.args[0] ?? 'nil'}), TnNewDate(${c.args[1] ?? 'nil'}))`;
|
|
4449
|
+
};
|
|
4450
|
+
r.methods['Intl.DateTimeFormat#formatRangeToParts'] = (c) => {
|
|
4451
|
+
use('intlDate');
|
|
4452
|
+
return `TnIntlDateFormatRangeParts(${c.recv}, TnNewDate(${c.args[0] ?? 'nil'}), TnNewDate(${c.args[1] ?? 'nil'}))`;
|
|
4453
|
+
};
|
|
4454
|
+
r.functions['Intl.DateTimeFormat.supportedLocalesOf'] = (c) => {
|
|
4455
|
+
use('intlCore');
|
|
4456
|
+
return `TnIntlSupportedLocalesOf(${c.args[0] ?? 'nil'})`;
|
|
4457
|
+
};
|
|
4458
|
+
setIntlResults(r, 'Intl.DateTimeFormat', 'formatToParts=[]interface{}; formatRangeToParts=[]interface{}; format=string; formatRange=string; supportedLocalesOf=[]string');
|
|
4459
|
+
// --- Intl.Collator
|
|
4460
|
+
defineClass(r, 'Intl.Collator', '*TnIntlCollator', 'class', 'resolvedOptions=interface{}', '', 'compare=func(string, string) float64', '');
|
|
4461
|
+
r.constructors['Intl.Collator'] = (c) => {
|
|
4462
|
+
use('intlCollate');
|
|
4463
|
+
return `TnNewIntlCollator(${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4464
|
+
};
|
|
4465
|
+
r.methods['Intl.Collator#compare'] = (c) => {
|
|
4466
|
+
use('intlCollate');
|
|
4467
|
+
return `TnIntlCollatorCompare(${c.recv}, ${c.args[0]}, ${c.args[1]})`;
|
|
4468
|
+
};
|
|
4469
|
+
r.functions['Intl.Collator.supportedLocalesOf'] = (c) => {
|
|
4470
|
+
use('intlCore');
|
|
4471
|
+
return `TnIntlSupportedLocalesOf(${c.args[0] ?? 'nil'})`;
|
|
4472
|
+
};
|
|
4473
|
+
setIntlResults(r, 'Intl.Collator', 'compare=float64; supportedLocalesOf=[]string');
|
|
4474
|
+
// --- Intl.PluralRules
|
|
4475
|
+
defineClass(r, 'Intl.PluralRules', '*TnIntlPluralRules', 'class', 'resolvedOptions=interface{}', '', '', '');
|
|
4476
|
+
r.constructors['Intl.PluralRules'] = (c) => {
|
|
4477
|
+
use('intlPlural');
|
|
4478
|
+
return `TnNewIntlPluralRules(${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4479
|
+
};
|
|
4480
|
+
r.methods['Intl.PluralRules#select'] = (c) => {
|
|
4481
|
+
use('intlPlural');
|
|
4482
|
+
return `TnIntlPluralSelect(${c.recv}, ${c.args[0] ?? 'nil'})`;
|
|
4483
|
+
};
|
|
4484
|
+
r.methods['Intl.PluralRules#selectRange'] = (c) => {
|
|
4485
|
+
use('intlPlural');
|
|
4486
|
+
return `TnIntlPluralSelectRange(${c.recv}, ${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4487
|
+
};
|
|
4488
|
+
r.functions['Intl.PluralRules.supportedLocalesOf'] = (c) => {
|
|
4489
|
+
use('intlCore');
|
|
4490
|
+
return `TnIntlSupportedLocalesOf(${c.args[0] ?? 'nil'})`;
|
|
4491
|
+
};
|
|
4492
|
+
setIntlResults(r, 'Intl.PluralRules', 'select=string; selectRange=string; supportedLocalesOf=[]string');
|
|
4493
|
+
// --- Intl.ListFormat
|
|
4494
|
+
defineClass(r, 'Intl.ListFormat', '*TnIntlListFormat', 'class', 'resolvedOptions=interface{}', '', '', '');
|
|
4495
|
+
r.constructors['Intl.ListFormat'] = (c) => {
|
|
4496
|
+
use('intlListRel');
|
|
4497
|
+
return `TnNewIntlListFormat(${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4498
|
+
};
|
|
4499
|
+
r.methods['Intl.ListFormat#format'] = (c) => {
|
|
4500
|
+
use('intlListRel');
|
|
4501
|
+
return `TnIntlListFormatFormat(${c.recv}, ${c.args[0] ?? 'nil'})`;
|
|
4502
|
+
};
|
|
4503
|
+
r.methods['Intl.ListFormat#formatToParts'] = (c) => {
|
|
4504
|
+
use('intlListRel');
|
|
4505
|
+
return `TnIntlListFormatParts(${c.recv}, ${c.args[0] ?? 'nil'})`;
|
|
4506
|
+
};
|
|
4507
|
+
r.functions['Intl.ListFormat.supportedLocalesOf'] = (c) => {
|
|
4508
|
+
use('intlCore');
|
|
4509
|
+
return `TnIntlSupportedLocalesOf(${c.args[0] ?? 'nil'})`;
|
|
4510
|
+
};
|
|
4511
|
+
setIntlResults(r, 'Intl.ListFormat', 'format=string; formatToParts=[]interface{}; supportedLocalesOf=[]string');
|
|
4512
|
+
// --- Intl.RelativeTimeFormat
|
|
4513
|
+
defineClass(r, 'Intl.RelativeTimeFormat', '*TnIntlRelativeTimeFormat', 'class', 'resolvedOptions=interface{}', '', '', '');
|
|
4514
|
+
r.constructors['Intl.RelativeTimeFormat'] = (c) => {
|
|
4515
|
+
use('intlListRel');
|
|
4516
|
+
return `TnNewIntlRelativeTimeFormat(${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4517
|
+
};
|
|
4518
|
+
r.methods['Intl.RelativeTimeFormat#format'] = (c) => {
|
|
4519
|
+
use('intlListRel');
|
|
4520
|
+
return `TnIntlRelativeFormat(${c.recv}, ${c.args[0] ?? 'nil'}, ${c.args[1] ?? '""'})`;
|
|
4521
|
+
};
|
|
4522
|
+
r.methods['Intl.RelativeTimeFormat#formatToParts'] = (c) => {
|
|
4523
|
+
use('intlListRel');
|
|
4524
|
+
return `TnIntlRelativeParts(${c.recv}, ${c.args[0] ?? 'nil'}, ${c.args[1] ?? '""'})`;
|
|
4525
|
+
};
|
|
4526
|
+
r.functions['Intl.RelativeTimeFormat.supportedLocalesOf'] = (c) => {
|
|
4527
|
+
use('intlCore');
|
|
4528
|
+
return `TnIntlSupportedLocalesOf(${c.args[0] ?? 'nil'})`;
|
|
4529
|
+
};
|
|
4530
|
+
setIntlResults(r, 'Intl.RelativeTimeFormat', 'format=string; formatToParts=[]interface{}; supportedLocalesOf=[]string');
|
|
4531
|
+
// --- Intl.Segmenter (segment() iterates; containing(i) reads one)
|
|
4532
|
+
defineClass(r, 'Intl.Segmenter', '*TnIntlSegmenter', 'class', 'resolvedOptions=interface{}', '', '', '');
|
|
4533
|
+
defineClass(r, 'Intl.Segments', '*TnIntlSegmentIter', 'class', 'tnItems=[]interface{}; containing=interface{}', '', '', '');
|
|
4534
|
+
r.constructors['Intl.Segmenter'] = (c) => {
|
|
4535
|
+
use('intlSegmenter');
|
|
4536
|
+
return `TnNewIntlSegmenter(${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4537
|
+
};
|
|
4538
|
+
r.methods['Intl.Segmenter#segment'] = (c) => {
|
|
4539
|
+
use('intlSegmenter');
|
|
4540
|
+
return `${c.recv}.segment(${c.args[0] ?? '""'})`;
|
|
4541
|
+
};
|
|
4542
|
+
r.functions['Intl.Segmenter.supportedLocalesOf'] = (c) => {
|
|
4543
|
+
use('intlCore');
|
|
4544
|
+
return `TnIntlSupportedLocalesOf(${c.args[0] ?? 'nil'})`;
|
|
4545
|
+
};
|
|
4546
|
+
r.iterators['*TnIntlSegmentIter'] = 'tnItems';
|
|
4547
|
+
setIntlResults(r, 'Intl.Segmenter', 'segment=*TnIntlSegmentIter; supportedLocalesOf=[]string');
|
|
4548
|
+
setIntlResults(r, 'Intl.Segments', 'tnItems=[]interface{}; containing=interface{}');
|
|
4549
|
+
// --- Intl.DisplayNames
|
|
4550
|
+
defineClass(r, 'Intl.DisplayNames', '*TnIntlDisplayNames', 'class', 'resolvedOptions=interface{}', '', '', '');
|
|
4551
|
+
r.constructors['Intl.DisplayNames'] = (c) => {
|
|
4552
|
+
use('intlDisplay');
|
|
4553
|
+
return `TnNewIntlDisplayNames(${c.args[0] ?? 'nil'}, ${c.args[1] ?? 'nil'})`;
|
|
4554
|
+
};
|
|
4555
|
+
r.methods['Intl.DisplayNames#of'] = (c) => {
|
|
4556
|
+
use('intlDisplay');
|
|
4557
|
+
return `${c.recv}.of(${c.args[0] ?? '""'})`;
|
|
4558
|
+
};
|
|
4559
|
+
setIntlResults(r, 'Intl.DisplayNames', 'of=interface{}');
|
|
4560
|
+
// --- Intl.Locale
|
|
4561
|
+
defineClass(r, 'Intl.Locale', '*TnIntlLocale', 'class', 'maximize=*TnIntlLocale; minimize=*TnIntlLocale; toString=string', '', 'baseName=string; language=string; script=interface{}; region=interface{}; numberingSystem=interface{}; calendar=interface{}; collation=interface{}; caseFirst=interface{}; numeric=bool; hourCycle=interface{}', '');
|
|
4562
|
+
r.constructors['Intl.Locale'] = (c) => {
|
|
4563
|
+
use('intlLocale');
|
|
4564
|
+
return `TnNewIntlLocale(${c.args[0] ?? '""'}, ${c.args[1] ?? 'nil'})`;
|
|
4565
|
+
};
|
|
4566
|
+
// --- Intl statics
|
|
4567
|
+
r.functions['Intl.getCanonicalLocales'] = (c) => {
|
|
4568
|
+
use('intlCore');
|
|
4569
|
+
return `TnIntlGetCanonicalLocales(${c.args[0] ?? 'nil'})`;
|
|
4570
|
+
};
|
|
4571
|
+
r.functions['Intl.supportedValuesOf'] = (c) => {
|
|
4572
|
+
use('intlCore');
|
|
4573
|
+
return `TnIntlSupportedValuesOf(${c.args[0] ?? '""'})`;
|
|
4574
|
+
};
|
|
4575
|
+
setResults(r, 'Intl', 'getCanonicalLocales=[]string; supportedValuesOf=[]string');
|
|
4576
|
+
}
|