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

proposal: unicode/utf8: add String #30615

Open
ianlancetaylor opened this issue Mar 6, 2019 · 3 comments
Open

proposal: unicode/utf8: add String #30615

ianlancetaylor opened this issue Mar 6, 2019 · 3 comments

Comments

@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Mar 6, 2019

Issue #3939 proposes removing the conversion from integer types to string types. In order to do that, it will be convenient if we have an exact replacement in the standard library.

I propose adding a new function to the unicode/utf8 package:

func String(r rune) string

This function will return a string containing the UTF-8 encoding of its argument.

The implementation will be equivalent to the following, though of course it may be further optimized.

func String(r rune) string {
    var a [4]byte
    return string(a[:EncodeRune(a[:], r)])
}
@ianlancetaylor ianlancetaylor added this to the Proposal milestone Mar 6, 2019
@robpike
Copy link
Contributor

robpike commented Mar 6, 2019

SGTM although the name is cumbrous yet fits the package (but the As is new).

I think though you could get away with String: utf8.String(r) reads well. Although I admit it steals a good word, it's just a replacement for string(r) so why not?

@ianlancetaylor ianlancetaylor changed the title proposal: unicode/utf8: add EncodeRuneAsString proposal: unicode/utf8: add String Mar 6, 2019
@ianlancetaylor
Copy link
Contributor Author

Much better. I updated the proposal.

@rsc
Copy link
Contributor

rsc commented Mar 6, 2019

If we resolve #3939 by keeping string(r) for rune-typed r, then we won't need this.
If we do remove string(r), we will need to introduce this a release or two before string(r) disappears, to allow a smooth transition. Can put this on hold until #3939 plans are figured out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants