remove limited utility escape function
This commit is contained in:
parent
c75c396578
commit
5a3e22b886
@ -1,19 +0,0 @@
|
||||
package textedit_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"code.squareroundforest.org/arpio/textedit"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEscape(t *testing.T) {
|
||||
t.Run("basic", func(t *testing.T) {
|
||||
var b bytes.Buffer
|
||||
w := textedit.New(&b, textedit.Escape('\\', '\n', '\t', '"'))
|
||||
w.Write([]byte("foo\nbar\t\"baz\""))
|
||||
w.Flush()
|
||||
if b.String() != "foo\\\nbar\\\t\\\"baz\\\"" {
|
||||
t.Fatal(b.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
9
lib.go
9
lib.go
@ -77,13 +77,6 @@ func Replace(a ...string) Editor {
|
||||
return replace(a...)
|
||||
}
|
||||
|
||||
// Escape can be used for basic escaping, where the found characters from the chars argument are replaced with
|
||||
// the same character prefixed by the escape char in the esc argument. The escape char will be escaped
|
||||
// automatically.
|
||||
func Escape(esc rune, chars ...rune) Editor {
|
||||
return escape(esc, chars...)
|
||||
}
|
||||
|
||||
// Indent applies indentation to multi-line text. Whitespaces are preserved.
|
||||
func Indent(first, rest string) Editor {
|
||||
return indent([]rune(first), []rune(rest))
|
||||
@ -145,7 +138,7 @@ func (w *Writer) flush() error {
|
||||
|
||||
r := w.editor.ReleaseState(w.state)
|
||||
w.state = nil
|
||||
if initializer, ok := w.editor.(interface{initialize() any}); ok {
|
||||
if initializer, ok := w.editor.(interface{ initialize() any }); ok {
|
||||
w.state = initializer.initialize()
|
||||
}
|
||||
|
||||
|
||||
@ -45,12 +45,3 @@ func replace(a ...string) Editor {
|
||||
|
||||
return sequence(e...)
|
||||
}
|
||||
|
||||
func escape(esc rune, chars ...rune) Editor {
|
||||
r := []string{string(esc), string([]rune{esc, esc})}
|
||||
for _, c := range chars {
|
||||
r = append(r, string(c), string([]rune{esc, c}))
|
||||
}
|
||||
|
||||
return replace(r...)
|
||||
}
|
||||
|
||||
@ -27,9 +27,9 @@ func sequenceRelease(e []Editor) func([]any) []rune {
|
||||
for i, ei := range e {
|
||||
r := ei.ReleaseState(s[i])
|
||||
for _, ri := range r {
|
||||
rri, ssi := sequenceEdit(e[i+1:])(ri, s[i + 1:])
|
||||
rri, ssi := sequenceEdit(e[i+1:])(ri, s[i+1:])
|
||||
rr = append(rr, rri...)
|
||||
s = append(s[:i + 1], ssi...)
|
||||
s = append(s[:i+1], ssi...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user