60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package char
|
|
|
|
import (
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// !Terminal Input Escape Code Sequences
|
|
// ----------------------------------------------------------------------------
|
|
|
|
const (
|
|
Backspace = '\x7f'
|
|
Backslash = '\\'
|
|
Esc = '\x1b'
|
|
Enter = '\r'
|
|
SingleQuote = '\''
|
|
DoubleQuote = '"'
|
|
)
|
|
|
|
// IsAscii Is this an ASCII character?
|
|
func IsAscii(char rune) bool {
|
|
return char <= unicode.MaxASCII
|
|
}
|
|
|
|
// IsCtrl Is this an ASCII ctrl character?
|
|
func IsCtrl(char rune) bool {
|
|
if !IsAscii(char) {
|
|
return false
|
|
}
|
|
|
|
return char == 0x7f || char < 0x20
|
|
}
|
|
|
|
// Ctrl Return the input code of a Ctrl-key chord.
|
|
func Ctrl(char rune) rune {
|
|
if !IsAscii(char) {
|
|
return 0
|
|
}
|
|
|
|
ch := char & 0x1f
|
|
|
|
return ch
|
|
}
|
|
|
|
// IsSeparator Is the character a general token separator type?
|
|
func IsSeparator(char rune) bool {
|
|
return unicode.IsSpace(char) || strings.ContainsRune(",.()+-/*=~%<>[];", char)
|
|
}
|
|
|
|
// IsDigit is a simple wrapper around built-in unicode.IsDigit
|
|
func IsDigit(char rune) bool {
|
|
return unicode.IsDigit(char)
|
|
}
|
|
|
|
// IsNumeric checks whether the character is a digit, or a numeric separator
|
|
func IsNumeric(char rune) bool {
|
|
return IsDigit(char) || char == '.'
|
|
}
|