Skip to content

Instantly share code, notes, and snippets.

@siberex
Created July 18, 2025 21:22
Show Gist options
  • Save siberex/f4aca71768ba91e4b50ec552a784b7b8 to your computer and use it in GitHub Desktop.
Save siberex/f4aca71768ba91e4b50ec552a784b7b8 to your computer and use it in GitHub Desktop.
Test golang strings.ToUpper with UTF-8 strings
package main
import "fmt"
import "strings"
// go run str_to_upper.go
// Compare with C++: https://gist.github.com/siberex/7684eadde46d5e119b3bc4c6d5ab6212
func main() {
strTestUpper1 := "hello🌍world"
strTestUpper2 := "naïve café"
strTestUpper3 := "αβγδε" // Greek
strTestUpper4 := "привет мир" // Cyrillic
strTestUpper5 := "MixeD_CaSe1_ÄÖÜ #üñö!" // Mixed latin
strTestUpper6 := "Straße" // German with ß, should be capitalized as ẞ
strTestUpper7 := "æon+早安øӕ" // Mixed with ligatures U+00E6, U+04D5
fmt.Printf("Generic string: %q → %q\n", strTestUpper1, strings.ToUpper(strTestUpper1))
fmt.Printf("Latin diacritics: %q → %q\n", strTestUpper2, strings.ToUpper(strTestUpper2))
fmt.Printf("Greek: %q → %q\n", strTestUpper3, strings.ToUpper(strTestUpper3))
fmt.Printf("Cyrillic: %q → %q\n", strTestUpper4, strings.ToUpper(strTestUpper4))
fmt.Printf("Mixed: %q → %q\n", strTestUpper5, strings.ToUpper(strTestUpper5))
fmt.Printf("German: %q → %q\n", strTestUpper6, strings.ToUpper(strTestUpper6))
fmt.Printf("Ligatures mixed: %q → %q\n", strTestUpper7, strings.ToUpper(strTestUpper7))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment