Skip to content

Commit

Permalink
export Unquote
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Jan 22, 2024
1 parent 57ae213 commit 6174ca8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions ast/api_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
var typeByte = rt.UnpackEface(byte(0)).Type

//go:nocheckptr
func quote(buf *[]byte, val string) {
func Quote(buf *[]byte, val string) {
*buf = append(*buf, '"')
if len(val) == 0 {
*buf = append(*buf, '"')
Expand Down Expand Up @@ -73,7 +73,7 @@ func quote(buf *[]byte, val string) {
*buf = append(*buf, '"')
}

func unquote(src string) (string, types.ParsingError) {
func Unquote(src string) (string, types.ParsingError) {
return uq.String(src)
}

Expand Down Expand Up @@ -162,7 +162,7 @@ func DecodeString(src string, pos int, needEsc bool) (v string, ret int, hasEsc
return str, p.p, true
}
/* unquote the string */
out, err := unquote(str)
out, err := Unquote(str)
/* check for errors */
if err != 0 {
return "", -int(err), true
Expand Down
4 changes: 2 additions & 2 deletions ast/api_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func init() {
println("WARNING: sonic only supports Go1.16~1.21 && CPU amd64, but your environment is not suitable")
}

func quote(buf *[]byte, val string) {
func Quote(buf *[]byte, val string) {
quoteString(buf, val)
}

func unquote(src string) (string, types.ParsingError) {
func Unquote(src string) (string, types.ParsingError) {
sp := rt.IndexChar(src, -1)
out, ok := unquoteBytes(rt.BytesFrom(sp, len(src)+2, len(src)+2))
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions ast/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (self *Node) encodeString(buf *[]byte) error {
return nil
}

quote(buf, self.toString())
Quote(buf, self.toString())
return nil
}

Expand Down Expand Up @@ -218,7 +218,7 @@ func (self *Pair) encode(buf *[]byte) error {
return self.Value.encode(buf)
}

quote(buf, self.Key)
Quote(buf, self.Key)
*buf = append(*buf, ':')

return self.Value.encode(buf)
Expand Down
10 changes: 5 additions & 5 deletions ast/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (self *Parser) decodeObject(ret *linkedPairs) (Node, types.ParsingError) {

/* check for escape sequence */
if njs.Ep != -1 {
if key, err = unquote(key); err != 0 {
if key, err = Unquote(key); err != 0 {
return Node{}, err
}
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func (self *Parser) decodeString(iv int64, ep int) (Node, types.ParsingError) {
}

/* unquote the string */
out, err := unquote(s)
out, err := Unquote(s)

/* check for errors */
if err != 0 {
Expand Down Expand Up @@ -353,7 +353,7 @@ func (self *Parser) key() (string, types.ParsingError) {

/* check for escape sequence */
if njs.Ep != -1 {
if key, err = unquote(key); err != 0 {
if key, err = Unquote(key); err != 0 {
return "", err
}
}
Expand Down Expand Up @@ -441,7 +441,7 @@ func (self *Parser) searchKey(match string) (int, types.ParsingError) {

/* check for escape sequence */
if njs.Ep != -1 {
if key, err = unquote(key); err != 0 {
if key, err = Unquote(key); err != 0 {
return comma, err
}
}
Expand Down Expand Up @@ -663,7 +663,7 @@ func (self *Node) skipNextPair() *Pair {

/* check for escape sequence */
if njs.Ep != -1 {
if key, err = unquote(key); err != 0 {
if key, err = Unquote(key); err != 0 {
return &Pair{key, *newSyntaxError(parser.syntaxError(err))}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ast/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (self *Value) SetByPath(val Value, allowAppend bool, path ...interface{}) (
func appendPathValue(b []byte, path []interface{}, val Value) ([]byte, error) {
for i, k := range path {
if key, ok := k.(string); ok {
quote(&b, key)
Quote(&b, key)
b = append(b, ":"...)
}
if i == len(path)-1 {
Expand Down Expand Up @@ -658,7 +658,7 @@ func (self *Value) SetMany(keys []string, vals []Value) (bool, error) {
}
empty = false
// write key
quote(&b, keys[r.i])
Quote(&b, keys[r.i])
b = append(b, ":"...)
// write new val
b = append(b, vals[r.i].js...)
Expand Down
4 changes: 2 additions & 2 deletions ast/visitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (self *traverser) decodeObject() error {

/* check for escape sequence */
if njs.Ep != -1 {
if key, err = unquote(key); err != 0 {
if key, err = Unquote(key); err != 0 {
return err
}
}
Expand Down Expand Up @@ -307,7 +307,7 @@ func (self *traverser) decodeString(iv int64, ep int) error {
}

/* unquote the string */
out, err := unquote(s)
out, err := Unquote(s)
if err != 0 {
return err
}
Expand Down

0 comments on commit 6174ca8

Please sign in to comment.