mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-17 05:54:59 +02:00
More work on porting the diff kitten
This commit is contained in:
@@ -4,6 +4,7 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
|
||||
"golang.org/x/exp/constraints"
|
||||
@@ -143,3 +144,15 @@ func Memset[T any](dest []T, pattern ...T) []T {
|
||||
}
|
||||
return dest
|
||||
}
|
||||
|
||||
var ControlCodesPat = (&Once[*regexp.Regexp]{Run: func() *regexp.Regexp {
|
||||
return regexp.MustCompile("[\x00-\x09\x0b-\x1f\x7f\x80-\x9f]")
|
||||
}}).Get
|
||||
|
||||
func SanitizeControlCodes(raw string, replace_with ...string) string {
|
||||
r := ""
|
||||
if len(replace_with) > 0 {
|
||||
r = replace_with[0]
|
||||
}
|
||||
return ControlCodesPat().ReplaceAllLiteralString(raw, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user