5 // Markdown escape map (ASCII)
6 // Inspired by https://github.com/golang-commonmark/markdown/blob/master/escape.go
7 type EscapeMap
[2]uint64
9 func (e
*EscapeMap
) Get(index
uint) bool {
10 if index
>= 128 { return false }
11 high
, low
:= index
/ 64, index
% 64
12 return e
[high
] & (1 << low
) != 0
15 func (e
*EscapeMap
) Set(index
uint, x
bool) {
16 if index
>= 128 { return }
17 high
, low
:= index
/ 64, index
% 64
19 e
[high
] = e
[high
] |
1 << low
21 e
[high
] = e
[high
] &^ 1 << low
25 func (e EscapeMap
) ToBuffer(src
string, dest
*bytes
.Buffer
) (err error
) {
26 for _
, char
:= range src
{
27 if char
< 0x80 && e
.Get(uint(char
)) {
28 // Write backslash + char
29 _
, err
= dest
.Write([]byte{0x5c, byte(char
)})
31 _
, err
= dest
.WriteRune(char
)
37 func (e EscapeMap
) ToString(src
string) (string, error
) {
38 var buffer bytes
.Buffer
39 err
:= e
.ToBuffer(src
, &buffer
)
43 return buffer
.String(), nil