blob: ab148d6d7b75071d466834c3f4fa971cd7b7cb68 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
package lowmemjson
import (
"git.lukeshu.com/go/lowmemjson/internal/jsonparse"
)
type reEncodeString struct {
out reEncoderModule
// BackslashEscape returns whether a given character in a
// string should be backslash-escaped. The bool argument is
// whether it was \u-escaped in the input. This does not
// affect characters that must or must-not be escaped to be
// valid JSON.
BackslashEscape BackslashEscaper
}
var _ reEncoderModule = (*reEncodeString)(nil)
func (enc *reEncodeString) PopWriteBarrier() {
enc.out.PopWriteBarrier()
}
func (enc *reEncodeString) HandleRune(c rune, t jsonparse.RuneType, escape BackslashEscapeMode, stackSize int) error {
if t == jsonparse.RuneTypeStringChar {
escape = enc.BackslashEscape(c, escape)
}
return enc.out.HandleRune(c, t, escape, stackSize)
}
|