Golang bytes.ToTitleSpecial() function example
package bytes
ToTitleSpecial returns a copy of the input byte slice with all Unicode letters mapped to their title case, giving priority to the special casing rules.
Golang bytes.ToTitleSpecial() function usage example
package main
import (
"fmt"
"bytes"
"unicode"
)
func main() {
str := []byte("funky i ŞĞÜÖIİi title")
toupper := bytes.ToUpperSpecial(unicode.AzeriCase, str)
tolower := bytes.ToLowerSpecial(unicode.AzeriCase, str)
totitle := bytes.ToTitleSpecial(unicode.AzeriCase, str)
fmt.Println("Original : " + string(str))
fmt.Println("ToUpper : " + string(toupper))
fmt.Println("ToLower : " + string(tolower))
fmt.Println("ToTitle : " + string(totitle))
}
Output :
Original : funky i ŞĞÜÖIİi title
ToUpper : FUNKY İ ŞĞÜÖIİİ TİTLE
ToLower : funky i şğüöıii title
ToTitle : FUNKY İ ŞĞÜÖIİİ TİTLE
To detect special case from the environment, try this function
var specialCase unicode.SpecialCase
func init() {
for _, env := range []string{"LC_ALL", "LC_CTYPE", "LANG"} {
locale := os.Getenv(env)
if strings.HasPrefix("tr_", locale) {
specialCase = unicode.TurkishCase
break
}
if strings.HasPrefix("az_", locale) {
specialCase = unicode.AzeriCase
break
}
}
}
Reference :
http://golang.org/pkg/bytes/#ToTitleSpecial
Advertisement
Something interesting
Tutorials
+33.7k Golang : All update packages with go get command
+12k Golang : Convert a rune to unicode style string \u
+6.3k Golang : How to get capacity of a slice or array?
+7k Golang : Gargish-English language translator
+13.5k Golang : How to get year, month and day?
+18.4k Golang : Logging with logrus
+17.5k Golang : Clone with pointer and modify value
+12.3k Golang : 2 dimensional array example
+22.1k Golang : Join arrays or slices example
+7k Web : How to see your website from different countries?
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name