m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-17 07:43:39 -05:00

ansi: speed up escape sequence parsing (#2927)

This commit is contained in:
Charlie Vieth
2022-08-25 01:02:08 -04:00
committed by GitHub
parent 9d041aa582
commit 209d5e8e90

View File

@@ -107,19 +107,27 @@ func matchControlSequence(s string) int {
// ^ match starting here // ^ match starting here
// //
i := 2 // prefix matched in nextAnsiEscapeSequence() i := 2 // prefix matched in nextAnsiEscapeSequence()
for ; i < len(s) && (isNumeric(s[i]) || s[i] == ';' || s[i] == ':' || s[i] == '?'); i++ { for ; i < len(s); i++ {
}
if i < len(s) {
c := s[i] c := s[i]
if 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '@' { switch c {
return i + 1 case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';', ':', '?':
// ok
default:
if 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '@' {
return i + 1
}
return -1
} }
} }
return -1 return -1
} }
func isCtrlSeqStart(c uint8) bool { func isCtrlSeqStart(c uint8) bool {
return c == '\\' || c == '[' || c == '(' || c == ')' switch c {
case '\\', '[', '(', ')':
return true
}
return false
} }
// nextAnsiEscapeSequence returns the ANSI escape sequence and is equivalent to // nextAnsiEscapeSequence returns the ANSI escape sequence and is equivalent to