summaryrefslogtreecommitdiff
path: root/vendor/github.com/bytedance/sonic/ast/node.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/bytedance/sonic/ast/node.go')
-rw-r--r--vendor/github.com/bytedance/sonic/ast/node.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/vendor/github.com/bytedance/sonic/ast/node.go b/vendor/github.com/bytedance/sonic/ast/node.go
index 0d37baf12..6b5ad8a3e 100644
--- a/vendor/github.com/bytedance/sonic/ast/node.go
+++ b/vendor/github.com/bytedance/sonic/ast/node.go
@@ -1541,13 +1541,19 @@ var (
emptyObjectNode = Node{t: types.V_OBJECT}
)
-// NewRaw creates a node of raw json, and decides its type by first char.
+// NewRaw creates a node of raw json.
+// If the input json is invalid, NewRaw returns a error Node.
func NewRaw(json string) Node {
- if json == "" {
- panic("empty json string")
+ parser := NewParser(json)
+ start, err := parser.skip()
+ if err != 0 {
+ return *newError(err, err.Message())
+ }
+ it := switchRawType(parser.s[start])
+ if it == _V_NONE {
+ return Node{}
}
- it := switchRawType(json[0])
- return newRawNode(json, it)
+ return newRawNode(parser.s[start:parser.p], it)
}
// NewAny creates a node of type V_ANY if any's type isn't Node or *Node,