2021-11-06 19:25:25 +01:00
|
|
|
package jsonx
|
|
|
|
|
2024-09-19 23:59:27 +02:00
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
|
|
|
)
|
2021-11-06 19:25:25 +01:00
|
|
|
|
|
|
|
var (
|
|
|
|
quoteLiteral = '"'
|
|
|
|
emptyQuoteBytes = []byte(`""`)
|
|
|
|
nullLiteral = []byte("null")
|
2024-09-19 23:59:27 +02:00
|
|
|
|
|
|
|
// ErrInvalid is returned when the value is invalid.
|
|
|
|
ErrInvalid = errors.New("invalid")
|
2021-11-06 19:25:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func isNull(b []byte) bool {
|
|
|
|
return len(b) == 0 || bytes.Equal(b, nullLiteral)
|
|
|
|
}
|
|
|
|
|
|
|
|
func trimQuotesFunc(r rune) bool {
|
|
|
|
return r == quoteLiteral
|
|
|
|
}
|
|
|
|
|
|
|
|
func trimQuotes(b []byte) []byte {
|
|
|
|
return bytes.TrimFunc(b, trimQuotesFunc)
|
|
|
|
}
|