diff options
Diffstat (limited to 'lib/lowmemjson/adapter_test.go')
-rw-r--r-- | lib/lowmemjson/adapter_test.go | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/lib/lowmemjson/adapter_test.go b/lib/lowmemjson/adapter_test.go deleted file mode 100644 index b1aec3e..0000000 --- a/lib/lowmemjson/adapter_test.go +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com> -// -// SPDX-License-Identifier: GPL-2.0-or-later - -package lowmemjson - -import ( - "bufio" - "bytes" - "encoding/json" - "io" -) - -func MarshalIndent(v any, prefix, indent string) ([]byte, error) { - var buf bytes.Buffer - formatter := &ReEncoder{ - Out: &buf, - Indent: indent, - prefix: prefix, - } - err := Encode(formatter, v) - return buf.Bytes(), err -} - -func Marshal(v any) ([]byte, error) { - var buf bytes.Buffer - formatter := &ReEncoder{ - Out: &buf, - Compact: true, - } - err := Encode(formatter, v) - return buf.Bytes(), err -} - -func HTMLEscape(dst *bytes.Buffer, src []byte) { - formatter := &ReEncoder{ - Out: dst, - } - _, _ = formatter.Write(src) -} - -func Compact(dst *bytes.Buffer, src []byte) error { - formatter := &ReEncoder{ - Out: dst, - Compact: true, - } - _, err := formatter.Write(src) - return err -} - -func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error { - formatter := &ReEncoder{ - Out: dst, - Indent: indent, - prefix: prefix, - } - _, err := formatter.Write(src) - return err -} - -func Valid(data []byte) bool { - formatter := &ReEncoder{ - Out: io.Discard, - Compact: true, - } - _, err := formatter.Write(data) - return err == nil -} - -func Unmarshal(data []byte, ptr any) error { - return Decode(bytes.NewReader(data), ptr) -} - -func init() { - forceBufio = true -} - -func (dec *Decoder) Buffered() io.Reader { - buf := dec.r.(*bufio.Reader) - dat, _ := buf.Peek(buf.Buffered()) - return bytes.NewReader(dat) -} - -//func (dec *Decoder) Token() (Token, error) - -///////////////////////////////////////////////////////////////////// - -type ( - Number = json.Number - Marshaler = json.Marshaler - RawMessage = json.RawMessage - - UnsupportedValueError = json.UnsupportedValueError - MarshalerError = json.MarshalerError - UnmarshalTypeError = json.UnmarshalTypeError -) - -const ( - startDetectingCyclesAfter = 1000 -) - -func isSpace(c byte) bool { - switch c { - case 0x0020, 0x000A, 0x000D, 0x0009: - return true - default: - return false - } -} - -type encodeState struct { - bytes.Buffer -} - -func (es *encodeState) string(str string, _ bool) { - encodeString(&es.Buffer, str) -} -func (es *encodeState) stringBytes(str []byte, _ bool) { - encodeString(&es.Buffer, str) -} |