Documentation ¶
Overview ¶
Package ascii provide a library for working with ASCII characters.
Index ¶
Examples ¶
Constants ¶
const ( // Letters contains list of lower and upper case characters in ASCII. Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // LettersNumber contains list of lower and upper case characters in // ASCII along with numbers. LettersNumber = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890" // HexaLETTERS contains list of hexadecimal characters in upper cases. HexaLETTERS = "0123456789ABCDEF" // HexaLetters contains list of hexadecimal characters in lower and // upper cases. HexaLetters = "0123456789abcedfABCDEF" // Hexaletters contains list of hexadecimal characters in lower cases. Hexaletters = "0123456789abcedf" )
Variables ¶
var ( // Spaces contains list of white spaces in ASCII. Spaces = []byte{'\t', '\n', '\v', '\f', '\r', ' '} )
Functions ¶
func IsAlnum ¶
IsAlnum will return true if byte is ASCII alphanumeric character, otherwise it will return false.
Example ¶
chars := []byte("0aZ!.") for _, c := range chars { fmt.Printf("%c: %t\n", c, IsAlnum(c)) }
Output: 0: true a: true Z: true !: false .: false
func IsAlpha ¶
IsAlpha will return true if byte is ASCII alphabet character, otherwise it will return false.
Example ¶
chars := []byte("0aZ!.") for _, c := range chars { fmt.Printf("%c: %t\n", c, IsAlpha(c)) }
Output: 0: false a: true Z: true !: false .: false
func IsDigit ¶
IsDigit will return true if byte is ASCII digit, otherwise it will return false.
Example ¶
chars := []byte("0aZ!.") for _, c := range chars { fmt.Printf("%c: %t\n", c, IsDigit(c)) }
Output: 0: true a: false Z: false !: false .: false
func IsDigits ¶
IsDigits will return true if all bytes are ASCII digit, otherwise it will return false.
Example ¶
inputs := []string{ "012", "012 ", " 012 ", "0.", "0.1", "0.1a", } for _, s := range inputs { fmt.Printf("%s: %t\n", s, IsDigits([]byte(s))) }
Output: 012: true 012 : false 012 : false 0.: false 0.1: false 0.1a: false
func IsHex ¶
IsHex will return true if byte is hexadecimal number, otherwise it will return false.
Example ¶
chars := []byte("09afgAFG") for _, c := range chars { fmt.Printf("%c: %t\n", c, IsHex(c)) }
Output: 0: true 9: true a: true f: true g: false A: true F: true G: false
func IsSpace ¶
IsSpace will return true if byte is ASCII white spaces character, otherwise it will return false.
Example ¶
fmt.Printf("\\t: %t\n", IsSpace('\t')) fmt.Printf("\\n: %t\n", IsSpace('\n')) fmt.Printf("\\v: %t\n", IsSpace('\v')) fmt.Printf("\\f: %t\n", IsSpace('\f')) fmt.Printf("\\r: %t\n", IsSpace('\r')) fmt.Printf(" : %t\n", IsSpace(' ')) fmt.Printf(" : %t\n", IsSpace(' ')) fmt.Printf("\\: %t\n", IsSpace('\\')) fmt.Printf("0: %t\n", IsSpace('0'))
Output: \t: true \n: true \v: true \f: true \r: true : true : true \: false 0: false
func Random ¶
Random generate random sequence of value from source with fixed length.
This function assume that random generator has been seeded.
Example ¶
fmt.Printf("Random 5 Letters: %s\n", Random([]byte(Letters), 5)) fmt.Printf("Random 5 LettersNumber: %s\n", Random([]byte(LettersNumber), 5)) fmt.Printf("Random 5 HexaLETTERS: %s\n", Random([]byte(HexaLETTERS), 5)) fmt.Printf("Random 5 HexaLetters: %s\n", Random([]byte(HexaLetters), 5)) fmt.Printf("Random 5 Hexaletters: %s\n", Random([]byte(Hexaletters), 5)) fmt.Printf("Random 5 binary: %s\n", Random([]byte("01"), 5))
Output: Random 5 Letters: XVlBz Random 5 LettersNumber: 80Aep Random 5 HexaLETTERS: 6F218 Random 5 HexaLetters: 675DA Random 5 Hexaletters: fa82f Random 5 binary: 11001
func ToLower ¶
ToLower convert slice of ASCII characters to lower cases, in places, which means it will return the same slice instead of creating new one.
Example ¶
in := []byte("@ABCDEFGhijklmnoPQRSTUVWxyz{12345678") fmt.Printf("%s\n", ToLower(in))
Output: @abcdefghijklmnopqrstuvwxyz{12345678
Types ¶
This section is empty.