gilo/editor/fn.go
Timothy J. Warren ca49b44c73
Some checks failed
timw4mail/gilo/pipeline/head There was a failure building this commit
More tests
2021-03-30 20:22:11 -04:00

54 lines
741 B
Go

// Helper functions
package editor
import "strings"
// Truncate a string to a length
func truncateString(s string, length int) string {
if length < 1 {
return ""
}
if len(s) < length {
return s
}
var buf strings.Builder
count := 0
for _, char := range s {
if count == length {
break
}
buf.WriteRune(char)
count++
}
return buf.String()
}
// Is this an ASCII character?
func isAscii(char rune) bool {
return char < 0x80
}
// Is this an ASCII ctrl character?
func isCtrl(char rune) bool {
if !isAscii(char) {
return false
}
return char == 0x7f || char < 0x20
}
// Return the input code of a Ctrl-key chord.
func ctrl(char rune) rune {
if !isAscii(char) {
return 0
}
ch := char & 0x1f
return ch
}