aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings
AgeCommit message (Collapse)Author
2013-11-01[release-branch.go1.2] strings: fix Replacer bug with prefix matchesAndrew Gerrand
««« CL 16880043 / 0eb6508d3e88 strings: fix Replacer bug with prefix matches singleStringReplacer had a bug where if a string was replaced at the beginning and no output had yet been produced into the temp buffer before matching ended, an invalid nil check (used as a proxy for having matched anything) meant it always returned its input. Fixes #6659 R=golang-dev, r CC=golang-dev https://golang.org/cl/16880043 »»» R=golang-dev CC=golang-dev https://golang.org/cl/20570044
2013-08-27bytes, strings: use copy in RepeatEvan Shaw
R=golang-dev, dave, bradfitz, adg CC=golang-dev https://golang.org/cl/13249043
2013-08-09strings: add test for CountPieter Droogendijk
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/12541050
2013-08-06strings: add IndexByte benchmarkBrad Fitzpatrick
Like existing Index, IndexRune, IndexHardN, etc. R=golang-dev, khr CC=golang-dev https://golang.org/cl/12486044
2013-08-05strings: use runtime assembly for IndexByteBrad Fitzpatrick
Fixes #3751 R=golang-dev, khr CC=golang-dev https://golang.org/cl/12483043
2013-08-01strings: add IndexByte, for consistency with bytes packageBrad Fitzpatrick
I always forget which package has it. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/12214044
2013-03-19bytes,strings: remove user name from BUG in commentRob Pike
R=golang-dev, dave CC=golang-dev https://golang.org/cl/7856048
2013-03-15bytes,string: move the BUG to the comment of the function it's aboutRob Pike
Avoids printing it every time we ask a question about the package from the command line. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/7789048
2013-03-06strings: remove allocations in Split(s, "")Ewan Chou
BenchmarkSplit1 77984460 24131380 -69.06% R=golang-dev, rsc, minux.ma, dave, extemporalgenome CC=golang-dev https://golang.org/cl/7458043
2013-02-28all: fix a few more printf arg bugs found by go vetRob Pike
R=golang-dev, iant CC=golang-dev https://golang.org/cl/7413045
2013-02-20bufio: new Scanner interfaceRob Pike
Add a new, simple interface for scanning (probably textual) data, based on a new type called Scanner. It does its own internal buffering, so should be plausibly efficient even without injecting a bufio.Reader. The format of the input is defined by a "split function", by default splitting into lines. Other implemented split functions include single bytes, single runes, and space-separated words. Here's the loop to scan stdin as a file of lines: s := bufio.NewScanner(os.Stdin) for s.Scan() { fmt.Printf("%s\n", s.Bytes()) } if s.Err() != nil { log.Fatal(s.Err()) } While we're dealing with spaces, define what space means to strings.Fields. Fixes #4802. R=adg, rogpeppe, bradfitz, rsc CC=golang-dev https://golang.org/cl/7322088
2013-02-19strings: faster Count, IndexDonovan Hide
Slightly better benchmarks for when string and separator are equivalent and also less branching in inner loops. benchmark old ns/op new ns/op delta BenchmarkGenericNoMatch 3430 3442 +0.35% BenchmarkGenericMatch1 23590 22855 -3.12% BenchmarkGenericMatch2 108031 105025 -2.78% BenchmarkSingleMaxSkipping 2969 2704 -8.93% BenchmarkSingleLongSuffixFail 2826 2572 -8.99% BenchmarkSingleMatch 205268 197832 -3.62% BenchmarkByteByteNoMatch 987 921 -6.69% BenchmarkByteByteMatch 2014 1749 -13.16% BenchmarkByteStringMatch 3083 3050 -1.07% BenchmarkHTMLEscapeNew 922 915 -0.76% BenchmarkHTMLEscapeOld 1654 1570 -5.08% BenchmarkByteByteReplaces 11897 11556 -2.87% BenchmarkByteByteMap 4485 4255 -5.13% BenchmarkIndexRune 174 121 -30.46% BenchmarkIndexRuneFastPath 41 41 -0.24% BenchmarkIndex 45 44 -0.22% BenchmarkMapNoChanges 433 431 -0.46% BenchmarkIndexHard1 4015336 3316490 -17.40% BenchmarkIndexHard2 3976254 3395627 -14.60% BenchmarkIndexHard3 3973158 3378329 -14.97% BenchmarkCountHard1 4403549 3448512 -21.69% BenchmarkCountHard2 4387437 3413059 -22.21% BenchmarkCountHard3 4403891 3382661 -23.19% BenchmarkIndexTorture 28354 25864 -8.78% BenchmarkCountTorture 29625 27463 -7.30% BenchmarkFields 38752040 39169840 +1.08% BenchmarkFieldsFunc 38797765 38888060 +0.23% benchmark old MB/s new MB/s speedup BenchmarkSingleMaxSkipping 3367.07 3697.62 1.10x BenchmarkSingleLongSuffixFail 354.51 389.47 1.10x BenchmarkSingleMatch 73.07 75.82 1.04x BenchmarkFields 27.06 26.77 0.99x BenchmarkFieldsFunc 27.03 26.96 1.00x R=dave, fullung, remyoudompheng, rsc CC=golang-dev https://golang.org/cl/7350045
2013-02-17strings: better mean complexity for Count and Index.Rémy Oudompheng
The O(n+m) complexity is obtained probabilistically by using Rabin-Karp algorithm, which provides the needed complexity unless exceptional collisions occur, without memory allocation. benchmark old ns/op new ns/op delta BenchmarkIndexHard1 6532331 4045886 -38.06% BenchmarkIndexHard2 8178173 4038975 -50.61% BenchmarkIndexHard3 6973687 4042591 -42.03% BenchmarkCountHard1 6270864 4071090 -35.08% BenchmarkCountHard2 7838039 4072853 -48.04% BenchmarkCountHard3 6697828 4071964 -39.20% BenchmarkIndexTorture 2730546 28934 -98.94% BenchmarkCountTorture 2729622 29064 -98.94% Fixes #4600. R=rsc, donovanhide, remyoudompheng CC=golang-dev https://golang.org/cl/7314095
2013-02-01bytes, strings: add TrimPrefix and TrimSuffixBrad Fitzpatrick
Everybody either gets confused and thinks this is TrimLeft/TrimRight or does this by hand which gets repetitive looking. R=rsc, kevlar CC=golang-dev https://golang.org/cl/7239044
2012-11-25bytes, strings: fix Reader WriteTo return value on 0 bytes copiedBrad Fitzpatrick
Fixes #4421 R=golang-dev, dave, minux.ma, mchaten, rsc CC=golang-dev https://golang.org/cl/6855083
2012-10-30gofmt: apply gofmt -w src miscRobert Griesemer
Remove trailing whitespace in comments. No other changes. R=r CC=golang-dev https://golang.org/cl/6815053
2012-10-12bytes, strings: add (*Reader).WriteToEvan Shaw
Fixes #4031. R=golang-dev, bradfitz, remyoudompheng, r, dave CC=golang-dev https://golang.org/cl/6632046
2012-09-28strings: implement a faster single-string ReplacerEric Roshan-Eisner
The string searching is implemented separately so other functions may make use of it in the future. benchmark old ns/op new ns/op delta BenchmarkSingleMaxSkipping 125889 2474 -98.03% BenchmarkSingleLongSuffixFail 16252 1996 -87.72% BenchmarkSingleMatch 260793 136266 -47.75% benchmark old MB/s new MB/s speedup BenchmarkSingleMaxSkipping 79.43 4041.57 50.88x BenchmarkSingleLongSuffixFail 61.65 501.81 8.14x BenchmarkSingleMatch 57.52 110.08 1.91x R=nigeltao CC=golang-dev https://golang.org/cl/6545049
2012-09-18bytes, strings: add Fields benchmarksRuss Cox
The performance changes will be a few different CLs. Start with benchmarks as a baseline. R=golang-dev, r CC=golang-dev https://golang.org/cl/6537043
2012-09-17strings: implement a faster generic ReplacerEric Eisner
This also fixes the semantics of some corner cases with the empty match. TODOs for genericReplacer in the tests are fixed. benchmark old ns/op new ns/op delta BenchmarkGenericNoMatch 71395 3132 -95.61% BenchmarkGenericMatch1 75610 20280 -73.18% BenchmarkGenericMatch2 837995 86725 -89.65% R=nigeltao, rsc CC=golang-dev https://golang.org/cl/6492076
2012-09-12strings: fix NewReplacer(old0, new0, old1, new1, ...) to be consistentNigel Tao
when oldi == oldj. Benchmark numbers show no substantial change. R=eric.d.eisner, rogpeppe CC=golang-dev https://golang.org/cl/6496104
2012-09-11strings: more thorough Replacer tests.Nigel Tao
This verifies existing behavior. Some replacements are arguably wrong (these are marked with TODO) but changing behavior is left for a follow-up CL. Also fix that BenchmarkGenericMatch wasn't actually matching anything. R=rsc, eric.d.eisner CC=bradfitz, golang-dev https://golang.org/cl/6488110
2012-05-22go/parser: fix comment grouping (day 1 bug)Robert Griesemer
Comment groups must end at the end of a line (or the next non-comment token) if the group started on a line with non-comment tokens. This is important for correct computation of "lead" and "line" comments (Doc and Comment fields in AST nodes). Without this fix, the "line" comment for F1 in the following example: type T struct { F1 int // comment1 // comment2 F2 int } is "// comment1// comment2" rather than just "// comment1". This bug was present from Day 1 but only visible when looking at export-filtered ASTs where only comments associated with AST nodes are printed, and only in rare cases (e.g, in the case above, if F2 where not exported, godoc would show "// comment2" anyway because it was considered part of the "line" comment for F1). The bug fix is very small (parser.go). The bulk of the changes are additional test cases (parser_test.go). The fix exposed a caching bug in go/printer via one of the existing tests, hence the changes to printer.go. As an aside, the fix removes the the need for empty lines before an "// Output" comment for some special cases of code examples (e.g.: src/pkg/strings/example_test.go, Count example). No impact on gofmt formatting of src, misc. Fixes #3139. R=rsc CC=golang-dev https://golang.org/cl/6209080
2012-03-05strings: Rename example to match function name.Volker Dobler
R=golang-dev, adg CC=golang-dev https://golang.org/cl/5729065
2012-02-27strings: make Count example show resultsRobert Griesemer
Thanks to dr.volker.dobler for tracking this down. Filed a long-term issue (3142) which may eventually resolve this problem w/o the need for a manual fix. R=iant CC=golang-dev https://golang.org/cl/5698078
2012-02-16godoc: make example code more readable with new comment conventionAndrew Gerrand
go/doc: move Examples to go/ast cmd/go: use go/doc to read examples src/pkg: update examples to use new convention This is to make whole file examples more readable. When presented as a complete function, preceding an Example with its output is confusing. The new convention is to put the expected output in the final comment of the example, preceded by the string "output:" (case insensitive). An idiomatic example looks like this: // This example demonstrates Foo by doing bar and quux. func ExampleFoo() { // example body that does bar and quux // Output: // example output } R=rsc, gri CC=golang-dev https://golang.org/cl/5673053
2012-02-15strings: add Bernardo O'Higgins exampleAndrew Gerrand
R=r, bradfitz CC=golang-dev, rogpeppe https://golang.org/cl/5673049
2012-02-15bytes,strings: make *Reader implement io.ReaderAtBrad Fitzpatrick
R=golang-dev, adg, bradfitz, r CC=golang-dev https://golang.org/cl/5675053
2012-02-13strings: more examplesBrad Fitzpatrick
R=golang-dev, adg CC=golang-dev https://golang.org/cl/5645092
2012-02-10strings: delete method comments implied by interface satisfactionRob Pike
Fixes #2957. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5653053
2012-02-09strings: add Seek method to ReaderBrad Fitzpatrick
strings.Reader is already stateful and read-only. This permits a *Reader with http.ServeContent. R=golang-dev, r, rsc, rsc CC=golang-dev https://golang.org/cl/5639068
2012-02-03strings: add Fields exampleBrad Fitzpatrick
R=golang-dev, rsc, r CC=golang-dev https://golang.org/cl/5629043
2012-01-30build: remove Make.pkg, Make.toolRuss Cox
Consequently, remove many package Makefiles, and shorten the few that remain. gomake becomes 'go tool make'. Turn off test phases of run.bash that do not work, flagged with $BROKEN. Future CLs will restore these, but this seemed like a big enough CL already. R=golang-dev, r CC=golang-dev https://golang.org/cl/5601057
2011-12-20panics: use the new facilities of testing.B insteadRob Pike
Lots of panics go away. Also fix a name error in html/template. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5498045
2011-12-08update tree for new default type ruleRuss Cox
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5448091
2011-11-28strings: fix test outputChristopher Wedgwood
R=rsc, gri CC=golang-dev https://golang.org/cl/5445044
2011-11-23strings: Add ContainsAny and ContainsRune to correspond to IndexAny etc.Scott Lawrence
R=golang-dev, r CC=golang-dev https://golang.org/cl/5430046
2011-11-13various: avoid func compareRuss Cox
R=gri, r, bradfitz CC=golang-dev https://golang.org/cl/5371074
2011-11-08renaming_3: gofix -r go1pkgrename src/pkg/[m-z]*Rob Pike
R=rsc CC=golang-dev https://golang.org/cl/5345045
2011-11-03all: rename os.EOF to io.EOF in various non-code contextsVincent Vanackere
R=golang-dev, r CC=golang-dev https://golang.org/cl/5334050
2011-11-01src/pkg/[n-z]*: gofix -r error -force=errorRuss Cox
R=golang-dev, bsiegert, iant CC=golang-dev https://golang.org/cl/5294074
2011-10-25bytes, strings: use runeRuss Cox
Various rune-based APIs change. R=golang-dev, r CC=golang-dev https://golang.org/cl/5306044
2011-10-03strings: implement a faster byte->string ReplacerBrad Fitzpatrick
This implements a replacer for when all old strings are single bytes, but new values are not. BenchmarkHTMLEscapeNew 1000000 1090 ns/op BenchmarkHTMLEscapeOld 1000000 2049 ns/op R=rsc CC=golang-dev https://golang.org/cl/5176043
2011-10-03strings: implement a faster byte->byte ReplacerBrad Fitzpatrick
When all old & new string values are single bytes, byteReplacer is now used, instead of the generic algorithm. BenchmarkGenericMatch 10000 102519 ns/op BenchmarkByteByteMatch 1000000 2178 ns/op fast path, when nothing matches: BenchmarkByteByteNoMatch 1000000 1109 ns/op comparisons to multiple Replace calls: BenchmarkByteByteReplaces 100000 16164 ns/op comparison to strings.Map: BenchmarkByteByteMap 500000 5454 ns/op R=rsc CC=golang-dev https://golang.org/cl/5175050
2011-09-28strings: add Replacer, NewReplacerBrad Fitzpatrick
This is just a new API to do many replacements at once. While the point of this API is to be faster than doing replacements one at a time, the implementation in this CL has the optimizations removed and may actually be slower. Future CLs will bring back & add optimizations. R=r, rsc, rogpeppe CC=golang-dev https://golang.org/cl/5081042
2011-09-26bytes: add EqualFoldRuss Cox
R=golang-dev, r, r CC=golang-dev https://golang.org/cl/5123047
2011-09-26strings: add EqualFoldRuss Cox
Case-insensitive strcmp without using ToLower. (Using ToLower is not always correct, and it allocates.) R=golang-dev, r CC=golang-dev https://golang.org/cl/5143044
2011-07-14go/printer: changed max. number of newlines from 3 to 2Robert Griesemer
manual changes in src/pkg/go/printer, src/cmd/gofix/signal_test.go (cd src/cmd/gofix/testdata; gofmt -w *.in *.out) (cd src/pkg/go/printer; gotest -update) gofmt -w misc src runs all tests R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4715041
2011-06-28strings.Split: make the default to split all.Rob Pike
Change the signature of Split to have no count, assuming a full split, and rename the existing Split with a count to SplitN. Do the same to package bytes. Add a gofix module. R=adg, dsymonds, alex.brainman, rsc CC=golang-dev https://golang.org/cl/4661051
2011-06-22os.Error API: don't export os.ErrorString, use os.NewError consistentlyRobert Griesemer
This is a core API change. 1) gofix misc src 2) Manual adjustments to the following files under src/pkg: gob/decode.go rpc/client.go os/error.go io/io.go bufio/bufio.go http/request.go websocket/client.go as well as: src/cmd/gofix/testdata/*.go.in (reverted) test/fixedbugs/bug243.go 3) Implemented gofix patch (oserrorstring.go) and test case (oserrorstring_test.go) Compiles and runs all tests. R=r, rsc, gri CC=golang-dev https://golang.org/cl/4607052