-
Notifications
You must be signed in to change notification settings - Fork 18k
x/text/encoding/charmap: values should have type *Charmap, not encoding.Encoding #19584
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
Comments
@nigeltao generally I think this is a good idea. This has the other big benefit that the linker can now shed unused encodings. This is probably something that should be done for all encodings. One caveat with this API is the user now needs to be aware of text normalization. The encoding packages are the only ones in the text repo where the input needs to be normalized to get consistent encodings. I plan to fix this at some point and the current API supports that. Using this API there is no way around it that the user needs to normalize to NFC first. But I guess in this use case that was already lost. In fact, this API will make documenting this possible. Furthermore, I recall seeing some of the "single-byte" encodings allowing for a multi-rune decoding, but I must be wrong. I ran |
I think the change from interface to concrete type is a good idea independent of the proposed |
CL https://golang.org/cl/38873 mentions this issue. |
Seems breaking compatibility. mattn/go-encoding#1 |
But I understand why this change was required. So ignore this. Sorry. |
The golang.org/x/text/encoding/charmap package exports values of type encoding.Encoding (an interface, https://godoc.org/golang.org/x/text/encoding#Encoding):
var Macintosh encoding.Encoding = etc
Being an interface (defined in another package) means that we can't add extra methods to these variables.
The (API-breaking) proposal is to change these variable's types from encoding.Encoding to *Charmap (the existing charmap type would be exported as Charmap), and then add two methods:
The motivation is that https://go.googlesource.com/image/+/master/font/sfnt/cmap.go contains:
With this proposal, this code would become:
@mpvl
The text was updated successfully, but these errors were encountered: