Menu Close

Go – SpecialCase type in unicode package in go

Here, We will learn about SpecialCase type in unicode package in go. SpecialCase in unicode package shows language-specific case mappings such as Turkish in go golang.

Type prototype

type SpecialCase []CaseRange

Functions

1: func (SpecialCase) ToLower:

Function prototype:

func (special SpecialCase) ToLower(r rune) rune

Definition:

ToLower method of SpecialCase type maps 
the rune to lower case giving priority to
the special mapping.

2: func (SpecialCase) ToTitle:

Function prototype:

func (special SpecialCase) ToTitle(r rune) rune

Definition:

ToTitle method of SpecialCase type maps 
the rune to title case giving priority
to the special mapping.

3: func (SpecialCase) ToUpper:

Function prototype:

func (special SpecialCase) ToUpper(r rune) rune

Definition:

ToUpper method of SpecialCase type maps 
the rune to upper case giving priority
to the special mapping.

Example:

var AzeriCase SpecialCase = _TurkishCase

var TurkishCase SpecialCase = _TurkishCase

Example with code:

package main

import (
  "fmt"
  "unicode"
)

func main() {
  x := unicode.TurkishCase

  const l_ci = 'a'

  fmt.Printf("%#U\n", x.ToLower(l_ci))
  fmt.Printf("%#U\n", x.ToTitle(l_ci))
  fmt.Printf("%#U\n", x.ToUpper(l_ci))

  const u_ci = 'A'
  fmt.Printf("%#U\n", x.ToLower(u_ci))
  fmt.Printf("%#U\n", x.ToTitle(u_ci))
  fmt.Printf("%#U\n", x.ToUpper(u_ci))

}

Output:

U+0061 'a' 
U+0041 'A'
U+0041 'A'
U+0061 'a'
U+0041 'A'
U+0041 'A'

To learn more about golang, Please refer given below link:

https://www.techieindoor.com/go-lang-tutorial/

References:

https://golang.org/doc/
https://golang.org/pkg/
Posted in golang, unicode

Leave a Reply

Your email address will not be published. Required fields are marked *