1
0
mirror of https://github.com/golang/go synced 2024-10-05 09:11:21 -06:00
Commit Graph

13 Commits

Author SHA1 Message Date
Rob Pike
cb20146097 strings: mention UTF-8 in the package comment.
Also add a reference to the strings blog post.

Fixes #11045.

Change-Id: Ic0a8908cbd7b51a36d104849fa0e8abfd54de2b9
Reviewed-on: https://go-review.googlesource.com/10662
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-06-03 19:28:41 +00:00
Dmitry Vyukov
cfb8b18e75 strings: use LastIndexByte in LastIndex
Change-Id: I1add1b92f5c2688a99133d90bf9789d770fd9f05
Reviewed-on: https://go-review.googlesource.com/9503
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2015-04-30 08:33:29 +00:00
Dmitry Vyukov
0fb5475bdf bytes, strings: add LastIndexByte
Currently the packages have the following index functions:

func Index(s, sep []byte) int
func IndexAny(s []byte, chars string) int
func IndexByte(s []byte, c byte) int
func IndexFunc(s []byte, f func(r rune) bool) int
func IndexRune(s []byte, r rune) int

func LastIndex(s, sep []byte) int
func LastIndexAny(s []byte, chars string) int
func LastIndexFunc(s []byte, f func(r rune) bool) int

Searching for the last occurrence of a byte is quite common
for string parsing algorithms (e.g. find the last paren on a line).
Also addition of LastIndexByte makes the set more orthogonal.

Change-Id: Ida168849acacf8e78dd70c1354bef9eac5effafe
Reviewed-on: https://go-review.googlesource.com/9500
Reviewed-by: Rob Pike <r@golang.org>
2015-04-30 07:13:18 +00:00
Brad Fitzpatrick
c264c87335 bytes, strings: add Reader.Size methods
As noted on recently on golang-nuts, there's currently no way to know
the total size of a strings.Reader or bytes.Reader when using ReadAt
on them. Most callers resort to wrapping it in an io.SectionReader to
retain that information.

The SizeReaderAt abstraction (an io.ReaderAt with a Size() int64
method) has proven useful as a way of expressing a concurrency-safe
read-only number of bytes.

As one example, see http://talks.golang.org/2013/oscon-dl.slide#49 and
the rest of that presentation for its use in dl.google.com.

SizeReaderAt is also used in the open source google-api-go-client, and
within Google's internal codebase, where it exists in a public package
created in 2013 with the package comment: "These may migrate to the
standard library after we have enough experience with their feel."

I'm still as happy with the SizeReaderAt abstraction and its
composabilty as I was in 2013, so I'd like to make these two Readers
also be SizeReaderAts.

Fixes #9667

Change-Id: Ie6f145ada419dd116280472d8c029f046d5edf70
Reviewed-on: https://go-review.googlesource.com/3199
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2015-04-06 08:53:47 +00:00
John Potocny
6262192cd0 strings: Add benchmark test for trim function
The strings.Trim function and variants allocate memory on the heap when creating a function to pass into TrimFunc.
Add a benchmark to document the behavior; an issue will be submitted to address this behavior in the compiler if possible.

Change-Id: I8b66721f077951f7e7b8cf3cf346fac27a9b68c0
Reviewed-on: https://go-review.googlesource.com/8200
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-03-31 00:40:55 +00:00
areski
3f12d27133 bytes, os/exec, strings: fix a few BUG comments
Regular expression noteMarker requires the definition of a (who) section
when reading note from a sequence of comments.

Change-Id: I9635de9b86f00d20ec108097fee4d4a8f76237b2
Reviewed-on: https://go-review.googlesource.com/1952
Reviewed-by: Russ Cox <rsc@golang.org>
2015-03-20 18:34:39 +00:00
Josh Bleecher Snyder
2adc4e8927 all: use "reports whether" in place of "returns true if(f)"
Comment changes only.

Change-Id: I56848814564c4aa0988b451df18bebdfc88d6d94
Reviewed-on: https://go-review.googlesource.com/7721
Reviewed-by: Rob Pike <r@golang.org>
2015-03-18 15:14:06 +00:00
Robert Griesemer
19c1b163e8 bytes, strings: improve documentation for Count functions
Fixes #9659.

Change-Id: If364d5984a0c9a48858ae524b1560f633e621826
Reviewed-on: https://go-review.googlesource.com/3181
Reviewed-by: Rob Pike <r@golang.org>
2015-01-22 18:28:35 +00:00
Russ Cox
fd4dc91a96 strings: remove overengineered Compare implementation
The function is here ONLY for symmetry with package bytes.
This function should be used ONLY if it makes code clearer.
It is not here for performance. Remove any performance benefit.

If performance becomes an issue, the compiler should be fixed to
recognize the three-way compare (for all comparable types)
rather than encourage people to micro-optimize by using this function.

Change-Id: I71f4130bce853f7aef724c6044d15def7987b457
Reviewed-on: https://go-review.googlesource.com/3012
Reviewed-by: Rob Pike <r@golang.org>
2015-01-19 02:19:17 +00:00
Alan Donovan
90ce1936e3 strings: add Compare(x, y string) int, for symmetry with bytes.Compare
The implementation is the same assembly (or Go) routine.

Change-Id: Ib937c461c24ad2d5be9b692b4eed40d9eb031412
Reviewed-on: https://go-review.googlesource.com/2828
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-01-15 17:17:05 +00:00
Brad Fitzpatrick
4731c382f6 strings: use fast path for IndexRune
Noticed while reviewing https://golang.org/cl/147690043/

I'd never seen anybody use IndexRune before, and
unsurprisingly it doesn't use the other fast paths in the
strings/bytes packages. IndexByte uses assembly.

Also, less code this way.

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/147700043
2014-10-06 15:10:51 -07:00
Russ Cox
e9ec8e7a26 bytes, strings: document that FieldsFunc f must not be stateful
Fixes #8738.

LGTM=adg
R=golang-codereviews, adg
CC=golang-codereviews
https://golang.org/cl/143260045
2014-09-18 19:40:31 -04:00
Russ Cox
c007ce824d build: move package sources from src/pkg to src
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-08 00:08:51 -04:00