Skip to content

Commit

Permalink
move json.SafeSet
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Jul 8, 2024
1 parent 48a864b commit bbf1432
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions ast/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"sync"
"unicode/utf8"

"github.com/bytedance/sonic/internal/encoder/alg"
"github.com/bytedance/sonic/internal/rt"
)

const (
Expand All @@ -32,7 +32,7 @@ func quoteString(e *[]byte, s string) {
start := 0
for i := 0; i < len(s); {
if b := s[i]; b < utf8.RuneSelf {
if alg.SafeSet[b] {
if rt.SafeSet[b] {
i++
continue
}
Expand All @@ -56,8 +56,8 @@ func quoteString(e *[]byte, s string) {
// user-controlled strings are rendered into JSON
// and served to some browsers.
*e = append(*e, `u00`...)
*e = append(*e, alg.Hex[b>>4])
*e = append(*e, alg.Hex[b&0xF])
*e = append(*e, rt.Hex[b>>4])
*e = append(*e, rt.Hex[b&0xF])
}
i++
start = i
Expand All @@ -78,7 +78,7 @@ func quoteString(e *[]byte, s string) {
*e = append(*e, s[start:i]...)
}
*e = append(*e, `\u202`...)
*e = append(*e, alg.Hex[c&0xF])
*e = append(*e, rt.Hex[c&0xF])
i += size
start = i
continue
Expand Down
8 changes: 4 additions & 4 deletions internal/encoder/alg/spec_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Quote(e []byte, s string, double bool) []byte {

for i := 0; i < len(s); {
if b := s[i]; b < utf8.RuneSelf {
if SafeSet[b] {
if rt.SafeSet[b] {
i++
continue
}
Expand All @@ -79,8 +79,8 @@ func Quote(e []byte, s string, double bool) []byte {
// user-controlled strings are rendered into JSON
// and served to some browsers.
e = append(e, `u00`...)
e = append(e, Hex[b>>4])
e = append(e, Hex[b&0xF])
e = append(e, rt.Hex[b>>4])
e = append(e, rt.Hex[b&0xF])
}
i++
start = i
Expand All @@ -101,7 +101,7 @@ func Quote(e []byte, s string, double bool) []byte {
e = append(e, s[start:i]...)
}
e = append(e, `\u202`...)
e = append(e, Hex[c&0xF])
e = append(e, rt.Hex[c&0xF])
i += size
start = i
continue
Expand Down
2 changes: 1 addition & 1 deletion internal/encoder/alg/table.go → internal/rt/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package alg
package rt

import "unicode/utf8"

Expand Down

0 comments on commit bbf1432

Please sign in to comment.