Code Examples
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Printf("%t\n", unicode.IsDigit('৩'))
fmt.Printf("%t\n", unicode.IsDigit('A'))
}
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Printf("%t\n", unicode.IsLetter('A'))
fmt.Printf("%t\n", unicode.IsLetter('7'))
}
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Printf("%t\n", unicode.IsLower('a'))
fmt.Printf("%t\n", unicode.IsLower('A'))
}
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Printf("%t\n", unicode.IsNumber('Ⅷ'))
fmt.Printf("%t\n", unicode.IsNumber('A'))
}
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Printf("%t\n", unicode.IsSpace(' '))
fmt.Printf("%t\n", unicode.IsSpace('\n'))
fmt.Printf("%t\n", unicode.IsSpace('\t'))
fmt.Printf("%t\n", unicode.IsSpace('a'))
}
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Printf("%t\n", unicode.IsTitle('Dž'))
fmt.Printf("%t\n", unicode.IsTitle('a'))
}
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Printf("%t\n", unicode.IsUpper('A'))
fmt.Printf("%t\n", unicode.IsUpper('a'))
}
package main
import (
"fmt"
"unicode"
)
func main() {
fmt.Printf("%#U\n", unicode.SimpleFold('A')) // 'a'
fmt.Printf("%#U\n", unicode.SimpleFold('a')) // 'A'
fmt.Printf("%#U\n", unicode.SimpleFold('K')) // 'k'
fmt.Printf("%#U\n", unicode.SimpleFold('k')) // '\u212A' (Kelvin symbol, K)
fmt.Printf("%#U\n", unicode.SimpleFold('\u212A')) // 'K'
fmt.Printf("%#U\n", unicode.SimpleFold('1')) // '1'
}
package main
import (
"fmt"
"unicode"
)
func main() {
t := unicode.TurkishCase
const lci = 'i'
fmt.Printf("%#U\n", t.ToLower(lci))
fmt.Printf("%#U\n", t.ToTitle(lci))
fmt.Printf("%#U\n", t.ToUpper(lci))
const uci = 'İ'
fmt.Printf("%#U\n", t.ToLower(uci))
fmt.Printf("%#U\n", t.ToTitle(uci))
fmt.Printf("%#U\n", t.ToUpper(uci))
}
package main
import (
"fmt"
"unicode"
)
func main() {
const lcG = 'g'
fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, lcG))
fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, lcG))
fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, lcG))
const ucG = 'G'
fmt.Printf("%#U\n", unicode.To(unicode.UpperCase, ucG))
fmt.Printf("%#U\n", unicode.To(unicode.LowerCase, ucG))
fmt.Printf("%#U\n", unicode.To(unicode.TitleCase, ucG))
}
package main
import (
"fmt"
"unicode"
)
func main() {
const ucG = 'G'
fmt.Printf("%#U\n", unicode.ToLower(ucG))
}
package main
import (
"fmt"
"unicode"
)
func main() {
const ucG = 'g'
fmt.Printf("%#U\n", unicode.ToTitle(ucG))
}
package main
import (
"fmt"
"unicode"
)
func main() {
const ucG = 'g'
fmt.Printf("%#U\n", unicode.ToUpper(ucG))
}
package main
import (
"fmt"
"unicode"
)
func main() {
// constant with mixed type runes
const mixed = "\b5Ὂg̀9! ℃ᾭG"
for _, c := range mixed {
fmt.Printf("For %q:\n", c)
if unicode.IsControl(c) {
fmt.Println("\tis control rune")
}
if unicode.IsDigit(c) {
fmt.Println("\tis digit rune")
}
if unicode.IsGraphic(c) {
fmt.Println("\tis graphic rune")
}
if unicode.IsLetter(c) {
fmt.Println("\tis letter rune")
}
if unicode.IsLower(c) {
fmt.Println("\tis lower case rune")
}
if unicode.IsMark(c) {
fmt.Println("\tis mark rune")
}
if unicode.IsNumber(c) {
fmt.Println("\tis number rune")
}
if unicode.IsPrint(c) {
fmt.Println("\tis printable rune")
}
if !unicode.IsPrint(c) {
fmt.Println("\tis not printable rune")
}
if unicode.IsPunct(c) {
fmt.Println("\tis punct rune")
}
if unicode.IsSpace(c) {
fmt.Println("\tis space rune")
}
if unicode.IsSymbol(c) {
fmt.Println("\tis symbol rune")
}
if unicode.IsTitle(c) {
fmt.Println("\tis title case rune")
}
if unicode.IsUpper(c) {
fmt.Println("\tis upper case rune")
}
}
}
Package-Level Type Names (total 7, in which 5 are exported)
/* sort exporteds by: | */
CaseRange represents a range of Unicode code points for simple (one
code point to one code point) case conversion.
The range runs from Lo to Hi inclusive, with a fixed stride of 1. Deltas
are the number to add to the code point to reach the code point for a
different case for that character. They may be negative. If zero, it
means the character is in the corresponding case. There is a special
case representing sequences of alternating corresponding Upper and Lower
pairs. It appears with a fixed Delta of
{UpperLower, UpperLower, UpperLower}
The constant UpperLower has an otherwise impossible delta value.DeltadHiuint32Louint32
func lookupCaseRange(r rune, caseRange []CaseRange) *CaseRange
func convertCase(_case int, r rune, cr *CaseRange) rune
func lookupCaseRange(r rune, caseRange []CaseRange) *CaseRange
func to(_case int, r rune, caseRange []CaseRange) (mappedRune rune, foundMapping bool)
Range16 represents of a range of 16-bit Unicode code points. The range runs from Lo to Hi
inclusive and has the specified stride.Hiuint16Louint16Strideuint16
func is16(ranges []Range16, r uint16) bool
Range32 represents of a range of Unicode code points and is used when one or
more of the values will not fit in 16 bits. The range runs from Lo to Hi
inclusive and has the specified stride. Lo and Hi must always be >= 1<<16.Hiuint32Louint32Strideuint32
func is32(ranges []Range32, r uint32) bool
SpecialCase represents language-specific case mappings such as Turkish.
Methods of SpecialCase customize (by overriding) the standard mappings. ToLower maps the rune to lower case giving priority to the special mapping. ToTitle maps the rune to title case giving priority to the special mapping. ToUpper maps the rune to upper case giving priority to the special mapping.
func bytes.ToLowerSpecial(c SpecialCase, s []byte) []byte
func bytes.ToTitleSpecial(c SpecialCase, s []byte) []byte
func bytes.ToUpperSpecial(c SpecialCase, s []byte) []byte
func strings.ToLowerSpecial(c SpecialCase, s string) string
func strings.ToTitleSpecial(c SpecialCase, s string) string
func strings.ToUpperSpecial(c SpecialCase, s string) string
var AzeriCase
var TurkishCase
var _TurkishCase
caseOrbit is defined in tables.go as []foldPair. Right now all the
entries fit in uint16, so use uint16. If that changes, compilation
will fail (the constants in the composite literal will not fit in uint16)
and the types here can change to uint32.Fromuint16Touint16
Package-Level Functions (total 27, in which 21 are exported)
In reports whether the rune is a member of one of the ranges.
Is reports whether the rune is in the specified table of ranges.
IsControl reports whether the rune is a control character.
The [C] ([Other]) Unicode category includes more code points
such as surrogates; use [Is](C, r) to test for them.
IsDigit reports whether the rune is a decimal digit.
IsGraphic reports whether the rune is defined as a Graphic by Unicode.
Such characters include letters, marks, numbers, punctuation, symbols, and
spaces, from categories [L], [M], [N], [P], [S], [Zs].
IsLetter reports whether the rune is a letter (category [L]).
IsLower reports whether the rune is a lower case letter.
IsMark reports whether the rune is a mark character (category [M]).
IsNumber reports whether the rune is a number (category [N]).
IsOneOf reports whether the rune is a member of one of the ranges.
The function "In" provides a nicer signature and should be used in preference to IsOneOf.
IsPrint reports whether the rune is defined as printable by Go. Such
characters include letters, marks, numbers, punctuation, symbols, and the
ASCII space character, from categories [L], [M], [N], [P], [S] and the ASCII space
character. This categorization is the same as [IsGraphic] except that the
only spacing character is ASCII space, U+0020.
IsPunct reports whether the rune is a Unicode punctuation character
(category [P]).
IsSpace reports whether the rune is a space character as defined
by Unicode's White Space property; in the Latin-1 space
this is
'\t', '\n', '\v', '\f', '\r', ' ', U+0085 (NEL), U+00A0 (NBSP).
Other definitions of spacing characters are set by category
Z and property [Pattern_White_Space].
IsSymbol reports whether the rune is a symbolic character.
IsTitle reports whether the rune is a title case letter.
IsUpper reports whether the rune is an upper case letter.
SimpleFold iterates over Unicode code points equivalent under
the Unicode-defined simple case folding. Among the code points
equivalent to rune (including rune itself), SimpleFold 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.
For example:
SimpleFold('A') = 'a'
SimpleFold('a') = 'A'
SimpleFold('K') = 'k'
SimpleFold('k') = '\u212A' (Kelvin symbol, K)
SimpleFold('\u212A') = 'K'
SimpleFold('1') = '1'
SimpleFold(-2) = -2
To maps the rune to the specified case: [UpperCase], [LowerCase], or [TitleCase].
ToLower maps the rune to lower case.
ToTitle maps the rune to title case.
ToUpper maps the rune to upper case.
convertCase converts r to _case using CaseRange cr.
is16 reports whether r is in the sorted slice of 16-bit ranges.
is32 reports whether r is in the sorted slice of 32-bit ranges.
CaseRanges is the table describing case mappings for all letters with
non-self mappings.
Categories is the set of Unicode category tables.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
FoldCategory maps a category name to a table of
code points outside the category that are equivalent under
simple case folding to code points inside the category.
If there is no entry for a category name, there are no such points.
FoldScript maps a script name to a table of
code points outside the script that are equivalent under
simple case folding to code points inside the script.
If there is no entry for a script name, there are no such points.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
GraphicRanges defines the set of graphic characters according to Unicode.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
These variables have type *RangeTable.
PrintRanges defines the set of printable characters according to Go.
ASCII space, U+0020, is handled separately.