3636
3737const (
3838 // Root is a top-level JSONPointer, indicated by an empty string.
39- Root JSONPointer = ""
39+ Root Pointer = ""
4040)
4141
4242// New encodes and returns the token + tokens into a JSONPointer.
@@ -49,15 +49,15 @@ const (
4949// jsonpointer.New("/") => "/~1"
5050// jsonpointer.New("~") => "/~0"
5151//
52- func New (tokens ... string ) JSONPointer {
52+ func New (tokens ... string ) Pointer {
5353 return NewFromStrings (tokens )
5454}
5555
5656// NewFromStrings encodes and returns the tokens into a JSONPointer.
5757//
5858// Examples:
5959// jsonpointer.NewFromStrings([]string{"foo", "bar", "baz"}) => "/foo/bar/baz"
60- func NewFromStrings (tokens []string ) JSONPointer {
60+ func NewFromStrings (tokens []string ) Pointer {
6161 b := & strings.Builder {}
6262 b .Grow (len (tokens ))
6363 if len (tokens ) == 0 {
@@ -70,31 +70,35 @@ func NewFromStrings(tokens []string) JSONPointer {
7070 panic (err )
7171 }
7272 }
73- return JSONPointer (b .String ())
73+ return Pointer (b .String ())
7474}
7575
76- // A JSONPointer is a Unicode string containing a sequence of zero or more
76+ // Alias for Pointer
77+ // Deprecated in favor of Pointer
78+ type JSONPointer = Pointer
79+
80+ // A Pointer is a Unicode string containing a sequence of zero or more
7781// reference tokens, each prefixed by a '/' character.
7882//
7983// See [rfc 6901 for more information](https://datatracker.ietf.org/doc/html/rfc6901).
8084//
81- type JSONPointer string
85+ type Pointer string
8286
83- func (p JSONPointer ) String () string {
87+ func (p Pointer ) String () string {
8488 return string (p )
8589}
8690
8791// Append appends token to the end of reference p and returns the new JSONPointer.
8892//
8993// Note: token is not encoded. Use p.AppendString to encode and append the
9094// token.
91- func (p JSONPointer ) Append (token Token ) JSONPointer {
95+ func (p Pointer ) Append (token Token ) Pointer {
9296 return p + "/" + token .ptr ()
9397}
9498
9599// AppendString encodes and appends token to the value of p and returns the new
96100// JSONPointer.
97- func (p JSONPointer ) AppendString (token string ) JSONPointer {
101+ func (p Pointer ) AppendString (token string ) Pointer {
98102 return p .Append (Token (encoder .Replace (token )))
99103}
100104
@@ -103,13 +107,13 @@ func (p JSONPointer) AppendString(token string) JSONPointer {
103107//
104108// Note: token is not encoded. Use p.PrependString to encode and prepend the
105109// token.
106- func (p JSONPointer ) Prepend (token Token ) JSONPointer {
110+ func (p Pointer ) Prepend (token Token ) Pointer {
107111 return "/" + token .ptr () + p
108112}
109113
110114// PrependString encodes and prepends token to the value of p and returns the new
111115// JSONPointer.
112- func (p JSONPointer ) PrependString (token string ) JSONPointer {
116+ func (p Pointer ) PrependString (token string ) Pointer {
113117 return p .Prepend (Token (encoder .Replace (token )))
114118}
115119
@@ -121,14 +125,14 @@ func (p JSONPointer) PrependString(token string) JSONPointer {
121125// by a '0' or '1'.
122126//
123127//
124- func (p JSONPointer ) Validate () (err error ) {
128+ func (p Pointer ) Validate () (err error ) {
125129 if err = p .validateStart (); err != nil {
126130 return err
127131 }
128132 return p .validateeEncoding ()
129133}
130134
131- func (p JSONPointer ) validateeEncoding () error {
135+ func (p Pointer ) validateeEncoding () error {
132136 if len (p ) == 0 {
133137 return nil
134138 }
@@ -143,29 +147,29 @@ func (p JSONPointer) validateeEncoding() error {
143147 return nil
144148}
145149
146- func (p JSONPointer ) validateStart () error {
150+ func (p Pointer ) validateStart () error {
147151 if len (p ) > 0 && ! startsWithSlash (p ) {
148152 return ErrMalformedStart
149153 }
150154 return nil
151155}
152156
153- func (p JSONPointer ) Pop () (JSONPointer , Token , bool ) {
157+ func (p Pointer ) Pop () (Pointer , Token , bool ) {
154158 i := lastSlash (p )
155159 if i == - 1 {
156160 return "" , "" , false
157161 }
158- return JSONPointer (p [:i ]), Token (p [i + 1 :]), true
162+ return Pointer (p [:i ]), Token (p [i + 1 :]), true
159163}
160164
161- func (p JSONPointer ) LastToken () (Token , bool ) {
165+ func (p Pointer ) LastToken () (Token , bool ) {
162166 _ , t , e := p .Pop ()
163167 return t , e
164168}
165169
166170// Next splits the JSONPointer at the first slash and returns the token and the
167171// remaining JSONPointer.
168- func (p JSONPointer ) Next () (JSONPointer , Token , bool ) {
172+ func (p Pointer ) Next () (Pointer , Token , bool ) {
169173 if p == "" {
170174 return "" , "" , false
171175 }
@@ -176,27 +180,27 @@ func (p JSONPointer) Next() (JSONPointer, Token, bool) {
176180 case 0 :
177181 return "" , Token (p [1 :]), true
178182 default :
179- return JSONPointer (p [i :]), Token (p [1 :i ]), true
183+ return Pointer (p [i :]), Token (p [1 :i ]), true
180184 }
181185}
182186
183187// NextToken splits the JSONPointer at the first slash and returns the token.
184- func (p JSONPointer ) NextToken () (Token , bool ) {
188+ func (p Pointer ) NextToken () (Token , bool ) {
185189 _ , t , ok := p .Next ()
186190 return t , ok
187191}
188192
189- func (p JSONPointer ) NextPointer () (JSONPointer , bool ) {
193+ func (p Pointer ) NextPointer () (Pointer , bool ) {
190194 v , _ , ok := p .Next ()
191195 return v , ok
192196}
193197
194- func (p JSONPointer ) IsRoot () bool {
198+ func (p Pointer ) IsRoot () bool {
195199 return p == Root
196200}
197201
198202// Tokens returns the decoded tokens of the JSONPointer.
199- func (p JSONPointer ) Tokens () []string {
203+ func (p Pointer ) Tokens () []string {
200204 if p == "" {
201205 return []string {}
202206 }
@@ -212,19 +216,19 @@ func (p JSONPointer) Tokens() []string {
212216
213217// lastSlash(ptr) returns the index of the last slash in the JSONPointer or -1
214218// if not present
215- func lastSlash (ptr JSONPointer ) int {
219+ func lastSlash (ptr Pointer ) int {
216220 return strings .LastIndexByte (string (ptr ), '/' )
217221}
218222
219- func startsWithSlash (ptr JSONPointer ) bool {
223+ func startsWithSlash (ptr Pointer ) bool {
220224 if len (ptr ) == 0 {
221225 return false
222226 }
223227 return ptr [0 ] == '/'
224228}
225229
226230// nextSlash(ptr) returns the index of the next slash in the JSONPointer.
227- func nextSlash (ptr JSONPointer ) int {
231+ func nextSlash (ptr Pointer ) int {
228232 if ! startsWithSlash (ptr ) {
229233 return - 1
230234 }
0 commit comments