×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang unicode.SimpleFold() Function with Examples

Golang | unicode.SimpleFold() Function: Here, we are going to learn about the SimpleFold() function of the unicode package with its usages, syntax, and examples.
Submitted by IncludeHelp, on September 18, 2021

unicode.SimpleFold()

The SimpleFold() function is an inbuilt function of the unicode package which is used to iterate over Unicode code points equivalent under the Unicode-defined simple case folding. Among the code points equivalent to rune (including rune itself), SimpleFold() function returns the smallest rune > r if one exists, or else the smallest rune >= 0. If r is not a valid Unicode code point, SimpleFold(r) returns r.

It accepts one parameter (r rune) and returns the smallest rune > r if one exists, or else the smallest rune >= 0. If r is not a valid Unicode code point, SimpleFold(r) returns r.

Syntax

func SimpleFold(r rune) rune

Parameters

  • r : Rune type value.

Return Value

The return type of the unicode.SimpleFold() function is a rune, it returns the smallest rune > r if one exists, or else the smallest rune >= 0. If r is not a valid Unicode code point, SimpleFold(r) returns r.

Example 1

// Golang program to demonstrate the
// example of unicode.SimpleFold() Function

package main

import (
	"fmt"
	"unicode"
)

func main() {
	fmt.Printf("unicode.SimpleFold('A'): %#U\n",
		unicode.SimpleFold('A'))
	fmt.Printf("unicode.SimpleFold('A'): %#U\n",
		unicode.SimpleFold('a'))
	fmt.Printf("unicode.SimpleFold('Ä'): %#U\n",
		unicode.SimpleFold('Ä'))
	fmt.Printf("unicode.SimpleFold('Æ'): %#U\n",
		unicode.SimpleFold('Æ'))
	fmt.Printf("unicode.SimpleFold('ῌ'): %#U\n",
		unicode.SimpleFold('ῌ'))
	fmt.Printf("unicode.SimpleFold('G'): %#U\n",
		unicode.SimpleFold('G'))
}

Output:

unicode.SimpleFold('A'): U+0061 'a'
unicode.SimpleFold('A'): U+0041 'A'
unicode.SimpleFold('Ä'): U+00E4 'ä'
unicode.SimpleFold('Æ'): U+00E6 'æ'
unicode.SimpleFold('ῌ'): U+1FC3 'ῃ'
unicode.SimpleFold('G'): U+0067 'g'

Example 2

// Golang program to demonstrate the
// example of unicode.To() Function

package main

import (
	"fmt"
	"unicode"
)

func main() {
	var r rune

	r = 'Q'
	fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, r))
	fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, r))
	fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, r))
	fmt.Println()

	r = 'q'
	fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, r))
	fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, r))
	fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, r))
	fmt.Println()

	r = 'Ä'
	fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, r))
	fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, r))
	fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, r))
}

Output:

U+0051 'Q'
U+0071 'q'
U+0051 'Q'

U+0051 'Q'
U+0071 'q'
U+0051 'Q'

U+00C4 'Ä'
U+00E4 'ä'
U+00C4 'Ä'

Golang unicode Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.