aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/strings/strings.go
AgeCommit message (Collapse)Author
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.
2014-09-01strings: use Rabin-Karp algorithm for LastIndex.Rui Ueyama
benchmark old ns/op new ns/op delta BenchmarkSingleMatch 49443 52275 +5.73% BenchmarkIndex 28.8 27.4 -4.86% BenchmarkLastIndex 14.5 14.0 -3.45% BenchmarkLastIndexHard1 3982782 2309200 -42.02% BenchmarkLastIndexHard2 3985562 2287715 -42.60% BenchmarkLastIndexHard3 3555259 2282866 -35.79% LGTM=josharian, nigeltao R=golang-codereviews, ality, josharian, bradfitz, dave, nigeltao, gobot, nightlyone CC=golang-codereviews https://golang.org/cl/102560043
2014-08-25strings, bytes: document behavior of Replace when old is emptyCaleb Spare
Fixes #8143. LGTM=r R=rsc, bradfitz, r CC=golang-codereviews https://golang.org/cl/135760043
2014-06-11bytes, strings: optimize RepeatRui Ueyama
Call copy with as large buffer as possible to reduce the number of function calls. benchmark old ns/op new ns/op delta BenchmarkBytesRepeat 540 162 -70.00% BenchmarkStringsRepeat 563 177 -68.56% LGTM=josharian R=golang-codereviews, josharian, dave, dvyukov CC=golang-codereviews https://golang.org/cl/90550043
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-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-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
2011-12-08update tree for new default type ruleRuss Cox
R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5448091
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-08renaming_3: gofix -r go1pkgrename src/pkg/[m-z]*Rob Pike
R=rsc CC=golang-dev https://golang.org/cl/5345045
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-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-04-20src/pkg: make package doc comments consistently start with "Package foo".Nigel Tao
R=rsc CC=golang-dev https://golang.org/cl/4442064
2011-03-29bytes, strings: simplify JoinEvan Shaw
R=gri, rsc CC=golang-dev https://golang.org/cl/4300044
2011-03-28strings: Map: avoid allocation when string is unchangedBrad Fitzpatrick
This speeds up strings.ToLower, etc. before/after: strings_test.BenchmarkMapNoChanges 1000000 1013 ns/op strings_test.BenchmarkMapNoChanges 5000000 442 ns/op R=r, rog, eh, rsc CC=golang-dev https://golang.org/cl/4306056
2011-03-08strings: add IndexRune tests, ASCII fast pathBrad Fitzpatrick
$ gotest -test.v -test.run=IndexRune -test.bench=.* === RUN strings_test.TestIndexRune --- PASS: strings_test.TestIndexRune (0.0 seconds) PASS strings_test.BenchmarkIndexRune 20000000 105 ns/op strings_test.BenchmarkIndexByte 50000000 48 ns/op R=rsc, dsymonds CC=golang-dev https://golang.org/cl/4267050
2011-01-04strings: fix description of FieldsFuncRoger Peppe
R=r CC=golang-dev https://golang.org/cl/3814041
2010-11-30utf8: make EncodeRune's destination the first argument.Adam Langley
R=r CC=golang-dev https://golang.org/cl/3364041
2010-11-12strings: add LastIndexAnyBenny Siegert
The need for a LastIndexAny function has come up in the discussion for https://golang.org/cl/3008041/. This function is implemented analogously to lastIndexFunc, using functions from the utf8 package. R=r, rsc, PeterGo CC=golang-dev https://golang.org/cl/3057041
2010-11-01strings: ContainsBrad Fitzpatrick
Tiny helper to avoid strings.Index(s, sub) != -1 R=rsc, r2, r CC=golang-dev https://golang.org/cl/2265044
2010-10-26use copyRuss Cox
R=gri CC=golang-dev https://golang.org/cl/2763041
2010-09-23bytes, strings: change lastIndexFunc to use DecodeLastRuneRoger Peppe
R=r CC=golang-dev, rsc https://golang.org/cl/2271041
2010-09-21strings: fix minor bug in LastIndexFuncRoger Peppe
R=r, rsc CC=golang-dev https://golang.org/cl/2250042
2010-08-05bytes: add IndexRune, FieldsFunc and To*SpecialChristian Himpel
Basically these functions are implemented the same way as the corresponding functions in the strings package. Test functions are implemented for IndexRune and FieldsFunc. Additionally two typos are fixed in packages bytes and strings. R=r CC=golang-dev https://golang.org/cl/1696062
2010-08-03strings: fix Split("", "", -1)Scott Lawrence
Fixes #980. Made it return an empty array, rather than crash. Added relevant test cases to strings. R=golang-dev, r CC=golang-dev https://golang.org/cl/1914041
2010-07-27bytes, strings: mention the n < 0 case in Split/SplitAfter doc commentAndrew Gerrand
R=r, rsc CC=golang-dev https://golang.org/cl/1669055
2010-07-23bytes: port IndexFunc and LastIndexFunc from strings packageFazlul Shahriar
This CL basically applies the same changes as http://code.google.com/p/go/source/detail?r=5e0a29014e8e but for bytes package. R=r, rog CC=golang-dev https://golang.org/cl/1670052
2010-07-20strings: add TitleRob Pike
strings.ToTitle converts all characters to title case, which for consistency with the other To* functions it should continue to do. This CL adds string.Title, which does a proper title-casing of the string. A similar function for package bytes will follow once this is settled. Fixes #933. R=rsc CC=golang-dev https://golang.org/cl/1869042
2010-07-01strings and bytes.Split: make count of 0 mean 0, not infinite.Rob Pike
Use a count of -1 for infinity. Ditto for Replace. R=rsc CC=golang-dev https://golang.org/cl/1704044
2010-06-30bytes, strings: add ReplaceRuss Cox
This is the Replace I suggested in the review of CL 1114041. It's true that we already have regexp.MustCompile(regexp.QuoteMeta(old)).ReplaceAll(s, new) but because this Replace is doing a simpler job it is simpler to call and inherently more efficient. I will add the bytes implementation and tests to the CL after the strings one has been reviewed. R=r, cw CC=golang-dev https://golang.org/cl/1731048
2010-06-14Add IndexFunc and LastIndexFunc.Roger Peppe
Change TrimRight and TrimLeft to use these functions. Incidentally fix minor bug in TrimRight. Add some test cases for this. YMMV whether it's worth saving the closure allocation. R=r, r2 CC=golang-dev, hoisie, rsc https://golang.org/cl/1198044
2010-05-05Conversion from loop to copy().Kyle Consalus
R=golang-dev, gri CC=golang-dev https://golang.org/cl/1072041
2010-04-19Added strings.FieldsFunc, a generalization of strings.Fields in style of the ↵Kyle Consalus
strings.Trim*Func functions. R=golang-dev, r CC=golang-dev https://golang.org/cl/824051
2010-04-09strings: add IndexRune, Trim, TrimLeft, TrimRight, and the generic ↵Michael Hoisie
equivalents TrimFunc, TrimLeftFunc, TrimRightFunc R=rsc, r CC=golang-dev https://golang.org/cl/799048
2010-03-30Unicode: provide an ability to supplement the case-mapping tablesRob Pike
in character and string case mapping routines. Add a custom mapper for Turkish and Azeri. A more general solution for deriving the case information from Unicode's SpecialCasing.txt will require more work. Fixes #703. R=rsc, rsc1 CC=golang-dev, mdakin https://golang.org/cl/824043
2010-03-29strings.FIelds: slight simplification.Rob Pike
R=rsc CC=golang-dev https://golang.org/cl/833042
2010-03-26bytes, strings: IndexOfAnyRobert Griesemer
+ first use in go/doc R=r CC=golang-dev https://golang.org/cl/781041
2010-03-04strings: make Split(s, "", n) fasterSpring Mc
R=rsc CC=golang-dev https://golang.org/cl/223096
2010-02-25strings: delete Runes, BytesRuss Cox
gofmt -w -r 'strings.Bytes(a) -> []byte(a)' src/cmd src/pkg test/bench gofmt -w -r 'strings.Runes(a) -> []int(a)' src/cmd src/pkg test/bench delete unused imports R=r CC=golang-dev https://golang.org/cl/224062
2010-02-25strings: remove a couple of redundant testsRobert Griesemer
(per suggestion from Heresy.Mc@gmail.com) R=rsc CC=golang-dev https://golang.org/cl/223052