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

x/text: Title() behaves differently than strings.Title() #51956

Closed
hangxie opened this issue Mar 25, 2022 · 4 comments
Closed

x/text: Title() behaves differently than strings.Title() #51956

hangxie opened this issue Mar 25, 2022 · 4 comments
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@hangxie
Copy link

hangxie commented Mar 25, 2022

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

$ go version
go version go1.18 darwin/arm64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/xiehang/Library/Caches/go-build"
GOENV="/Users/xiehang/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/xiehang/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/xiehang/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.18/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.18/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/xiehang/dev/parquet-tools/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vj/wtn1vqpj12g4k75p7snx28d80000gn/T/go-build3311008797=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://go.dev/play/p/qGo_iTp7AQ7

What did you expect to see?

cases.Title() behaves the same as strings.Title(), I believe this is what #48367 tells (explicitly)

What did you see instead?

cases.Title() changes the first character to uppercase, and change rest of the string lowercase
strings.Title() changes the first character to uppercase, leave rest of the string untouched.

@gopherbot gopherbot added this to the Unreleased milestone Mar 25, 2022
@frederikhors
Copy link

Surprisingly, in the same minutes you, @hangxie and I discovered the same problems: #48367 (comment).

@ianlancetaylor
Copy link
Contributor

I'm not sure there is anything to do here. Evidently we were mistaken in thinking that cases.Title was a drop-in replacement for strings.Title. Sorry about that. But changing cases.Title would lead to compatibility concerns. And the deprecation notice for strings.Title doesn't actually refer to cases.Title.

I'm open to suggestions.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Mar 26, 2022
@smasher164
Copy link
Member

cases.Title does work as a substitute for strings.Title as long as you pass in the cases.NoLower option to the Caser.
The corrected version of the example should be
https://go.dev/play/p/uzYSvdtKNRy

package main

import (
	"fmt"
	"strings"

	"golang.org/x/text/cases"
	"golang.org/x/text/language"
)

func main() {
	orig := "thisIsCool"
	c := cases.Title(language.Und, cases.NoLower).String(orig)
	s := strings.Title(orig)
	fmt.Printf("orig: %s\ncases: %s\nstrings: %s\n", orig, c, s)
}

which outputs

orig: thisIsCool
cases: ThisIsCool
strings: ThisIsCool

@hangxie
Copy link
Author

hangxie commented Mar 26, 2022

cases.Title does work as a substitute for strings.Title as long as you pass in the cases.NoLower option to the Caser.

Perfect, thank you!

@hangxie hangxie closed this as completed Mar 26, 2022
ALiwoto referenced this issue in AnimeKaizoku/ssg Apr 14, 2022
Add tests for Title function.

Signed-off-by: aliwoto <aminnimaj@gmail.com>
@golang golang locked and limited conversation to collaborators Mar 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

5 participants