Skip to content

Commit 13c1a37

Browse files
authored
Merge pull request #1193 from carapace-sh/stripansi-ondemand
stripansi: compile regex ondemand
2 parents 13617b4 + 977d407 commit 13c1a37

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

third_party/github.com/acarl005/stripansi/stripansi.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import (
66

77
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
88

9-
var re = regexp.MustCompile(ansi)
9+
var re *regexp.Regexp
1010

1111
func Strip(str string) string {
12+
if re == nil {
13+
re = regexp.MustCompile(ansi)
14+
}
1215
return re.ReplaceAllString(str, "")
1316
}

0 commit comments

Comments
 (0)