github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/value_type.go (about)

     1  package jzon
     2  
     3  // ValueType is the type of the next json token
     4  type ValueType int
     5  
     6  const (
     7  	// WhiteSpaceValue the next token is whitespace
     8  	WhiteSpaceValue ValueType = iota
     9  	// InvalidValue an error occurred
    10  	InvalidValue
    11  	// StringValue the next token is string
    12  	StringValue
    13  	// NumberValue the next token is number
    14  	NumberValue
    15  	// ObjectValue the next token is object
    16  	ObjectValue
    17  	// ArrayValue the next token is array
    18  	ArrayValue
    19  	// BoolValue the next token is a boolean value
    20  	BoolValue
    21  	// NullValue the next token is null
    22  	NullValue
    23  	// LastValue is a counter, should not be used
    24  	LastValue
    25  )
    26  
    27  var (
    28  	valueTypeNames [LastValue]string
    29  	valueTypeMap   [charNum]ValueType
    30  )
    31  
    32  func init() {
    33  	// value type names
    34  	valueTypeNames[WhiteSpaceValue] = "WhiteSpaceValue"
    35  	valueTypeNames[InvalidValue] = "InvalidValue"
    36  	valueTypeNames[StringValue] = "StringValue"
    37  	valueTypeNames[NumberValue] = "NumberValue"
    38  	valueTypeNames[ObjectValue] = "ObjectValue"
    39  	valueTypeNames[ArrayValue] = "ArrayValue"
    40  	valueTypeNames[BoolValue] = "BoolValue"
    41  	valueTypeNames[NullValue] = "NullValue"
    42  
    43  	// value type map
    44  	for i := 0; i < charNum; i++ {
    45  		valueTypeMap[i] = InvalidValue
    46  	}
    47  	for _, c := range " \n\t\r" {
    48  		valueTypeMap[c] = WhiteSpaceValue
    49  	}
    50  	valueTypeMap['"'] = StringValue
    51  	for _, c := range "-0123456789" {
    52  		valueTypeMap[c] = NumberValue
    53  	}
    54  	valueTypeMap['{'] = ObjectValue
    55  	valueTypeMap['['] = ArrayValue
    56  	for _, c := range "tf" {
    57  		valueTypeMap[c] = BoolValue
    58  	}
    59  	valueTypeMap['n'] = NullValue
    60  }