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())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
7
lib.go
7
lib.go
@ -77,13 +77,6 @@ func Replace(a ...string) Editor {
|
|||||||
return replace(a...)
|
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.
|
// Indent applies indentation to multi-line text. Whitespaces are preserved.
|
||||||
func Indent(first, rest string) Editor {
|
func Indent(first, rest string) Editor {
|
||||||
return indent([]rune(first), []rune(rest))
|
return indent([]rune(first), []rune(rest))
|
||||||
|
|||||||
@ -45,12 +45,3 @@ func replace(a ...string) Editor {
|
|||||||
|
|
||||||
return sequence(e...)
|
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...)
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user