Debian Codegraph @

pkg/internal/third_party/go-json-experiment/json/jsontext/quote.go

raw
1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package jsontext
6
7 import (
8 "k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json/internal/jsonflags"
9 "k8s.io/kube-openapi/pkg/internal/third_party/go-json-experiment/json/internal/jsonwire"
10 )
11
12 // AppendQuote appends a double-quoted JSON string literal representing src
13 // to dst and returns the extended buffer.
14 // It uses the minimal string representation per RFC 8785, section 3.2.2.2.
15 // Invalid UTF-8 bytes are replaced with the Unicode replacement character
16 // and an error is returned at the end indicating the presence of invalid UTF-8.
17 // The dst must not overlap with the src.
18 func AppendQuote[Bytes ~[]byte | ~string](dst []byte, src Bytes) ([]byte, error) {
19 dst, err := jsonwire.AppendQuote(dst, src, &jsonflags.Flags{})
20 if err != nil {
21 err = &SyntacticError{Err: err}
22 }
23 return dst, err
24 }
25
26 // AppendUnquote appends the decoded interpretation of src as a
27 // double-quoted JSON string literal to dst and returns the extended buffer.
28 // The input src must be a JSON string without any surrounding whitespace.
29 // Invalid UTF-8 bytes are replaced with the Unicode replacement character
30 // and an error is returned at the end indicating the presence of invalid UTF-8.
31 // Any trailing bytes after the JSON string literal results in an error.
32 // The dst must not overlap with the src.
33 func AppendUnquote[Bytes ~[]byte | ~string](dst []byte, src Bytes) ([]byte, error) {
34 dst, err := jsonwire.AppendUnquote(dst, src)
35 if err != nil {
36 err = &SyntacticError{Err: err}
37 }
38 return dst, err
39 }