Skip to content

Commit 977d407

Browse files
committed
stripansi: compile regex ondemand
1 parent 13617b4 commit 977d407

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)