cmd/geth, core/rawdb, internal/version: replace deprecated strings.Title

strings.Title has been deprecated since Go 1.18 because it does not
handle Unicode punctuation properly. Replace all 4 call sites with
cases.Title from golang.org/x/text which is already a dependency.

Use cases.NoLower to preserve the original strings.Title behavior
of only capitalizing the first letter of each word without lowering
the rest.
This commit is contained in:
ray 2026-04-15 19:23:52 +08:00
parent ef0f1f96f9
commit a7654f1916
3 changed files with 11 additions and 5 deletions

View file

@ -20,10 +20,11 @@ import (
"fmt" "fmt"
"os" "os"
"runtime" "runtime"
"strings"
"github.com/ethereum/go-ethereum/internal/version" "github.com/ethereum/go-ethereum/internal/version"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
"golang.org/x/text/cases"
"golang.org/x/text/language"
) )
var ( var (
@ -47,7 +48,7 @@ The output of this command is supposed to be machine-readable.
func printVersion(ctx *cli.Context) error { func printVersion(ctx *cli.Context) error {
git, _ := version.VCS() git, _ := version.VCS()
fmt.Println(strings.Title(clientIdentifier)) fmt.Println(cases.Title(language.English, cases.NoLower).String(clientIdentifier))
fmt.Println("Version:", version.WithMeta) fmt.Println("Version:", version.WithMeta)
if git.Commit != "" { if git.Commit != "" {
fmt.Println("Git Commit:", git.Commit) fmt.Println("Git Commit:", git.Commit)

View file

@ -38,6 +38,8 @@ import (
"github.com/ethereum/go-ethereum/internal/tablewriter" "github.com/ethereum/go-ethereum/internal/tablewriter"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"golang.org/x/text/cases"
"golang.org/x/text/language"
) )
var ErrDeleteRangeInterrupted = errors.New("safe delete range operation interrupted") var ErrDeleteRangeInterrupted = errors.New("safe delete range operation interrupted")
@ -657,11 +659,12 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
if err != nil { if err != nil {
return err return err
} }
caser := cases.Title(language.English, cases.NoLower)
for _, ancient := range ancients { for _, ancient := range ancients {
for _, table := range ancient.sizes { for _, table := range ancient.sizes {
stats = append(stats, []string{ stats = append(stats, []string{
fmt.Sprintf("Ancient store (%s)", strings.Title(ancient.name)), fmt.Sprintf("Ancient store (%s)", caser.String(ancient.name)),
strings.Title(table.name), caser.String(table.name),
table.size.String(), table.size.String(),
fmt.Sprintf("%d", ancient.count), fmt.Sprintf("%d", ancient.count),
}) })

View file

@ -24,6 +24,8 @@ import (
"strings" "strings"
"github.com/ethereum/go-ethereum/version" "github.com/ethereum/go-ethereum/version"
"golang.org/x/text/cases"
"golang.org/x/text/language"
) )
const ourPath = "github.com/ethereum/go-ethereum" // Path to our module const ourPath = "github.com/ethereum/go-ethereum" // Path to our module
@ -73,7 +75,7 @@ func Archive(gitCommit string) string {
func ClientName(clientIdentifier string) string { func ClientName(clientIdentifier string) string {
git, _ := VCS() git, _ := VCS()
return fmt.Sprintf("%s/v%v/%v-%v/%v", return fmt.Sprintf("%s/v%v/%v-%v/%v",
strings.Title(clientIdentifier), cases.Title(language.English, cases.NoLower).String(clientIdentifier),
WithCommit(git.Commit, git.Date), WithCommit(git.Commit, git.Date),
runtime.GOOS, runtime.GOARCH, runtime.GOOS, runtime.GOARCH,
runtime.Version(), runtime.Version(),