diff options
Diffstat (limited to 'reencode_string.go')
-rw-r--r-- | reencode_string.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/reencode_string.go b/reencode_string.go new file mode 100644 index 0000000..ab148d6 --- /dev/null +++ b/reencode_string.go @@ -0,0 +1,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) +} |