Skip to content

Commit ee88191

Browse files
authored
Fix incorrect jsontext docs (#154)
In #65, we always track the StackPointer regardless of whether AllowDuplicateNames is enabled or not. Fix stale documentation comments.
1 parent 4e03810 commit ee88191

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

jsontext/decode.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,8 +1143,6 @@ func (d *Decoder) StackIndex(i int) (Kind, int64) {
11431143
}
11441144

11451145
// StackPointer returns a JSON Pointer (RFC 6901) to the most recently read value.
1146-
// Object names are only present if [AllowDuplicateNames] is false, otherwise
1147-
// object members are represented using their index within the object.
11481146
func (d *Decoder) StackPointer() Pointer {
11491147
return Pointer(d.s.AppendStackPointer(nil, -1))
11501148
}

jsontext/encode.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,6 @@ func (e *Encoder) StackIndex(i int) (Kind, int64) {
947947
}
948948

949949
// StackPointer returns a JSON Pointer (RFC 6901) to the most recently written value.
950-
// Object names are only present if [AllowDuplicateNames] is false, otherwise
951-
// object members are represented using their index within the object.
952950
func (e *Encoder) StackPointer() Pointer {
953951
return Pointer(e.s.AppendStackPointer(nil, -1))
954952
}

jsontext/state.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ type state struct {
5555
Tokens stateMachine
5656

5757
// Names is a stack of object names.
58-
// Not used if AllowDuplicateNames is true.
5958
Names objectNameStack
6059

6160
// Namespaces is a stack of object namespaces.
@@ -107,11 +106,11 @@ func (p Pointer) IsValid() bool {
107106
return len(p) == 0 || p[0] == '/'
108107
}
109108

110-
// Contains reports whether the JSON value that p1 points to
111-
// is equal to or contains the JSON value that p2 points to.
112-
func (p1 Pointer) Contains(p2 Pointer) bool {
113-
// Invariant: len(p1) <= len(p2) if p1.Contains(p2)
114-
suffix, ok := strings.CutPrefix(string(p2), string(p1))
109+
// Contains reports whether the JSON value that p points to
110+
// is equal to or contains the JSON value that pc points to.
111+
func (p Pointer) Contains(pc Pointer) bool {
112+
// Invariant: len(p) <= len(pc) if p.Contains(pc)
113+
suffix, ok := strings.CutPrefix(string(pc), string(p))
115114
return ok && (suffix == "" || suffix[0] == '/')
116115
}
117116

0 commit comments

Comments
 (0)