aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ettle/strcase/unicode.go
blob: b75e25a512eb0c9cfd79f1fb7dd3d9103020dbd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package strcase

import "unicode"

// Unicode functions, optimized for the common case of ascii
// No performance lost by wrapping since these functions get inlined by the compiler

func isUpper(r rune) bool {
	return unicode.IsUpper(r)
}

func isLower(r rune) bool {
	return unicode.IsLower(r)
}

func isNumber(r rune) bool {
	if r >= '0' && r <= '9' {
		return true
	}
	return unicode.IsNumber(r)
}

func isSpace(r rune) bool {
	if r == ' ' || r == '\t' || r == '\n' || r == '\r' {
		return true
	} else if r < 128 {
		return false
	}
	return unicode.IsSpace(r)
}

func toUpper(r rune) rune {
	if r >= 'a' && r <= 'z' {
		return r - 32
	} else if r < 128 {
		return r
	}
	return unicode.ToUpper(r)
}

func toLower(r rune) rune {
	if r >= 'A' && r <= 'Z' {
		return r + 32
	} else if r < 128 {
		return r
	}
	return unicode.ToLower(r)
}