Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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