aboutsummaryrefslogtreecommitdiff
path: root/src/strconv
AgeCommit message (Collapse)Author
2025-04-07strconv: use switch for '+'/'-' prefix handlingzhi.wang
Follow the approach used in strconv's readFloat, decimal.set, and Atoi, where leading '+' and '-' are handled using a switch for clarity and consistency. Change-Id: I41eff34ce90b5ac43fcdbc0bb88910d6d5fb4d39 GitHub-Last-Rev: 0c9d2efb5a828515fa00afdba8c436aa31fb0e53 GitHub-Pull-Request: golang/go#73185 Reviewed-on: https://go-review.googlesource.com/c/go/+/663257 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-24strconv: use builtin min function in commonPrefixLenIgnoreCaseJes Cok
To make code a bit simpler. Change-Id: I33b3e04bc810a4838584c477854ef612b355579a GitHub-Last-Rev: 6d5bbc2a2877193e1319b9e626f408eda399666e GitHub-Pull-Request: golang/go#71927 Reviewed-on: https://go-review.googlesource.com/c/go/+/651975 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
2025-01-27strconv: adjust comment so that gofmt doesn't mung itIan Lance Taylor
Change-Id: I7fe5c6a0521d3c597eae0f3568942df1db9370b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/642497 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-12-17fmt, strconv: document that exponent is always two digitsIan Lance Taylor
Except for %b where it is only one. Fixes #70862 Change-Id: Ic423a799b73bfa534f4083f6544bb9cd639fef06 Reviewed-on: https://go-review.googlesource.com/c/go/+/636915 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-11-14strconv: cleanup old compiler bits.TrailingZeros workaroundJorropo
Since CL 599096 the compiler knows bits.TrailingZeros's maximum value based on the input type size. Since CL 603996 it knows it based on input's maximum value. Change-Id: Ib0d6b15a3ba6894d3e7e12b79b387ddbffabe370 Reviewed-on: https://go-review.googlesource.com/c/go/+/618715 Auto-Submit: Robert Griesemer <gri@google.com> Commit-Queue: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org>
2024-10-16strconv: display format options as listSean Liao
Fixes #69890 Change-Id: I1da4eb76c008679a687f4faa4294fe32b5fc7f42 Reviewed-on: https://go-review.googlesource.com/c/go/+/620236 Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-07-22strconv: document that Unquote("''") returns an empty stringYossef Hisham
Fixes #64280 Change-Id: I1ad84d85b666a2ef52dc6ecdecd508b4e7fe24a6 GitHub-Last-Rev: 6242027261f02c578a09f70fcb39a8cac259855c GitHub-Pull-Request: golang/go#68524 Reviewed-on: https://go-review.googlesource.com/c/go/+/599575 Auto-Submit: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com>
2024-05-05strconv: use stringslite.Cloneqiulaidongfeng
Change-Id: Ifa3c022ad5453301573593a3d05e7b1d42b931ff GitHub-Last-Rev: a7468b068b5c7bcaa573042cf9d5c2732c0385f1 GitHub-Pull-Request: golang/go#67167 Reviewed-on: https://go-review.googlesource.com/c/go/+/583215 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Auto-Submit: Keith Randall <khr@golang.org>
2024-04-04strconv: add available godoc linkcui fliter
Change-Id: Iad58155f29a101fb72768b170c0c2c9d76b6041a Reviewed-on: https://go-review.googlesource.com/c/go/+/539357 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: qiu laidongfeng2 <2645477756@qq.com> Run-TryBot: shuang cui <imcusg@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2024-03-12strconv: use generics to reduce redundant helper functionsapocelipes
Benchstat shows there are no noticeable performance changes here. Change-Id: If2250334fe6664986f044cbaabfa1bfc84f871f7 GitHub-Last-Rev: d41a498d54483759b9c85c3d8efa848c0cc1bbd9 GitHub-Pull-Request: golang/go#66266 Reviewed-on: https://go-review.googlesource.com/c/go/+/570935 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2024-03-11strconv: use slices.BinarySearch to simplify makeisprint.goapocelipes
Change-Id: I9886a99f730b7616f6f8a5e6154e1beb7d3c79e6 GitHub-Last-Rev: 3f9dc7707377f79968e2dfcd206b83db21e60e60 GitHub-Pull-Request: golang/go#66242 Reviewed-on: https://go-review.googlesource.com/c/go/+/570535 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2023-10-19all: drop old +build linesDmitri Shuralyov
Running 'go fix' on the cmd+std packages handled much of this change. Also update code generators to use only the new go:build lines, not the old +build ones. For #41184. For #60268. Change-Id: If35532abe3012e7357b02c79d5992ff5ac37ca23 Cq-Include-Trybots: luci.golang.try:gotip-linux-386-longtest,gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/536237 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-10-13strconv: add example for QuotedPrefixJoe Tsai
Example can sometimes be more informative than additional prose. Fixes #46829 Change-Id: Ia5a5b121ad0b891026e77420d5f7f1b2c4a407da Reviewed-on: https://go-review.googlesource.com/c/go/+/336749 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-08-24strconv: add missing function name, avoid unnecessary raw stringLuka Krmpotić
Change-Id: Iecd68f69f5265f1a4ea41b90aa819ce68fe55908 GitHub-Last-Rev: 4d1f4a1bc2740fc19bbb4768009ccfea1c8eb5bc GitHub-Pull-Request: golang/go#62177 Reviewed-on: https://go-review.googlesource.com/c/go/+/521277 Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-08-17strconv: rely on utf8.AppendRuneJoe Tsai
This is both simpler and more performant. Quote 268ns ± 5% 258ns ± 4% -3.70% (p=0.014 n=10+10) QuoteRune 28.9ns ± 3% 28.4ns ± 4% ~ (p=0.113 n=9+10) AppendQuote 165ns ± 3% 165ns ± 3% ~ (p=0.661 n=9+10) AppendQuoteRune 8.05ns ± 5% 7.75ns ± 7% ~ (p=0.065 n=10+9) Change-Id: Ib0ee332e970d4986026c05e5e0e368f41eff7977 Reviewed-on: https://go-review.googlesource.com/c/go/+/412338 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Robert Griesemer <gri@google.com>
2023-08-11strconv: use the built-in min/max functionqiulaidongfeng
Change-Id: Iab170943e6e80ffe08bb061e563c106b53740372 Change-Id: Iab170943e6e80ffe08bb061e563c106b53740372 GitHub-Last-Rev: 2964e03f1fbc499247bb6c3365475a91ef64547a GitHub-Pull-Request: golang/go#61828 Reviewed-on: https://go-review.googlesource.com/c/go/+/516875 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2023-03-25all: add a few links in package godocsDaniel Martí
I noticed the one in path/filepath while reading the docs, and the other ones were found via some quick grepping. Change-Id: I386f2f74ef816a6d18aa2f58ee6b64dbd0147c9e Reviewed-on: https://go-review.googlesource.com/c/go/+/478795 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-02-21strconv: add Atoi test cases with characters less than '0'Anuraag Agrawal
Change-Id: I35c0fe4e7e11b694ef07687d5e0532a2ab9ba213 GitHub-Last-Rev: e0a28f42367c2685d80bcc5c45294c0d2eae77fe GitHub-Pull-Request: golang/go#58575 Reviewed-on: https://go-review.googlesource.com/c/go/+/469035 Auto-Submit: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
2023-02-06all: upgrade Unicode from 13.0.0 to 15.0.0weebney
Update unicode/tables.go to reflect changes in the Unicode Standard up to Unicode 15.0.0, released 13 Sept 2022. In order to accommodate this update, strconv/isPrint has been updated to reflect changes in printable characters. Also changed is template/exec_test.go for both text and html packages- in the test "TestJSEscaping", rune U+FDFF was used as a placeholder for an unprintable character. This codepoint was assigned and made printable in Unicode 14.0.0, breaking this test. It has been replaced with the assigned and never-printable U+FFFE to fix the test and provide resiliency in the future. This upgrade bypasses Unicode 14.0.0, but is compatible. Updates https://github.com/golang/go/issues/48621 Fixes https://github.com/golang/go/issues/55079 Change-Id: I40efd097eb746db0727ebf7437280916d1242e47 GitHub-Last-Rev: c8885cab7a0c23632e1e5a433b1e8d5634a45a30 GitHub-Pull-Request: golang/go#57265 Reviewed-on: https://go-review.googlesource.com/c/go/+/456837 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Rob Pike <r@golang.org>
2023-01-31strconv: show what fmt package uses for float printingKevin Burke
The strconv docs are not very helpful for people who just want to pick a reasonable default, for example the one used by the fmt package to show floats. Add an example illustrating what the fmt package uses. Change-Id: Iefefa70dfd4d4bfa9962a20654ee23662818ef38 Reviewed-on: https://go-review.googlesource.com/c/go/+/463980 Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-10-26all: remove uses of rand.SeedRuss Cox
As of CL 443058, rand.Seed is not necessary to call, nor is it a particular good idea. For #54880. Change-Id: If9d70763622c09008599db8c97a90fcbe285c6f8 Reviewed-on: https://go-review.googlesource.com/c/go/+/445395 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-30strconv: delete unused fieldcuiweixie
Change-Id: I1257270c55d69962988b6034e7341a9142a0c449 Reviewed-on: https://go-review.googlesource.com/c/go/+/436720 Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Run-TryBot: xie cui <523516579@qq.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-15strconv: add a test case when base is illegalcui fliter
Increase unit test coverage of strconv/itoa.go from 83.8% to 85% Change-Id: I0abdfc70a3f06251106f229c12ffb105eeb43fc8 GitHub-Last-Rev: da9755368b5db41123c8f945fecedd135e9f894a GitHub-Pull-Request: golang/go#55014 Reviewed-on: https://go-review.googlesource.com/c/go/+/430137 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Jenny Rakoczy <jenny@golang.org> Reviewed-by: Jenny Rakoczy <jenny@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Jenny Rakoczy <jenny@golang.org>
2022-09-09strconv: remove redundant type conversioncui fliter
Change-Id: I25c8e8b701d6489f360fea30d09090826276b950 GitHub-Last-Rev: c2c8319dd5fa2a53fe82b10ecbf45eb54b5d6a68 GitHub-Pull-Request: golang/go#54924 Reviewed-on: https://go-review.googlesource.com/c/go/+/428976 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2022-08-23strconv: optimize Parse for []byte argumentsJoe Tsai
When one has a []byte on hand, but desires to call the Parse functions, the conversion from []byte to string would allocate. var b []byte = ... v, err := strconv.ParseXXX(string(b), ...) This changes it such that the input string never escapes from any of the Parse functions. Together with the compiler optimization where the compiler stack allocates any string smaller than 32B this makes most valid inputs for strconv.ParseXXX(string(b), ...) not require an allocation for the input string. For example, the longest int64 or uint64 encoded in decimal is 20B. Also, the longest decimal formatting of a float64 in appendix B of RFC 8785 is 25B. Previously, this was not possible since the input leaked to the error, which causes the prover to give up and instead heap copy the []byte. We fix this by copying the input string in the error case. The advantage of this change is that you can now call strconv.ParseXXX with a []byte without allocations (most times) in the non-error case. The detriment is that the error-case now has an extra allocation. We should optimize for the non-error path, rather than the error path. The effects of this change is transitively seen through packages that must use strconv.ParseXXX on a []byte such as "encoding/json": name old time/op new time/op delta UnmarshalFloat64 186ns 157ns -15.89% (p=0.000 n=10+10) name old alloc/op new alloc/op delta UnmarshalFloat64 148B 144B -2.70% (p=0.000 n=10+10) name old allocs/op new allocs/op delta UnmarshalFloat64 2.00 1.00 -50.00% (p=0.000 n=10+10) In order for "encoding/json" to benefit, there needs to be a small change made to how "encoding/json" calls strconv.ParseXXX. That will be a future change. Credit goes to Jeff Wendling for a similar patch. Fixes #42429 Change-Id: I512d6927f965f82e95bd7ec14a28a587f23b7203 Reviewed-on: https://go-review.googlesource.com/c/go/+/345488 Reviewed-by: Martin Möhrmann <martin@golang.org> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-06-24strconv: avoid panic on invalid call to FormatFloatRémy Oudompheng
Calling FormatFloat with an invalid value of fmt is expected to return a string containing '%' and the input fmt character. Since even before Go 1.0, the code has been panicking in the case where prec=0. Fixes #52187 Change-Id: I74fec601eedb7fe28efc5132c4253674661452aa Reviewed-on: https://go-review.googlesource.com/c/go/+/402817 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-06-06strconv: fix typo in atof.go90364136+butterfly1924@users.noreply.github.com
strings for 'NaN' -> string for 'NaN' Change-Id: Ia415644a1b651e6ef9996ad24dd9708a60e57dfc GitHub-Last-Rev: 877f1c3eb1dc885915ae75385c5d38ee6f5fd9b1 GitHub-Pull-Request: golang/go#53246 Reviewed-on: https://go-review.googlesource.com/c/go/+/410494 Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-06-04strconv: clarify ParseFloat accepts Go syntax for float literalsBen Hoyt
The documentation for strconv.ParseFloat mentions that it "accepts decimal and hexadecimal floating-point number syntax", but it doesn't specify what those formats entail. For example, "0x10" is not allowed; you need an explicit exponent, as in "0x10p0". This clarifies that ParseFloat accepts the Go syntax for floating-point literals, and links to that spec section. I've also linked to the relevant spec section for ParseInt's doc comment, which already said "as defined by the Go syntax for integer literals". Change-Id: Ib5d2b408bdd01ea0b9f69381a9dbe858f6d1d424 Reviewed-on: https://go-review.googlesource.com/c/go/+/410335 Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-01all: remove trailing blank doc comment linesRuss Cox
A future change to gofmt will rewrite // Doc comment. // func f() to // Doc comment. func f() Apply that change preemptively to all doc comments. For #51082. Change-Id: I4023e16cfb0729b64a8590f071cd92f17343081d Reviewed-on: https://go-review.googlesource.com/c/go/+/384259 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-31strconv: quote rune 007F as \x7f, not \u007fIan Lance Taylor
\u007f is not wrong but it's weird to use \u when we could use the shorter \x. Fixes #52062 Change-Id: Ica4bdc2463128051876f44e15297ed1e9edf1de8 Reviewed-on: https://go-review.googlesource.com/c/go/+/397255 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2022-03-16fmt, strconv: document use of Unicode replacement character in %qRuss Cox
Fixes #51526. Change-Id: I365a763454bd201f804df29f800416b1731b8ebc Reviewed-on: https://go-review.googlesource.com/c/go/+/390436 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-10-06all: use bytes.Cut, strings.CutRuss Cox
Many uses of Index/IndexByte/IndexRune/Split/SplitN can be written more clearly using the new Cut functions. Do that. Also rewrite to other functions if that's clearer. For #46336. Change-Id: I68d024716ace41a57a8bf74455c62279bde0f448 Reviewed-on: https://go-review.googlesource.com/c/go/+/351711 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-08-21strconv: reject surrogate halves in UnquoteJoe Tsai
Unquote implements unescaping a "single-quoted, doubled-quoted, or backquoted Go string literal". Therefore, it should reject anything that the Go specification explicitly forbids. The section on "Rune literals" explicitly rejects rune values "above 0x10FFFF and surrogate halves". We properly checked for the previous condition, but were failing to check for the latter. In general, "r > utf8.MaxRune" is probably the wrong check, while !utf8.ValidRune(r) is the more correct check. We make changes to both UnquoteChar and appendEscapedRune to use the correct check. The change to appendEscapedRune is technically a noop since callers of that function already guarantee that the provided rune is valid. Fixes #47853 Change-Id: Ib8977e56b91943ec8ada821b8d217b5e9a66f950 Reviewed-on: https://go-review.googlesource.com/c/go/+/343877 Trust: Joe Tsai <joetsai@digital-static.net> Run-TryBot: Joe Tsai <joetsai@digital-static.net> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2021-08-17all: fix typosYasuhiro Matsumoto
Change-Id: I83180c472db8795803c1b9be3a33f35959e4dcc2 Reviewed-on: https://go-review.googlesource.com/c/go/+/336889 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Austin Clements <austin@google.com>
2021-06-09strconv: document parsing of leading +/-Damien Neil
Explicitly document the handling of a sign prefix, and the interaction between the sign and base prefixes. Fixes #46641. Change-Id: I3cd6773e3f074fe671a944a05a79d2408137fcd4 Reviewed-on: https://go-review.googlesource.com/c/go/+/325875 Trust: Damien Neil <dneil@google.com> Run-TryBot: Damien Neil <dneil@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2021-06-07strconv: ParseFloat: always return ErrSyntax for bad syntaxIan Lance Taylor
Previously we would sometimes return ErrRange if the parseable part of the floating point number was out of range. Fixes #46628 Change-Id: I15bbbb1e2a56fa27c19fe25ab5554d988cbfd9d2 Reviewed-on: https://go-review.googlesource.com/c/go/+/325750 Trust: Ian Lance Taylor <iant@golang.org> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2021-05-04strconv: fix a typoEndlessCheng
Change-Id: I17911dc95fb2126b41dc95f8839c4b3fa8f35d12 GitHub-Last-Rev: 88e120329301bd73db39e1081737a83f49a5672b GitHub-Pull-Request: golang/go#45933 Reviewed-on: https://go-review.googlesource.com/c/go/+/316689 Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-05-04strconv: add QuotedPrefixJoe Tsai
QuotedPrefix is similar to Unquote, but returns the quoted string verbatim and ignores any data after the quoted string. Fixes #45033 Change-Id: I9f69fe9e3e45cbe9e63581cf1b457facb625045d Reviewed-on: https://go-review.googlesource.com/c/go/+/314775 Trust: Joe Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
2021-04-27strconv: remove unused extfloat (Grisu3) ftoa codeRémy Oudompheng
Change-Id: Ie8995362f9e8072b173d08820330d2d1e512aa71 Reviewed-on: https://go-review.googlesource.com/c/go/+/314029 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
2021-04-15strconv: Implement Ryū algorithm for ftoa shortest modeRémy Oudompheng
This patch implements the algorithm from Ulf Adams, "Ryū: Fast Float-to-String Conversion" (doi:10.1145/3192366.3192369) for formatting floating-point numbers with a fixed number of decimal digits. It is not a direct translation of the reference C implementation but still follows the original paper. In particular, it uses full 128-bit powers of 10, which allows for more precision in the other modes (fixed ftoa, atof). name old time/op new time/op delta AppendFloat/Decimal-4 49.6ns ± 3% 59.3ns ± 0% +19.59% (p=0.008 n=5+5) AppendFloat/Float-4 122ns ± 1% 91ns ± 1% -25.92% (p=0.008 n=5+5) AppendFloat/Exp-4 89.3ns ± 1% 100.0ns ± 1% +11.98% (p=0.008 n=5+5) AppendFloat/NegExp-4 88.3ns ± 2% 97.1ns ± 1% +9.87% (p=0.008 n=5+5) AppendFloat/LongExp-4 143ns ± 2% 103ns ± 0% -28.17% (p=0.016 n=5+4) AppendFloat/Big-4 144ns ± 1% 110ns ± 1% -23.26% (p=0.008 n=5+5) AppendFloat/BinaryExp-4 46.2ns ± 2% 46.0ns ± 1% ~ (p=0.603 n=5+5) AppendFloat/32Integer-4 49.1ns ± 1% 58.7ns ± 1% +19.57% (p=0.008 n=5+5) AppendFloat/32ExactFraction-4 95.6ns ± 1% 88.6ns ± 1% -7.30% (p=0.008 n=5+5) AppendFloat/32Point-4 122ns ± 1% 87ns ± 1% -28.63% (p=0.008 n=5+5) AppendFloat/32Exp-4 88.6ns ± 2% 95.0ns ± 1% +7.29% (p=0.008 n=5+5) AppendFloat/32NegExp-4 87.2ns ± 1% 91.3ns ± 1% +4.63% (p=0.008 n=5+5) AppendFloat/32Shortest-4 107ns ± 1% 82ns ± 0% -24.08% (p=0.008 n=5+5) AppendFloat/Slowpath64-4 1.00µs ± 1% 0.10µs ± 0% -89.92% (p=0.016 n=5+4) AppendFloat/SlowpathDenormal64-4 34.1µs ± 3% 0.1µs ± 1% -99.72% (p=0.008 n=5+5) Fixes #15672 Change-Id: Ib90dfa245f62490a6666671896013cf3f9a1fb22 Reviewed-on: https://go-review.googlesource.com/c/go/+/170080 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Nigel Tao <nigeltao@golang.org> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org>
2021-04-15strconv: implement Ryū-like algorithm for fixed precision ftoaRémy Oudompheng
This patch implements a simplified version of Ulf Adams, "Ryū: Fast Float-to-String Conversion" (doi:10.1145/3192366.3192369) for formatting floating-point numbers with a fixed number of decimal digits. It uses the same principles but does not need to handle the complex task of finding a shortest representation. This allows to handle a few more cases than Grisu3, notably formatting with up to 18 significant digits. name old time/op new time/op delta AppendFloat/32Fixed8Hard-4 72.0ns ± 2% 56.0ns ± 2% -22.28% (p=0.000 n=10+10) AppendFloat/32Fixed9Hard-4 74.8ns ± 0% 64.2ns ± 2% -14.16% (p=0.000 n=8+10) AppendFloat/64Fixed1-4 60.4ns ± 1% 54.2ns ± 1% -10.31% (p=0.000 n=10+9) AppendFloat/64Fixed2-4 66.3ns ± 1% 53.3ns ± 1% -19.54% (p=0.000 n=10+9) AppendFloat/64Fixed3-4 61.0ns ± 1% 55.0ns ± 2% -9.80% (p=0.000 n=9+10) AppendFloat/64Fixed4-4 66.9ns ± 0% 52.0ns ± 2% -22.20% (p=0.000 n=8+10) AppendFloat/64Fixed12-4 95.5ns ± 1% 76.2ns ± 3% -20.19% (p=0.000 n=10+9) AppendFloat/64Fixed16-4 1.62µs ± 0% 0.07µs ± 2% -95.69% (p=0.000 n=10+10) AppendFloat/64Fixed12Hard-4 1.27µs ± 1% 0.07µs ± 1% -94.83% (p=0.000 n=9+9) AppendFloat/64Fixed17Hard-4 3.68µs ± 1% 0.08µs ± 2% -97.86% (p=0.000 n=10+9) AppendFloat/64Fixed18Hard-4 3.67µs ± 0% 3.72µs ± 1% +1.44% (p=0.000 n=9+10) Updates #15672 Change-Id: I160963e141dd48287ad8cf57bcc3c686277788e8 Reviewed-on: https://go-review.googlesource.com/c/go/+/170079 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Nigel Tao <nigeltao@golang.org> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
2021-02-23all: faster midpoint computation in binary searchyangwenmai
On my machine (3.1 GHz Quad-Core Intel Core i7, macOS 10.15.7 10.15.7), go 1.15.6 benchstat: name old time/op new time/op delta SearchInts-8 20.3ns ± 1% 16.6ns ± 6% -18.37% (p=0.000 n=9+10) Change-Id: I346e5955fd6df6ce10254b22267dbc8d5a2b16c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/279439 Reviewed-by: Ben Shi <powerman1st@163.com> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org>
2021-02-20all: go fmt std cmd (but revert vendor)Russ Cox
Make all our package sources use Go 1.17 gofmt format (adding //go:build lines). Part of //go:build change (#41184). See https://golang.org/design/draft-gobuild Change-Id: Ia0534360e4957e58cd9a18429c39d0e32a6addb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/294430 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-12-14Merge branch 'master' into dev.regabiAlexander Rakoczy
Change-Id: I098acdbc5e2676aeb8700d935e796a9c29d04b88
2020-12-09all: update to use os.ReadFile, os.WriteFile, os.CreateTemp, os.MkdirTempRuss Cox
As part of #42026, these helpers from io/ioutil were moved to os. (ioutil.TempFile and TempDir became os.CreateTemp and MkdirTemp.) Update the Go tree to use the preferred names. As usual, code compiled with the Go 1.4 bootstrap toolchain and code vendored from other sources is excluded. ReadDir changes are in a separate CL, because they are not a simple search and replace. For #42026. Change-Id: If318df0216d57e95ea0c4093b89f65e5b0ababb3 Reviewed-on: https://go-review.googlesource.com/c/go/+/266365 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-11-24[dev.regabi] strconv: add to bootstrap packagesMatthew Dempsky
go/constant relies on strconv for parsing Go literals, while older versions of strconv either lack recent Go language features (e.g., Go 1.13's new numeric literals) or have errors (e.g., mishandling of carriage returns in raw string literals prior to Go 1.8). This requires two changes: 1. Splitting out the internal/bytealg dependency into a separate file, which can be easily substituted with a simple loop for bootstrap builds. 2. Updating eisel_lemire.go to not utilize Go 1.13 functionality (underscores in numeric literals and signed shift counts). Change-Id: Ib48a858a03b155eebdcd08d577aec2254337e70e Reviewed-on: https://go-review.googlesource.com/c/go/+/272749 Reviewed-by: Robert Griesemer <gri@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
2020-11-03strconv: revert ParseFloat/ParseComplex error on incorrect bitSizeBen Hoyt
This is a partial revert of https://go-review.googlesource.com/c/go/+/248219 because we found that a non-trivial amount of code erroneously calls ParseFloat(s, 10) or even ParseFloat(s, 0) and expects it to work -- before that change was merged, ParseFloat accepted a bitSize of anything other than 32 or 64 to mean 64 (and ParseComplex was similar). So revert that behavior to avoid breaking people's code, and add tests for this. I may add a vet check to flag ParseFloat(s, not_32_or_64) in a later change. See #42297 for more details. Change-Id: I4bc0156bd74f67a39d5561b6e5fde3f2d20bd622 Reviewed-on: https://go-review.googlesource.com/c/go/+/267319 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-10-30strconv: fix incorrect bit size in ParseComplex; add testsBen Hoyt
In ParseComplex, the "size" passed to parseFloatPrefix should be 64 for complex128, not 128. It still works because of how parseFloatPrefix is forgiving about the size if it's not 32, but worth fixing anyway. Make ParseComplex and ParseFloat return a bit size error for anything other than 128 or 64 (for ParseComplex), or 64 or 32 (for ParseFloat). Add "InvalidBitSize" tests for these cases. Add tests for ParseComplex with bitSize==64: this is done in a similar way to how the ParseFloat 32-bit tests work, re-using the tests for the larger bit size. Add tests for FormatComplex -- there were none before. Fixes #40706 Change-Id: I16ddd546e5237207cc3b8c2181dd708eca42b04f Reviewed-on: https://go-review.googlesource.com/c/go/+/248219 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Trust: Minux Ma <minux@golang.org> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
2020-10-29strconv: make Eisel-Lemire handle long mantissasRémy Oudompheng
In many cases, it is not necessary to parse long decimal mantissas entirely to produce the correctly rounded floating-point number. It is enough to parse the short, rounded lower and upper bounds and in most cases they round to the same floating point number because uint64 can hold 19 digits. Previously this case was handled by the extFloat code path (Grisu3 algorithm). name old time/op new time/op delta Atof64Big-4 1.07µs ± 2% 0.11µs ± 2% -89.61% (p=0.000 n=10+9) Atof64RandomLongFloats-4 8.03µs ± 2% 0.14µs ± 7% -98.24% (p=0.000 n=10+10) Atof32RandomLong-4 760ns ± 1% 156ns ± 0% -79.46% (p=0.000 n=10+8) Benchmarks versus extFloat: name old time/op new time/op delta Atof64Big-4 121ns ± 3% 111ns ± 2% -7.93% (p=0.000 n=10+9) Atof64RandomLongFloats-4 144ns ± 1% 142ns ± 7% ~ (p=0.167 n=10+10) Atof32RandomLong-4 129ns ± 1% 156ns ± 0% +21.12% (p=0.000 n=10+8) Change-Id: Id734b8c11e74b49a444fda67ee72870ae9422e60 Reviewed-on: https://go-review.googlesource.com/c/go/+/264677 Trust: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Russ Cox <rsc@golang.org> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org>