File tree Expand file tree Collapse file tree 2 files changed +168
-75
lines changed Expand file tree Collapse file tree 2 files changed +168
-75
lines changed Original file line number Diff line number Diff line change @@ -442,3 +442,22 @@ func unsafeBytesToString(data []byte) string {
442
442
sh := reflect.StringHeader {Data : h .Data , Len : h .Len }
443
443
return * (* string )(unsafe .Pointer (& sh ))
444
444
}
445
+
446
+ // ParseBoolean parses a Boolean ValueType into a Go bool (not particularly useful, but here for completeness)
447
+ func ParseBoolean (vbytes []byte ) bool {
448
+ return (vbytes [0 ] == 't' ) // assumes value is already validated by Get(), etc. as signaled by jtype == Boolean
449
+ }
450
+
451
+ // ParseString parses a String ValueType into a Go string (the main parsing work is unescaping the JSON string)
452
+ func ParseString (vbytes []byte ) (string , error ) {
453
+ return "" , nil
454
+ }
455
+
456
+ // ParseNumber parses a Number ValueType into a Go float64
457
+ func ParseNumber (vbytes []byte ) (float64 , error ) {
458
+ if v , err := strconv .ParseFloat (unsafeBytesToString (vbytes ), 64 ); err != nil { // TODO: use better BytesParseFloat in PR #25
459
+ return 0 , MalformedValueError
460
+ } else {
461
+ return v , nil
462
+ }
463
+ }
You can’t perform that action at this time.
0 commit comments