8000 Moved stripEscape to utils by noborus · Pull Request #786 · noborus/ov · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Moved stripEscape to utils #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions oviewer/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,6 @@ func (substr regexpWord) String() string {
return substr.word
}

// stripRegexpES is a regular expression that excludes escape sequences.
var stripRegexpES = regexp.MustCompile("(\x1b\\[[\\d;*]*m)|.\b")

// stripEscapeSequenceString strips if it contains escape sequences.
func stripEscapeSequenceString(src string) string {
if !strings.ContainsAny(src, "\x1b\b") {
return src
}
// Remove EscapeSequence.
return stripRegexpES.ReplaceAllString(src, "")
}

// stripEscapeSequence strips if it contains escape sequences.
func stripEscapeSequenceBytes(src []byte) []byte {
if !bytes.ContainsAny(src, "\x1b\b") {
return src
}
// Remove EscapeSequence.
return stripRegexpES.ReplaceAll(src, []byte(""))
}

// NewSearcher returns the Searcher interface suitable for the search term.
func NewSearcher(word string, searchReg *regexp.Regexp, caseSensitive bool, regexpSearch bool) Searcher {
if regexpSearch && word != regexp.QuoteMeta(word) {
Expand Down
22 changes: 22 additions & 0 deletions oviewer/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package oviewer

import (
"bytes"
"io"
"log"
"regexp"
Expand Down Expand Up @@ -94,3 +95,24 @@ func writeLine(w io.Writer, line []byte) {
log.Printf("%s:%s", line, err)
}
}

// stripEscapeSequenceString removes escape sequences and backspaces from a string.
// It is used to identify and remove these sequences from strings or byte slices.
var stripRegexpES = regexp.MustCompile("(\x1b\\[[\\d;*]*m)|.\\x08")

func stripEscapeSequenceString(src string) string {
if !strings.ContainsAny(src, "\x1b\\x08") {
return src
}
// Remove EscapeSequence.
return stripRegexpES.ReplaceAllString(src, "")
}

// stripEscapeSequence strips if it contains escape sequences.
func stripEscapeSequenceBytes(src []byte) []byte {
if !bytes.ContainsAny(src, "\x1b\x08") {
return src
}
// Remove EscapeSequence.
return stripRegexpES.ReplaceAll(src, []byte(""))
}
Loading
0