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
+20.7k Golang : Saving private and public key to files
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+8.8k Golang : Get final balance from bit coin address example
+17.5k Golang : Linked list example
+9.4k Golang : Terminate-stay-resident or daemonize your program?
+5.2k PHP : See installed compiled-in-modules
+8.1k Golang : Check from web if Go application is running or not
+9k Golang : Get SPF and DMARC from email headers to fight spam
+21.2k Golang : How to force compile or remove object files first before rebuild?
+13.9k Golang : How to check if a file is hidden?
+13.6k Golang : Qt progress dialog example