Skip to content

fix(package): [strutil] handle non-ASCII letters in case conversion - #413

Merged
duke-git merged 2 commits into
duke-git:rcfrom
lee3Q:fix/strutil-unicode-case
Nov 9, 2026
Merged

duke-git merged 2 commits into
duke-git:rcfrom
lee3Q:fix/strutil-unicode-case

Conversation

@lee3Q

@lee3Q lee3Q commented Nov 3, 2026

Copy link
Copy Markdown

CamelCase, UpperCamelCase, KebabCase, UpperKebabCase, SnakeCase and UpperSnakeCase only treated 'a'-'z' and 'A'-'Z' as cased letters, so other cased letters were not split or converted correctly. On the base commit:

  • SnakeCase("Привет Мир") returns "Привет Мир" (not lowercased, not split). KebabCase and UpperSnakeCase give the same unchanged string.
  • SnakeCase("Köln Straße") returns "k_ö_ln_stra_ß_e" and CamelCase("Köln Straße") returns "kÖLnStraßE".
  • SnakeCase("élanVital") returns "é_lan_vital".

The helpers isLower, isUpper, toLower and toUpper in strutil/string_internal.go now use unicode.IsLower, unicode.IsUpper, unicode.ToLower and unicode.ToUpper. Uncased letters such as CJK stay in the same group as before, and the ASCII results are unchanged.

After the change: SnakeCase("Привет Мир") is "привет_мир", UpperKebabCase gives "ПРИВЕТ-МИР", CamelCase("Köln Straße") is "kölnStraße".

Output changes for non-ASCII input, which is the point of this fix. Limits:

  • ß is not expanded to SS when upper-cased (Go's simple case mapping keeps ß).
  • Titlecase letters such as Dž are now classified by unicode.IsLower/IsUpper, so their splitting changes.
  • Final sigma, Turkish dotted/dotless i, combining marks and Unicode normalization are not handled.

Tests: I added two rows (Привет Мир, Köln Straße) to each of the six case-function tests. On go1.26.6 (Linux amd64), go test ./strutil, go vet ./strutil and gofmt -l strutil are clean, and the new rows fail on the base commit. go test ./... has two failures, TestTelnetConnected and ExampleIsTelnetConnected in netutil. They fail identically on the base commit in my environment, which has no external network access, and I did not investigate the cause. strutil also passes under GOARCH=386.

@duke-git
duke-git merged commit ed237c1 into duke-git:rc Nov 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants