gilo/editor/fn.go

46 lines
581 B
Go

package editor
import "strings"
func truncateString(s string, length int) string {
if length < 1 {
return ""
}
var buf strings.Builder
count := 0
for _, char := range s {
if count == length {
break
}
buf.WriteRune(char)
count++
}
return buf.String()
}
func isAscii(char rune) bool {
return char < 0x80
}
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 {
ch := char & 0x1f
if !isCtrl(ch) {
return 0
}
return ch
}