@@ -175,6 +175,7 @@ func (fj *FJ) readObject(pathName []byte) error {
175175 }
176176
177177 var val []byte
178+ var alt []byte
178179 switch ch {
179180 case '"' :
180181 val , err = fj .readStringValue ()
@@ -185,7 +186,7 @@ func (fj *FJ) readObject(pathName []byte) error {
185186 case 'n' :
186187 val , err = fj .readLiteral (nullBytes )
187188 case '-' , '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' :
188- val , err = fj .readNumber ()
189+ val , alt , err = fj .readNumber ()
189190 case '[' :
190191 if ! fj .nameTracker .IsNameUsed (memberName ) {
191192 fj .skipping ++
@@ -228,6 +229,9 @@ func (fj *FJ) readObject(pathName []byte) error {
228229 fj .storeObjectMemberField (pathForChild (pathName , memberName ), arrayTrail , val )
229230 }
230231 }
232+ if alt != nil {
233+ alt = nil
234+ }
231235 state = afterValueState
232236 case afterValueState :
233237 switch ch {
@@ -265,6 +269,7 @@ func (fj *FJ) readArray(pathName []byte) error {
265269 for {
266270 ch := fj .ch ()
267271 var val []byte // resets on each loop
272+ var alt []byte
268273 switch state {
269274 case inArrayState :
270275 // bypass space before element value. A bit klunky but allows for immense simplification
@@ -285,7 +290,7 @@ func (fj *FJ) readArray(pathName []byte) error {
285290 case 'n' :
286291 val , err = fj .readLiteral (nullBytes )
287292 case '-' , '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' :
288- val , err = fj .readNumber ()
293+ val , alt , err = fj .readNumber ()
289294 case '{' :
290295 if fj .skipping == 0 {
291296 fj .stepOneArrayElement ()
@@ -315,6 +320,9 @@ func (fj *FJ) readArray(pathName []byte) error {
315320 fj .storeArrayElementField (pathName , val )
316321 }
317322 }
323+ if alt != nil {
324+ alt = nil
325+ }
318326 state = afterValueState
319327 case afterValueState :
320328 switch ch {
@@ -341,7 +349,7 @@ func (fj *FJ) readArray(pathName []byte) error {
341349 * these higher-level funcs are going to advance the pointer after each invocation
342350 */
343351
344- func (fj * FJ ) readNumber () ([]byte , error ) {
352+ func (fj * FJ ) readNumber () ([]byte , [] byte , error ) {
345353 numStart := fj .eventIndex
346354 state := numberStartState
347355 for {
@@ -354,7 +362,7 @@ func (fj *FJ) readNumber() ([]byte, error) {
354362 case '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' :
355363 state = numberIntegralPartState
356364 default :
357- return nil , fj .error (fmt .Sprintf ("illegal char '%c' in number" , ch ))
365+ return nil , nil , fj .error (fmt .Sprintf ("illegal char '%c' in number" , ch ))
358366 }
359367 case numberIntegralPartState :
360368 switch ch {
@@ -366,35 +374,56 @@ func (fj *FJ) readNumber() ([]byte, error) {
366374 state = numberExpState
367375 case ',' , ']' , '}' , ' ' , '\t' , '\n' , '\r' :
368376 fj .eventIndex --
369- return fj .event [numStart : fj .eventIndex + 1 ], nil
377+ // TODO: Too expensive; make it possible for people to ask for this
378+ //bytes := fj.event[numStart : fj.eventIndex+1]
379+ //c, err := canonicalize(bytes)
380+ var alt []byte
381+ //if err == nil {
382+ // alt = []byte(c)
383+ //}
384+ return fj .event [numStart : fj .eventIndex + 1 ], alt , nil
370385 default :
371- return nil , fj .error (fmt .Sprintf ("illegal char '%c' in number" , ch ))
386+ return nil , nil , fj .error (fmt .Sprintf ("illegal char '%c' in number" , ch ))
372387 }
373388 case numberFracState :
374389 switch ch {
375390 case '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' :
376391 // no-op
377392 case ',' , ']' , '}' , ' ' , '\t' , '\n' , '\r' :
378393 fj .eventIndex --
379- return fj .event [numStart : fj .eventIndex + 1 ], nil
394+ bytes := fj .event [numStart : fj .eventIndex + 1 ]
395+ // TODO: Too expensive; make it possible for people to ask for this
396+ // c, err := canonicalize(bytes)
397+ var alt []byte
398+ //if err == nil {
399+ // alt = []byte(c)
400+ //}
401+ return bytes , alt , nil
380402 case 'e' :
381403 state = numberExpState
382404 default :
383- return nil , fj .error (fmt .Sprintf ("illegal char '%c' in number" , ch ))
405+ return nil , nil , fj .error (fmt .Sprintf ("illegal char '%c' in number" , ch ))
384406 }
385407 case numberExpState :
386408 switch ch {
387409 case '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' :
388410 // no-op
389411 case ',' , ']' , '}' , ' ' , '\t' , '\n' , '\r' :
390412 fj .eventIndex --
391- return fj .event [numStart : fj .eventIndex + 1 ], nil
413+ // bytes := fj.event[numStart : fj.eventIndex+1]
414+ // TODO: Too expensive; make it possible for people to ask for this
415+ // c, err := canonicalize(bytes)
416+ var alt []byte
417+ // if err == nil {
418+ // alt = []byte(c)
419+ // }
420+ return fj .event [numStart : fj .eventIndex + 1 ], alt , nil
392421 }
393422 default :
394- return nil , fj .error (fmt .Sprintf ("illegal char '%c' in number" , ch ))
423+ return nil , nil , fj .error (fmt .Sprintf ("illegal char '%c' in number" , ch ))
395424 }
396425 if fj .step () != nil {
397- return nil , fj .error ("event truncated in number" )
426+ return nil , nil , fj .error ("event truncated in number" )
398427 }
399428 }
400429}
0 commit comments