Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bytes: bytes.Count(buf, []byte {}) return number of runes in buf + 1 #9659

Closed
kostya-sh opened this issue Jan 22, 2015 · 3 comments
Closed
Milestone

Comments

@kostya-sh
Copy link
Contributor

I believe bytes.Count(buf, []byte {}) should return len(buf) + 1. Currently it returns utf8.RuneCount(s) + 1

Demo to show the problem: http://play.golang.org/p/xjQJGlmuOJ

@kostya-sh kostya-sh changed the title bytes.Count(buf, []byte {}) return number of runes in buf + 1 bytes: bytes.Count(buf, []byte {}) return number of runes in buf + 1 Jan 22, 2015
@bradfitz
Copy link
Contributor

Either way, the docs don't say. And I agree the name of the package alone would suggest it operates on bytes and not runes. Over to @robpike.

@minux
Copy link
Member

minux commented Jan 22, 2015

The reason is that bytes.Count is direct analogous to the strings.Count
function.

However, I do agree that although this behavior is natural for
strings.Count,
it is not apparent for bytes.Count.

Needs doc fix.

@bradfitz bradfitz added this to the Go1.5 milestone Jan 22, 2015
@cespare
Copy link
Contributor

cespare commented Jan 22, 2015

We had the same discussion on #8143 (about Replace). bytes is intended to be the same as strings, but just take []byte arguments.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants