You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package nbyte
|
|
|
|
// IsLower checks if a character is lower case ('a' to 'z')
|
|
func IsLower(c byte) bool {
|
|
return 'a' <= c && c <= 'z'
|
|
}
|
|
|
|
// ToLower converts a character 'A' to 'Z' to its lower case
|
|
func ToLower(c byte) byte {
|
|
if c >= 'A' && c <= 'Z' {
|
|
return c + 32
|
|
}
|
|
return c
|
|
}
|
|
|
|
// ToLowerAll converts a character 'A' to 'Z' to its lower case
|
|
func ToLowerAll(bs []byte) []byte {
|
|
for i := range bs {
|
|
bs[i] = ToLower(bs[i])
|
|
}
|
|
return bs
|
|
}
|
|
|
|
// IsUpper checks if a character is upper case ('A' to 'Z')
|
|
func IsUpper(c byte) bool {
|
|
return 'A' <= c && c <= 'Z'
|
|
}
|
|
|
|
// ToUpper converts a character 'a' to 'z' to its upper case
|
|
func ToUpper(r byte) byte {
|
|
if r >= 'a' && r <= 'z' {
|
|
return r - 32
|
|
}
|
|
return r
|
|
}
|
|
|
|
// ToUpperAll converts a character 'a' to 'z' to its upper case
|
|
func ToUpperAll(rs []byte) []byte {
|
|
for i := range rs {
|
|
rs[i] = ToUpper(rs[i])
|
|
}
|
|
return rs
|
|
}
|
|
|
|
// IsDigit checks if a character is digit ('0' to '9')
|
|
func IsDigit(r byte) bool {
|
|
return r >= '0' && r <= '9'
|
|
}
|
|
|
|
// IsAlphabet byte
|
|
func IsAlphabet(char byte) bool {
|
|
// A 65 -> Z 90
|
|
if char >= 'A' && char <= 'Z' {
|
|
return true
|
|
}
|
|
|
|
// a 97 -> z 122
|
|
if char >= 'a' && char <= 'z' {
|
|
return true
|
|
}
|
|
return false
|
|
}
|