Bumps the go-deps group with 6 updates: | Package | From | To | | --- | --- | --- | | [github.com/aws/aws-sdk-go](https://github.com/aws/aws-sdk-go) | `1.45.10` | `1.45.16` | | [github.com/gophercloud/gophercloud](https://github.com/gophercloud/gophercloud) | `1.6.0` | `1.7.0` | | [github.com/openshift-online/ocm-sdk-go](https://github.com/openshift-online/ocm-sdk-go) | `0.1.364` | `0.1.371` | | [github.com/osbuild/images](https://github.com/osbuild/images) | `0.5.1-0.20230915095808-dd48a38be218` | `0.7.0` | | [github.com/vmware/govmomi](https://github.com/vmware/govmomi) | `0.30.7` | `0.31.0` | | [google.golang.org/api](https://github.com/googleapis/google-api-go-client) | `0.142.0` | `0.143.0` | Updates `github.com/aws/aws-sdk-go` from 1.45.10 to 1.45.16 - [Release notes](https://github.com/aws/aws-sdk-go/releases) - [Commits](https://github.com/aws/aws-sdk-go/compare/v1.45.10...v1.45.16) Updates `github.com/gophercloud/gophercloud` from 1.6.0 to 1.7.0 - [Release notes](https://github.com/gophercloud/gophercloud/releases) - [Changelog](https://github.com/gophercloud/gophercloud/blob/v1.7.0/CHANGELOG.md) - [Commits](https://github.com/gophercloud/gophercloud/compare/v1.6.0...v1.7.0) Updates `github.com/openshift-online/ocm-sdk-go` from 0.1.364 to 0.1.371 - [Release notes](https://github.com/openshift-online/ocm-sdk-go/releases) - [Changelog](https://github.com/openshift-online/ocm-sdk-go/blob/main/CHANGES.md) - [Commits](https://github.com/openshift-online/ocm-sdk-go/compare/v0.1.364...v0.1.371) Updates `github.com/osbuild/images` from 0.5.1-0.20230915095808-dd48a38be218 to 0.7.0 - [Release notes](https://github.com/osbuild/images/releases) - [Commits](https://github.com/osbuild/images/commits/v0.7.0) Updates `github.com/vmware/govmomi` from 0.30.7 to 0.31.0 - [Release notes](https://github.com/vmware/govmomi/releases) - [Changelog](https://github.com/vmware/govmomi/blob/main/CHANGELOG.md) - [Commits](https://github.com/vmware/govmomi/compare/v0.30.7...v0.31.0) Updates `google.golang.org/api` from 0.142.0 to 0.143.0 - [Release notes](https://github.com/googleapis/google-api-go-client/releases) - [Changelog](https://github.com/googleapis/google-api-go-client/blob/main/CHANGES.md) - [Commits](https://github.com/googleapis/google-api-go-client/compare/v0.142.0...v0.143.0) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-deps - dependency-name: github.com/gophercloud/gophercloud dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-deps - dependency-name: github.com/openshift-online/ocm-sdk-go dependency-type: direct:production update-type: version-update:semver-patch dependency-group: go-deps - dependency-name: github.com/osbuild/images dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-deps - dependency-name: github.com/vmware/govmomi dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-deps - dependency-name: google.golang.org/api dependency-type: direct:production update-type: version-update:semver-minor dependency-group: go-deps ... Signed-off-by: dependabot[bot] <support@github.com>
143 lines
3.4 KiB
Go
143 lines
3.4 KiB
Go
// Copyright 2010 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package json
|
|
|
|
import (
|
|
"bytes"
|
|
)
|
|
|
|
// Compact appends to dst the JSON-encoded src with
|
|
// insignificant space characters elided.
|
|
func Compact(dst *bytes.Buffer, src []byte) error {
|
|
return compact(dst, src, false)
|
|
}
|
|
|
|
func compact(dst *bytes.Buffer, src []byte, escape bool) error {
|
|
origLen := dst.Len()
|
|
scan := newScanner()
|
|
defer freeScanner(scan)
|
|
start := 0
|
|
for i, c := range src {
|
|
if escape && (c == '<' || c == '>' || c == '&') {
|
|
if start < i {
|
|
dst.Write(src[start:i])
|
|
}
|
|
dst.WriteString(`\u00`)
|
|
dst.WriteByte(hex[c>>4])
|
|
dst.WriteByte(hex[c&0xF])
|
|
start = i + 1
|
|
}
|
|
// Convert U+2028 and U+2029 (E2 80 A8 and E2 80 A9).
|
|
if escape && c == 0xE2 && i+2 < len(src) && src[i+1] == 0x80 && src[i+2]&^1 == 0xA8 {
|
|
if start < i {
|
|
dst.Write(src[start:i])
|
|
}
|
|
dst.WriteString(`\u202`)
|
|
dst.WriteByte(hex[src[i+2]&0xF])
|
|
start = i + 3
|
|
}
|
|
v := scan.step(scan, c)
|
|
if v >= scanSkipSpace {
|
|
if v == scanError {
|
|
break
|
|
}
|
|
if start < i {
|
|
dst.Write(src[start:i])
|
|
}
|
|
start = i + 1
|
|
}
|
|
}
|
|
if scan.eof() == scanError {
|
|
dst.Truncate(origLen)
|
|
return scan.err
|
|
}
|
|
if start < len(src) {
|
|
dst.Write(src[start:])
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func newline(dst *bytes.Buffer, prefix, indent string, depth int) {
|
|
dst.WriteByte('\n')
|
|
dst.WriteString(prefix)
|
|
for i := 0; i < depth; i++ {
|
|
dst.WriteString(indent)
|
|
}
|
|
}
|
|
|
|
// Indent appends to dst an indented form of the JSON-encoded src.
|
|
// Each element in a JSON object or array begins on a new,
|
|
// indented line beginning with prefix followed by one or more
|
|
// copies of indent according to the indentation nesting.
|
|
// The data appended to dst does not begin with the prefix nor
|
|
// any indentation, to make it easier to embed inside other formatted JSON data.
|
|
// Although leading space characters (space, tab, carriage return, newline)
|
|
// at the beginning of src are dropped, trailing space characters
|
|
// at the end of src are preserved and copied to dst.
|
|
// For example, if src has no trailing spaces, neither will dst;
|
|
// if src ends in a trailing newline, so will dst.
|
|
func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error {
|
|
origLen := dst.Len()
|
|
scan := newScanner()
|
|
defer freeScanner(scan)
|
|
needIndent := false
|
|
depth := 0
|
|
for _, c := range src {
|
|
scan.bytes++
|
|
v := scan.step(scan, c)
|
|
if v == scanSkipSpace {
|
|
continue
|
|
}
|
|
if v == scanError {
|
|
break
|
|
}
|
|
if needIndent && v != scanEndObject && v != scanEndArray {
|
|
needIndent = false
|
|
depth++
|
|
newline(dst, prefix, indent, depth)
|
|
}
|
|
|
|
// Emit semantically uninteresting bytes
|
|
// (in particular, punctuation in strings) unmodified.
|
|
if v == scanContinue {
|
|
dst.WriteByte(c)
|
|
continue
|
|
}
|
|
|
|
// Add spacing around real punctuation.
|
|
switch c {
|
|
case '{', '[':
|
|
// delay indent so that empty object and array are formatted as {} and [].
|
|
needIndent = true
|
|
dst.WriteByte(c)
|
|
|
|
case ',':
|
|
dst.WriteByte(c)
|
|
newline(dst, prefix, indent, depth)
|
|
|
|
case ':':
|
|
dst.WriteByte(c)
|
|
dst.WriteByte(' ')
|
|
|
|
case '}', ']':
|
|
if needIndent {
|
|
// suppress indent in empty object/array
|
|
needIndent = false
|
|
} else {
|
|
depth--
|
|
newline(dst, prefix, indent, depth)
|
|
}
|
|
dst.WriteByte(c)
|
|
|
|
default:
|
|
dst.WriteByte(c)
|
|
}
|
|
}
|
|
if scan.eof() == scanError {
|
|
dst.Truncate(origLen)
|
|
return scan.err
|
|
}
|
|
return nil
|
|
}
|