gilo/editor/fn.go

51 lines
648 B
Go
Raw Normal View History

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()
}
2021-03-19 16:36:02 -04:00
func isAscii(char rune) bool {
ord := int(char)
return ord < 0x80
}
func IsCtrl(char rune) bool {
if !isAscii(char) {
return false
}
ord := int(char)
return ord == 0x7f || ord < 0x20
}
// Return the input code of a Ctrl-key chord.
func Ctrl(char rune) rune {
ord := int(char)
raw := ord & 0x1f
if !IsCtrl(rune(raw)) {
return 0
}
return rune(raw)
}