strings: Docs & Examples unclear about difference between ToTitle and ToUpper #37334
Comments
Or in other words:
Document an example that can help the user decide which function is the right one to use for his case. Something that helps him understand what the difference is. |
Title case and Upper case of a character have distinct definitions in unicode to allow for specific characters that have distinctive differences: https://unicode.org/faq/casemap_charprop.html#4 dz, in latin, is one for example: http://www.fileformat.info/info/unicode/char/01f3/index.htm It's hard to find a good example to add that doesn't add confusion to people who aren't already familiar with this feature of unicode. package main
import (
"fmt"
"strings"
)
func main() {
fmt.Println(strings.ToUpper("dzz")) // DZZ
fmt.Println(strings.ToTitle("dzz")) // DzZ
} What would you suggest? /cc @griesemer |
Assigned to @mpvl who is our local Unicode expert. |
True! After thinking about it for a short while I know what the difference means now as well. I thought, why not help and raise an small issue to make the difference a little more clear in the docs to be - in the future - quicker to decide what to use for a specific case. I think just add a little ToTitle specific string for the ToTitle example and we're good to go. If you want, I'm fine also with a decision against it. |
Change https://golang.org/cl/224097 mentions this issue: |
What version of Go are you using (
go version
)?The current documentation on https://golang.org/pkg/strings/
Does this issue reproduce with the latest release?
Yes, using the examples inside the strings package documentation
What operating system and processor architecture are you using (
go env
)?None providable
What did you do?
Copied
strings.ToTitle
example tostrings.ToUpper
and changedToTitle()
toToUpper()
:What did you expect to see?
A difference in output.
What did you see instead?
Example ToTitle (unmodified) outputs:
Example ToUpper (modified as described above) outputs:
No difference. So for me it is unclear which function is now the correct one to use for an imaginary case.
The text was updated successfully, but these errors were encountered: