parser.gno

0.74 Kb ยท 36 lines
 1package json
 2
 3import (
 4	"bytes"
 5)
 6
 7const (
 8	unescapeStackBufSize = 64
 9	absMinInt64          = 1 << 63
10	maxInt64             = absMinInt64 - 1
11	maxUint64            = 1<<64 - 1
12)
13
14// PaseStringLiteral parses a string from the given byte slice.
15func ParseStringLiteral(data []byte) (string, error) {
16	var buf [unescapeStackBufSize]byte
17
18	bf, err := Unescape(data, buf[:])
19	if err != nil {
20		return "", errInvalidStringInput
21	}
22
23	return string(bf), nil
24}
25
26// ParseBoolLiteral parses a boolean value from the given byte slice.
27func ParseBoolLiteral(data []byte) (bool, error) {
28	switch {
29	case bytes.Equal(data, trueLiteral):
30		return true, nil
31	case bytes.Equal(data, falseLiteral):
32		return false, nil
33	default:
34		return false, errMalformedBooleanValue
35	}
36}