{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/21442","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/21442/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/21442/comments","events_url":"https://api.github.com/repos/golang/go/issues/21442/events","html_url":"https://github.com/golang/go/issues/21442","id":250101007,"number":21442,"title":"strings: fix Title function","user":{"login":"GwynethLlewelyn","id":304404,"avatar_url":"https://avatars1.githubusercontent.com/u/304404?v=4","gravatar_id":"","url":"https://api.github.com/users/GwynethLlewelyn","html_url":"https://github.com/GwynethLlewelyn","followers_url":"https://api.github.com/users/GwynethLlewelyn/followers","following_url":"https://api.github.com/users/GwynethLlewelyn/following{/other_user}","gists_url":"https://api.github.com/users/GwynethLlewelyn/gists{/gist_id}","starred_url":"https://api.github.com/users/GwynethLlewelyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GwynethLlewelyn/subscriptions","organizations_url":"https://api.github.com/users/GwynethLlewelyn/orgs","repos_url":"https://api.github.com/users/GwynethLlewelyn/repos","events_url":"https://api.github.com/users/GwynethLlewelyn/events{/privacy}","received_events_url":"https://api.github.com/users/GwynethLlewelyn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-08-14T17:38:22Z","updated_at":"2017-08-14T21:23:47Z","closed_at":null,"body":"First of all: no, this is **not** #6801!\r\n\r\nInstead, I just wanted to point out that the current `strings.Title()` implementation is a 'quick & dirty' way of dealing with titles; it does not respect proper English rules for title naming (although it might be appropriate for _some_ languages, I don't know).\r\n\r\nA suggestion was made on the [Go Cookbook](http://golangcookbook.com/chapters/strings/title/) to implement it thusly:\r\n\r\n```\r\nfunc properTitle(input string) string {\r\n\twords := strings.Fields(input)\r\n\tsmallwords := \" a an on the to \"\r\n\r\n\tfor index, word := range words {\r\n\t\tif strings.Contains(smallwords, \" \"+word+\" \") {\r\n\t\t\twords[index] = word\r\n\t\t} else {\r\n\t\t\twords[index] = strings.Title(word)\r\n\t\t}\r\n\t}\r\n\treturn strings.Join(words, \" \")\r\n}\r\n```\r\nThis is a clever and neat trick, and could be used for other languages as well (ex. in Portuguese the `smallwords` would have to include \" de do da dos das \" but possibly exclude \"a\" since that is by coincidence also a definite article, etc.).\r\nThe authors of the Go Cookbook did not seem to add a suggestion here, so I'm doing it 🙂"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/322313879","html_url":"https://github.com/golang/go/issues/21442#issuecomment-322313879","issue_url":"https://api.github.com/repos/golang/go/issues/21442","id":322313879,"user":{"login":"GwynethLlewelyn","id":304404,"avatar_url":"https://avatars1.githubusercontent.com/u/304404?v=4","gravatar_id":"","url":"https://api.github.com/users/GwynethLlewelyn","html_url":"https://github.com/GwynethLlewelyn","followers_url":"https://api.github.com/users/GwynethLlewelyn/followers","following_url":"https://api.github.com/users/GwynethLlewelyn/following{/other_user}","gists_url":"https://api.github.com/users/GwynethLlewelyn/gists{/gist_id}","starred_url":"https://api.github.com/users/GwynethLlewelyn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GwynethLlewelyn/subscriptions","organizations_url":"https://api.github.com/users/GwynethLlewelyn/orgs","repos_url":"https://api.github.com/users/GwynethLlewelyn/repos","events_url":"https://api.github.com/users/GwynethLlewelyn/events{/privacy}","received_events_url":"https://api.github.com/users/GwynethLlewelyn/received_events","type":"User","site_admin":false},"created_at":"2017-08-14T21:23:47Z","updated_at":"2017-08-14T21:23:47Z","body":"Sure, the best example is on the [Go Cookbook](http://golangcookbook.com/chapters/strings/title/) itself:\r\n\r\n`strings.Title(\"welcome to the dollhouse!\")` gives `Welcome To The Dollhouse!`\r\n\r\nwhile\r\n\r\n`properTitle(\"welcome to the dollhouse!\")` gives `Welcome to the Dollhouse!`\r\n\r\nwhich is grammatically correct (while the result from `strings.Title()` is not)"}}
{"actor":{"display_login":"GwynethLlewelyn"}}