summaryrefslogtreecommitdiff
path: root/borrowed_misc.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-08-13 15:11:17 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-08-13 15:18:11 -0600
commit234e0836f1040f7724251b4120a2351bcbf64131 (patch)
tree201b30fcc99eed470ae345a9bbe594f7ee7a1178 /borrowed_misc.go
parentf2769bd863521cf316ec9237a498bfa4ecaa115f (diff)
set up as a separate repo
Diffstat (limited to 'borrowed_misc.go')
-rw-r--r--borrowed_misc.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/borrowed_misc.go b/borrowed_misc.go
new file mode 100644
index 0000000..5c6bbb6
--- /dev/null
+++ b/borrowed_misc.go
@@ -0,0 +1,42 @@
+// Copyright 2010 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package lowmemjson
+
+import (
+ "fmt"
+ "reflect"
+)
+
+// A SyntaxError is a description of a JSON syntax error.
+//
+// from scanner.go
+type SyntaxError struct {
+ msg string // description of error
+ Offset int64 // error occurred after reading Offset bytes
+}
+
+func (e *SyntaxError) Error() string {
+ return fmt.Sprintf("JSON syntax error at input byte %v: %v",
+ e.Offset, e.msg)
+}
+
+// from encode.go
+func isEmptyValue(v reflect.Value) bool {
+ switch v.Kind() {
+ case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
+ return v.Len() == 0
+ case reflect.Bool:
+ return !v.Bool()
+ case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
+ return v.Int() == 0
+ case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
+ return v.Uint() == 0
+ case reflect.Float32, reflect.Float64:
+ return v.Float() == 0
+ case reflect.Interface, reflect.Pointer:
+ return v.IsNil()
+ }
+ return false
+}