From 8868fe9679bfdbffd55deecb34447de96c2cc612 Mon Sep 17 00:00:00 2001 From: "duanyi.aster" Date: Wed, 13 Mar 2024 17:32:18 +0800 Subject: [PATCH] unexport --- ast/decode.go | 4 +++- ast/search.go | 8 ++++--- export/api.go | 53 ---------------------------------------------- unquote/unquote.go | 3 ++- 4 files changed, 10 insertions(+), 58 deletions(-) delete mode 100644 export/api.go diff --git a/ast/decode.go b/ast/decode.go index 6328c347c..c521fb5f0 100644 --- a/ast/decode.go +++ b/ast/decode.go @@ -584,9 +584,11 @@ func skipArray(src string, pos int) (ret int, start int) { } } -// DecoderString decodes a JSON string from pos and return golang string. +// DecodeString decodes a JSON string from pos and return golang string. // - needEsc indicates if to unescaped escaping chars // - hasEsc tells if the returned string has escaping chars +// - validStr enables validating UTF8 charset +// func _DecodeString(src string, pos int, needEsc bool, validStr bool) (v string, ret int, hasEsc bool) { p := NewParserObj(src) p.p = pos diff --git a/ast/search.go b/ast/search.go index 820bf376b..a8d1e76f6 100644 --- a/ast/search.go +++ b/ast/search.go @@ -79,7 +79,7 @@ func (self *Searcher) getByPath(copystring bool, validate bool, path ...interfac return newRawNode(raw, t), nil } -// EXPORT +// GetByPath searches a path and returns relaction and types of target func _GetByPath(src string, path ...interface{}) (start int, end int, typ int, err error) { p := NewParserObj(src) s, e := p.getByPath(false, path...) @@ -104,7 +104,8 @@ func _GetByPath(src string, path ...interface{}) (start int, end int, typ int, e return s, p.p, int(t), nil } -// EXPORT +// ValidSyntax check if a json has a valid JSON syntax, +// while not validate UTF-8 charset func _ValidSyntax(json string) bool { p := NewParserObj(json) _, e := p.skip() @@ -117,7 +118,8 @@ func _ValidSyntax(json string) bool { return true } -// EXPORT +// SkipFast skip a json value in fast-skip algs, +// while not strictly validate JSON syntax and UTF-8 charset. func _SkipFast(src string, i int) (int, int, error) { p := NewParserObj(src) p.p = i diff --git a/export/api.go b/export/api.go deleted file mode 100644 index 2ddfa2d65..000000000 --- a/export/api.go +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2024 ByteDance Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This package is only used for exporting internal API to thrid-party libs. DO NOT USE IT. -package export - -import ( - _ "unsafe" -) - -// DecoderString decodes a JSON string from pos and return golang string. -// - needEsc indicates if to unescaped escaping chars -// - hasEsc tells if the returned string has escaping chars -// - validStr enables validating UTF8 charset -// -//go:linkname DecodeString github.com/bytedance/sonic/ast._DecodeString -func DecodeString(src string, pos int, needEsc bool, validStr bool) (v string, ret int, hasEsc bool) - -// GetByPath searches a path and returns relaction and types of target -// -//go:linkname GetByPath github.com/bytedance/sonic/ast._GetByPath -func GetByPath(src string, path ...interface{}) (start int, end int, typ int, err error) - -// ValidSyntax check if a json has a valid JSON syntax, -// while not validate UTF-8 charset -// -//go:linkname ValidSyntax github.com/bytedance/sonic/ast._ValidSyntax -func ValidSyntax(json string) bool - -// SkipFast skip a json value in fast-skip algs, -// while not strictly validate JSON syntax and UTF-8 charset. -// -//go:linkname SkipFast github.com/bytedance/sonic/ast._SkipFast -func SkipFast(src string, i int) (int, int, error) - -// Unquote unescapes a escaped string (not including `"` at begining and end) -// - replace enables replacing invalid utf8 escaped char with `\uffd` -// -//go:linkname Unquote github.com/bytedance/sonic/unquote._String -func Unquote(s string, replace bool) (ret string, err error) diff --git a/unquote/unquote.go b/unquote/unquote.go index 67f17d94b..d81406b2a 100644 --- a/unquote/unquote.go +++ b/unquote/unquote.go @@ -43,7 +43,8 @@ func IntoBytes(s string, m *[]byte) types.ParsingError { } } -// EXPORT +// String unescapes a escaped string (not including `"` at begining and end) +// - replace enables replacing invalid utf8 escaped char with `\uffd` func _String(s string, replace bool) (ret string, err error) { mm := make([]byte, 0, len(s)) err = intoBytesUnsafe(s, &mm, replace)