mirror of
https://github.com/golang/go.git
synced 2026-06-27 03:11:23 +00:00
encoding/json: fix typos in documentation
Change-Id: Ib5eb80efa2af9bd5d68a93d9de8e3f1a761ed7a7 Reviewed-on: https://go-review.googlesource.com/c/go/+/772740 LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
This commit is contained in:
parent
7912a25a4e
commit
5756e857c8
13 changed files with 24 additions and 24 deletions
|
|
@ -170,9 +170,9 @@ func (dst *Flags) Join(src Flags) {
|
|||
// then copy over source value bits over to the destination (using OR).
|
||||
// e.g., dst := Flags{Presence: 0b_1100_0011, Values: 0b_1000_0011}
|
||||
// e.g., src := Flags{Presence: 0b_0101_1010, Values: 0b_1001_0010}
|
||||
dst.Presence |= src.Presence // e.g., 0b_1100_0011 | 0b_0101_1010 -> 0b_110_11011
|
||||
dst.Values &= ^src.Presence // e.g., 0b_1000_0011 & 0b_1010_0101 -> 0b_100_00001
|
||||
dst.Values |= src.Values // e.g., 0b_1000_0001 | 0b_1001_0010 -> 0b_100_10011
|
||||
dst.Presence |= src.Presence // e.g., 0b_1100_0011 | 0b_0101_1010 -> 0b_1101_1011
|
||||
dst.Values &= ^src.Presence // e.g., 0b_1000_0011 & 0b_1010_0101 -> 0b_1000_0001
|
||||
dst.Values |= src.Values // e.g., 0b_1000_0001 | 0b_1001_0010 -> 0b_1001_0011
|
||||
}
|
||||
|
||||
// Set sets both the presence and value for the provided bool (or set of bools).
|
||||
|
|
@ -184,7 +184,7 @@ func (fs *Flags) Set(f Bools) {
|
|||
// e.g., fs := Flags{Presence: 0b_0101_0010, Values: 0b_0001_0010}
|
||||
// e.g., f := 0b_1001_0001
|
||||
id := uint64(f) &^ uint64(1) // e.g., 0b_1001_0001 & 0b_1111_1110 -> 0b_1001_0000
|
||||
fs.Presence |= id // e.g., 0b_0101_0010 | 0b_1001_0000 -> 0b_1101_0011
|
||||
fs.Presence |= id // e.g., 0b_0101_0010 | 0b_1001_0000 -> 0b_1101_0010
|
||||
fs.Values &= ^id // e.g., 0b_0001_0010 & 0b_0110_1111 -> 0b_0000_0010
|
||||
fs.Values |= uint64(f&1) * id // e.g., 0b_0000_0010 | 0b_1001_0000 -> 0b_1001_0010
|
||||
}
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ func AppendFloat(dst []byte, src float64, bits int) []byte {
|
|||
return dst
|
||||
}
|
||||
|
||||
// ReformatNumber consumes a JSON string from src and appends it to dst,
|
||||
// ReformatNumber consumes a JSON number from src and appends it to dst,
|
||||
// canonicalizing it if specified.
|
||||
// It returns the appended output and the number of consumed input bytes.
|
||||
func ReformatNumber(dst, src []byte, flags *jsonflags.Flags) ([]byte, int, error) {
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ type Decoder struct {
|
|||
}
|
||||
|
||||
// decoderState is the low-level state of Decoder.
|
||||
// It has exported fields and method for use by the "json" package.
|
||||
// It has exported fields and methods for use by the "json" package.
|
||||
type decoderState struct {
|
||||
state
|
||||
decodeBuffer
|
||||
|
|
@ -154,7 +154,7 @@ func (d *decoderState) reset(b []byte, r io.Reader, opts ...Options) {
|
|||
d.Struct = opts2
|
||||
}
|
||||
|
||||
// Options returns the options used to construct the encoder and
|
||||
// Options returns the options used to construct the decoder and
|
||||
// may additionally contain semantic options passed to a
|
||||
// [encoding/json/v2.UnmarshalDecode] call.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
//
|
||||
// - a JSON literal, string, or number
|
||||
// - a JSON object (e.g., `{"name":"value"}`)
|
||||
// - a JSON array (e.g., `[1,2,3,]`)
|
||||
// - a JSON array (e.g., `[1,2,3]`)
|
||||
//
|
||||
// A JSON value is represented by the [Value] type in Go and is a []byte
|
||||
// containing the raw textual representation of the value. There is some overlap
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ type Encoder struct {
|
|||
}
|
||||
|
||||
// encoderState is the low-level state of Encoder.
|
||||
// It has exported fields and method for use by the "json" package.
|
||||
// It has exported fields and methods for use by the "json" package.
|
||||
type encoderState struct {
|
||||
state
|
||||
encodeBuffer
|
||||
|
|
@ -138,7 +138,7 @@ func (e *encoderState) reset(b []byte, w io.Writer, opts ...Options) {
|
|||
}
|
||||
}
|
||||
|
||||
// Options returns the options used to construct the decoder and
|
||||
// Options returns the options used to construct the encoder and
|
||||
// may additionally contain semantic options passed to a
|
||||
// [encoding/json/v2.MarshalEncode] call.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import (
|
|||
// Options configures [NewEncoder], [Encoder.Reset], [NewDecoder],
|
||||
// and [Decoder.Reset] with specific features.
|
||||
// Each function takes in a variadic list of options, where properties
|
||||
// set in latter options override the value of previously set properties.
|
||||
// set in later options override the value of previously set properties.
|
||||
//
|
||||
// There is a single Options type, which is used with both encoding and decoding.
|
||||
// Some options affect both operations, while others only affect one operation:
|
||||
|
|
@ -224,7 +224,7 @@ func Multiline(v bool) Options {
|
|||
// followed by one or more copies of indent according to the nesting depth.
|
||||
// The indent must only be composed of space or tab characters.
|
||||
//
|
||||
// If the intent to emit indented output without a preference for
|
||||
// If the intent is to emit indented output without a preference for
|
||||
// the particular indent string, then use [Multiline] instead.
|
||||
//
|
||||
// This only affects encoding and is ignored when decoding.
|
||||
|
|
|
|||
|
|
@ -526,7 +526,7 @@ func newAddressableValue(t reflect.Type) addressableValue {
|
|||
// This can be directly accessed on the encoder or decoder.
|
||||
|
||||
// All marshal and unmarshal behavior is implemented using these signatures.
|
||||
// The *jsonopts.Struct argument is guaranteed to identical to or at least
|
||||
// The *jsonopts.Struct argument is guaranteed to be identical to or at least
|
||||
// a strict super-set of the options in Encoder.Struct or Decoder.Struct.
|
||||
// It is identical for Marshal, Unmarshal, MarshalWrite, and UnmarshalRead.
|
||||
// It is a super-set for MarshalEncode and UnmarshalDecode.
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ func marshalObjectAny(enc *jsontext.Encoder, obj map[string]any, mo *jsonopts.St
|
|||
if err := enc.WriteToken(jsontext.BeginObject); err != nil {
|
||||
return err
|
||||
}
|
||||
// A Go map guarantees that each entry has a unique key
|
||||
// A Go map guarantees that each entry has a unique key.
|
||||
// The only possibility of duplicates is due to invalid UTF-8.
|
||||
if !mo.Flags.Get(jsonflags.AllowInvalidUTF8) {
|
||||
xe.Tokens.Last.DisableNamespace()
|
||||
|
|
@ -181,7 +181,7 @@ func unmarshalObjectAny(dec *jsontext.Decoder, uo *jsonopts.Struct) (map[string]
|
|||
panic("BUG: invalid kind: " + tok.Kind().String())
|
||||
}
|
||||
obj := make(map[string]any)
|
||||
// A Go map guarantees that each entry has a unique key
|
||||
// A Go map guarantees that each entry has a unique key.
|
||||
// The only possibility of duplicates is due to invalid UTF-8.
|
||||
if !uo.Flags.Get(jsonflags.AllowInvalidUTF8) {
|
||||
export.Decoder(dec).Tokens.Last.DisableNamespace()
|
||||
|
|
|
|||
|
|
@ -1033,7 +1033,7 @@ func makeMapArshaler(t reflect.Type) *arshaler {
|
|||
// mapKeyWithUniqueRepresentation reports whether all possible values of k
|
||||
// marshal to a different JSON value, and whether all possible JSON values
|
||||
// that can unmarshal into k unmarshal to different Go values.
|
||||
// In other words, the representation must be a bijective.
|
||||
// In other words, the representation must be a bijection.
|
||||
func mapKeyWithUniqueRepresentation(k reflect.Kind, allowInvalidUTF8 bool) bool {
|
||||
switch k {
|
||||
case reflect.Bool,
|
||||
|
|
@ -1042,7 +1042,7 @@ func mapKeyWithUniqueRepresentation(k reflect.Kind, allowInvalidUTF8 bool) bool
|
|||
return true
|
||||
case reflect.String:
|
||||
// For strings, we have to be careful since names with invalid UTF-8
|
||||
// maybe unescape to the same Go string value.
|
||||
// may unescape to the same Go string value.
|
||||
return !allowInvalidUTF8
|
||||
default:
|
||||
// Floating-point kinds are not listed above since NaNs
|
||||
|
|
@ -1288,7 +1288,7 @@ func makeStructArshaler(t reflect.Type) *arshaler {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
// Marshal into value capable of storing arbitrary object members.
|
||||
// Unmarshal into a value capable of storing arbitrary object members.
|
||||
if err := unmarshalInlinedFallbackNext(dec, va, uo, fields.inlinedFallback, val, name); err != nil {
|
||||
if isFatalError(err, uo.Flags) {
|
||||
return err
|
||||
|
|
@ -1871,7 +1871,7 @@ func makeInterfaceArshaler(t reflect.Type) *arshaler {
|
|||
return &fncs
|
||||
}
|
||||
|
||||
// isAnyType reports wether t is equivalent to the any interface type.
|
||||
// isAnyType reports whether t is equivalent to the any interface type.
|
||||
func isAnyType(t reflect.Type) bool {
|
||||
// This is forward compatible if the Go language permits type sets within
|
||||
// ordinary interfaces where an interface with zero methods does not
|
||||
|
|
|
|||
|
|
@ -539,7 +539,7 @@ func parseDurationISO8601(b []byte) (time.Duration, error) {
|
|||
}
|
||||
|
||||
// Parse the number.
|
||||
// A fraction allowed for the accurate units in the last part.
|
||||
// A fraction is allowed for the accurate units in the last part.
|
||||
whole, frac, ok := cutBytes(number, '.', ',')
|
||||
if ok {
|
||||
sawFrac = true
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ func isSyntacticError(err error) bool {
|
|||
return ok
|
||||
}
|
||||
|
||||
// isFatalError reports whether this error must terminate asharling.
|
||||
// isFatalError reports whether this error must terminate arshaling.
|
||||
// All errors are considered fatal unless operating under
|
||||
// [jsonflags.ReportErrorsWithLegacySemantics] in which case only
|
||||
// syntactic errors and I/O errors are considered fatal.
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ func makeStructFields(root reflect.Type) (fs structFields, serr *SemanticError)
|
|||
return cmp.Or(serr, &SemanticError{GoType: t, Err: fmt.Errorf(f, a...)})
|
||||
}
|
||||
|
||||
// Setup a queue for a breath-first search.
|
||||
// Setup a queue for a breadth-first search.
|
||||
var queueIndex int
|
||||
type queueEntry struct {
|
||||
typ reflect.Type
|
||||
|
|
@ -320,7 +320,7 @@ func makeStructFields(root reflect.Type) (fs structFields, serr *SemanticError)
|
|||
}
|
||||
for foldedName, fields := range fs.byFoldedName {
|
||||
if len(fields) > 1 {
|
||||
// The precedence order for conflicting ignoreCase names
|
||||
// The precedence order for conflicting case-insensitive names
|
||||
// is by breadth-first order, rather than depth-first order.
|
||||
slices.SortFunc(fields, func(x, y *structField) int {
|
||||
return cmp.Compare(x.id, y.id)
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ func CallMethodsWithLegacySemantics(v bool) Options {
|
|||
}
|
||||
|
||||
// FormatByteArrayAsArray specifies that a Go [N]byte is
|
||||
// formatted as as a normal Go array in contrast to the v2 default of
|
||||
// formatted as a normal Go array in contrast to the v2 default of
|
||||
// formatting [N]byte as using binary data encoding (RFC 4648).
|
||||
// If a struct field has a `format` tag option,
|
||||
// then the specified formatting takes precedence.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue