Golang bytes.ToLowerSpecial() function example

package bytes

ToLowerSpecial returns a copy of the byte input slice with all Unicode letters mapped to their lower case, giving priority to the special casing rules. (See http://golang.org/pkg/unicode/#SpecialCase )

Golang bytes.ToLowerSpecial() function usage example

 package main

 import (
 "fmt"
 "bytes"
 "unicode"
 )

 func main() {
 str := []byte("ŞĞÜÖIİ")

 tolower := bytes.ToLowerSpecial(unicode.AzeriCase, str)

 fmt.Println(string(str))

 fmt.Println(string(tolower))

 }

Output :

ŞĞÜÖIİ

şğüöıi

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/unicode/#SpecialCase

http://golang.org/pkg/bytes/#ToLowerSpecial

https://gist.github.com/roktas/8514975

Advertisement