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

strconv: QuotedPrefix documentation ambiguous #46829

Closed
seebs opened this issue Jun 19, 2021 · 5 comments
Closed

strconv: QuotedPrefix documentation ambiguous #46829

seebs opened this issue Jun 19, 2021 · 5 comments
Labels
Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@seebs
Copy link
Contributor

seebs commented Jun 19, 2021

What version of Go are you using (go version)?

1.17 release notes

Does this issue reproduce with the latest release?

arguably no since the latest release, 1.16, does not have this function yet :)

What operating system and processor architecture are you using (go env)?

N/A

What did you do?

Read release notes and corresponding documentation.

What did you expect to see?

Documentation that I understand.

What did you see instead?

Documentation which confused me.

QuotedPrefix returns the quoted string (as understood by Unquote) at the prefix of s. If s does not start with a valid quoted string, QuotedPrefix returns an error.

It is unclear to me whether "as understood by Unquote" means "an initial prefix which Unquote would think was a valid quoted string that it could unquote", or "the result of unquoting such an initial prefix".

For instance, consider the string:

"foo"bar

I would guess that QuotedPrefix, called on this, would yield either "foo" or foo, but i don't know which; both are "the quoted string (as understood by Unquote)". I think the intent is probably "foo", because that seems more likely to be useful -- given the other string, I don't have a way to trim that prefix from the parent string, because I don't know how it looked in the parent string. On the other hand, it seems weird to go to all the trouble of separating it out and parsing it as though unquoting, and not actually do the unquoting, so I don't know.

I feel like QuotedPrefix should probably return (prefix string, remainder string, error). I'm less sure about dequoting; the dequoting operation presumably causes allocation. (It'd be neat, though, to be able to inquire as to the length the dequoted string would have...)

@seankhliao seankhliao changed the title strconv/QuotedPrefix documentation ambiguous strconv: QuotedPrefix documentation ambiguous Jun 19, 2021
@ianlancetaylor
Copy link
Contributor

CC @dsnet

@ianlancetaylor
Copy link
Contributor

For the record, QuotedPrefix finds the quoted prefix, and returns exactly that without unquoting it. There was discussion at #45033.

@ianlancetaylor ianlancetaylor added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Jun 19, 2021
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Jun 19, 2021
@dsnet
Copy link
Member

dsnet commented Jul 22, 2021

It says:

QuotedPrefix returns the quoted string (as understood by Unquote) at the prefix of s.

The adjective "quoted" implies that the result still contains the surrounding quotes. If the adjective wasn't there, then it would be ambiguous.

I'll add an example, so that it's more obvious what the function does.

@gopherbot
Copy link

Change https://golang.org/cl/336749 mentions this issue: strconv: add example for QuotedPrefix

@qiulaidongfeng
Copy link
Contributor

Is this issue waiting for CL336749 to be merged?

yunginnanet pushed a commit to yunginnanet/go that referenced this issue Oct 20, 2023
Example can sometimes be more informative than additional prose.

Fixes golang#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants