From 5a3e22b886be951937dfb8151eabe6389398d19f Mon Sep 17 00:00:00 2001 From: Arpad Ryszka Date: Tue, 9 Dec 2025 23:22:54 +0100 Subject: [PATCH] remove limited utility escape function --- escape_test.go | 19 ------------------- lib.go | 9 +-------- replace.go | 9 --------- sequence.go | 4 ++-- 4 files changed, 3 insertions(+), 38 deletions(-) delete mode 100644 escape_test.go diff --git a/escape_test.go b/escape_test.go deleted file mode 100644 index 1ae14fe..0000000 --- a/escape_test.go +++ /dev/null @@ -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()) - } - }) -} diff --git a/lib.go b/lib.go index 5beb9e2..cded859 100644 --- a/lib.go +++ b/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() } diff --git a/replace.go b/replace.go index 7aa6c54..518f7b0 100644 --- a/replace.go +++ b/replace.go @@ -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...) -} diff --git a/sequence.go b/sequence.go index 8db3b3e..883b6f6 100644 --- a/sequence.go +++ b/sequence.go @@ -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...) } }