830 lines
20 KiB
Go
830 lines
20 KiB
Go
// Code generated by zi2go from std_json_scan.zi. DO NOT EDIT.
|
|
package main
|
|
|
|
// #import std_text
|
|
// #import std_vec
|
|
type JsonSpan struct {
|
|
Start int32
|
|
End int32
|
|
After int32
|
|
Valid bool
|
|
}
|
|
|
|
type JsonNumber struct {
|
|
Value float64
|
|
After int32
|
|
Valid bool
|
|
}
|
|
|
|
type JsonRange struct {
|
|
Start int32
|
|
End int32
|
|
}
|
|
|
|
type JsonText struct {
|
|
Value __type_838711075b90279a
|
|
Valid bool
|
|
}
|
|
|
|
func StdJsonScan_Space(text string, at int32) int32 {
|
|
cursor := at
|
|
for cursor >= 0 && cursor < int32(int64(len(text))) {
|
|
ch := text[cursor]
|
|
if ch != 32 && ch != 9 && ch != 10 && ch != 13 {
|
|
break
|
|
}
|
|
cursor = cursor + 1
|
|
}
|
|
return cursor
|
|
}
|
|
|
|
func StdJsonScan_Digit(ch uint8) bool {
|
|
return ch >= 48 && ch <= 57
|
|
}
|
|
|
|
func StdJsonScan_Hex(ch uint8) bool {
|
|
var value_0 bool = StdJsonScan_Digit(ch)
|
|
return value_0 || (ch >= 65 && ch <= 70) || (ch >= 97 && ch <= 102)
|
|
}
|
|
|
|
func StdJsonScan_ReadString(text string, at int32) JsonSpan {
|
|
var result JsonSpan = JsonSpan{}
|
|
if at < 0 || at >= int32(int64(len(text))) || text[at] != 34 {
|
|
return result
|
|
}
|
|
result.Start = at + 1
|
|
cursor := result.Start
|
|
for cursor < int32(int64(len(text))) {
|
|
ch := text[cursor]
|
|
if ch == 34 {
|
|
result.End = cursor
|
|
result.After = cursor + 1
|
|
result.Valid = true
|
|
return result
|
|
}
|
|
if ch < 32 {
|
|
return result
|
|
}
|
|
if ch == 92 {
|
|
cursor = cursor + 1
|
|
if cursor >= int32(int64(len(text))) {
|
|
return result
|
|
}
|
|
escaped := text[cursor]
|
|
if escaped == 117 {
|
|
var index int32 = 0
|
|
for index < 4 {
|
|
cursor = cursor + 1
|
|
var value_0 bool = cursor >= int32(int64(len(text)))
|
|
if !value_0 {
|
|
var value_1 bool = StdJsonScan_Hex(text[cursor])
|
|
value_0 = !value_1
|
|
}
|
|
if value_0 {
|
|
return result
|
|
}
|
|
index = index + 1
|
|
}
|
|
} else {
|
|
var value_2 bool = escaped != 34 && escaped != 92 && escaped != 47 && escaped != 98 && escaped != 102 && escaped != 110
|
|
if value_2 && escaped != 114 && escaped != 116 {
|
|
return result
|
|
}
|
|
}
|
|
}
|
|
cursor = cursor + 1
|
|
}
|
|
return result
|
|
}
|
|
|
|
func StdJsonScan_HexValue(ch uint8) int32 {
|
|
if ch >= 48 && ch <= 57 {
|
|
return int32(ch) - 48
|
|
}
|
|
if ch >= 97 && ch <= 102 {
|
|
return int32(ch) - 87
|
|
}
|
|
if ch >= 65 && ch <= 70 {
|
|
return int32(ch) - 55
|
|
}
|
|
return -1
|
|
}
|
|
|
|
func StdJsonScan_ReadHex4(text string, at int32, end int32) int32 {
|
|
if at < 0 || at > end-4 {
|
|
return -1
|
|
}
|
|
var value int32 = 0
|
|
var index int32 = 0
|
|
for index < 4 {
|
|
digit := StdJsonScan_HexValue(text[(at + index)])
|
|
if digit < 0 {
|
|
return -1
|
|
}
|
|
value = (value * 16) + digit
|
|
index = index + 1
|
|
}
|
|
return value
|
|
}
|
|
|
|
func StdJsonScan_AppendUtf8(output []uint8, length int32, codepoint int32) int32 {
|
|
var size int32 = 1
|
|
if codepoint >= 128 {
|
|
size = 2
|
|
}
|
|
if codepoint >= 2048 {
|
|
size = 3
|
|
}
|
|
if codepoint >= 65536 {
|
|
size = 4
|
|
}
|
|
if length < 0 || (length+size)+1 > int32(int64(len(output))) {
|
|
return -1
|
|
}
|
|
if size == 1 {
|
|
output[length] = uint8(codepoint)
|
|
} else if size == 2 {
|
|
output[length] = uint8((192 + (codepoint / 64)))
|
|
output[(length + 1)] = uint8((128 + (codepoint % 64)))
|
|
} else if size == 3 {
|
|
output[length] = uint8((224 + (codepoint / 4096)))
|
|
output[(length + 1)] = uint8((128 + ((codepoint / 64) % 64)))
|
|
output[(length + 2)] = uint8((128 + (codepoint % 64)))
|
|
} else {
|
|
output[length] = uint8((240 + (codepoint / 262144)))
|
|
output[(length + 1)] = uint8((128 + ((codepoint / 4096) % 64)))
|
|
output[(length + 2)] = uint8((128 + ((codepoint / 64) % 64)))
|
|
output[(length + 3)] = uint8((128 + (codepoint % 64)))
|
|
}
|
|
return length + size
|
|
}
|
|
|
|
func StdJsonScan_ReadStringText(text string, at int32, output []uint8) int32 {
|
|
if int64(len(output)) == 0 {
|
|
return -1
|
|
}
|
|
output[0] = 0
|
|
end := int32(int64(len(text)))
|
|
if at < 0 || at >= end || text[at] != 34 {
|
|
return -1
|
|
}
|
|
var length int32 = 0
|
|
cursor := at + 1
|
|
for cursor < end && length >= 0 {
|
|
ch := text[cursor]
|
|
if ch == 34 {
|
|
output[length] = 0
|
|
return length
|
|
}
|
|
if ch < 32 {
|
|
break
|
|
}
|
|
codepoint := int32(ch)
|
|
if ch == 92 {
|
|
if cursor+1 >= end {
|
|
break
|
|
}
|
|
escaped := text[(cursor + 1)]
|
|
var value_0 bool = escaped != 34 && escaped != 92 && escaped != 47 && escaped != 98 && escaped != 102 && escaped != 110
|
|
if value_0 && escaped != 114 && escaped != 116 && escaped != 117 {
|
|
break
|
|
}
|
|
cursor = cursor + 2
|
|
codepoint = int32(escaped)
|
|
if escaped == 98 {
|
|
codepoint = 8
|
|
}
|
|
if escaped == 102 {
|
|
codepoint = 12
|
|
}
|
|
if escaped == 110 {
|
|
codepoint = 10
|
|
}
|
|
if escaped == 114 {
|
|
codepoint = 13
|
|
}
|
|
if escaped == 116 {
|
|
codepoint = 9
|
|
}
|
|
if escaped == 117 {
|
|
codepoint = StdJsonScan_ReadHex4(text, cursor, end)
|
|
if codepoint < 0 {
|
|
break
|
|
}
|
|
cursor = cursor + 4
|
|
if codepoint >= 55296 && codepoint <= 56319 && cursor+6 <= end && text[cursor] == 92 && text[(cursor+1)] == 117 {
|
|
low := StdJsonScan_ReadHex4(text, cursor+2, end)
|
|
if low >= 56320 && low <= 57343 {
|
|
codepoint = (65536 + ((codepoint - 55296) * 1024)) + (low - 56320)
|
|
cursor = cursor + 6
|
|
}
|
|
}
|
|
if codepoint >= 55296 && codepoint <= 57343 {
|
|
codepoint = 65533
|
|
}
|
|
}
|
|
length = StdJsonScan_AppendUtf8(output, length, codepoint)
|
|
} else {
|
|
start := cursor
|
|
for cursor < end {
|
|
byte := text[cursor]
|
|
if byte == 34 || byte == 92 || byte < 32 {
|
|
break
|
|
}
|
|
cursor++
|
|
}
|
|
size := cursor - start
|
|
if size >= int32(int64(len(output)))-length {
|
|
length = -1
|
|
} else {
|
|
{
|
|
var range_first_78 int32 = 0
|
|
range_last_78 := size - 1
|
|
i := range_first_78
|
|
for i <= range_last_78 {
|
|
output[(length + i)] = text[(start + i)]
|
|
if i == range_last_78 {
|
|
break
|
|
}
|
|
i++
|
|
}
|
|
}
|
|
length += size
|
|
}
|
|
}
|
|
}
|
|
output[0] = 0
|
|
return -1
|
|
}
|
|
|
|
func StdJsonScan_ReadStringValue(text string, at int32, max_bytes int32) JsonText {
|
|
span := StdJsonScan_ReadString(text, at)
|
|
if !span.Valid || max_bytes < 0 {
|
|
return JsonText{}
|
|
}
|
|
var out __type_838711075b90279a = __type_838711075b90279a{}
|
|
var value_0 *__type_838711075b90279a = &out
|
|
cursor := span.Start
|
|
start := cursor
|
|
for cursor < span.End {
|
|
if text[cursor] != 92 {
|
|
cursor++
|
|
continue
|
|
}
|
|
var value_1 bool = (out.Count+int64(cursor))-int64(start) > int64(max_bytes)
|
|
if !value_1 {
|
|
var value_2 bool = false
|
|
out.Data = append(out.Data, text[start:cursor]...)
|
|
out.Count = int64(len(out.Data))
|
|
out.Capacity = int64(cap(out.Data))
|
|
value_2 = true
|
|
value_1 = !value_2
|
|
}
|
|
if value_1 {
|
|
var value_3 JsonText = JsonText{}
|
|
value_0.Data = nil
|
|
value_0.Capacity = 0
|
|
value_0.Count = 0
|
|
return value_3
|
|
}
|
|
escaped := text[(cursor + 1)]
|
|
cursor += 2
|
|
codepoint := int32(escaped)
|
|
if escaped == 98 {
|
|
codepoint = 8
|
|
}
|
|
if escaped == 102 {
|
|
codepoint = 12
|
|
}
|
|
if escaped == 110 {
|
|
codepoint = 10
|
|
}
|
|
if escaped == 114 {
|
|
codepoint = 13
|
|
}
|
|
if escaped == 116 {
|
|
codepoint = 9
|
|
}
|
|
if escaped == 117 {
|
|
codepoint = StdJsonScan_ReadHex4(text, cursor, span.End)
|
|
cursor += 4
|
|
if codepoint >= 55296 && codepoint <= 56319 && cursor+6 <= span.End && text[cursor] == 92 && text[(cursor+1)] == 117 {
|
|
low := StdJsonScan_ReadHex4(text, cursor+2, span.End)
|
|
if low >= 56320 && low <= 57343 {
|
|
codepoint = ((65536 + ((codepoint - 55296) * 1024)) + low) - 56320
|
|
cursor += 6
|
|
}
|
|
}
|
|
if codepoint >= 55296 && codepoint <= 57343 {
|
|
codepoint = 65533
|
|
}
|
|
}
|
|
var encoded [5]uint8
|
|
_ = encoded
|
|
size := StdJsonScan_AppendUtf8(encoded[0:5:5], 0, codepoint)
|
|
var value_4 bool = size < 0 || out.Count+int64(size) > int64(max_bytes)
|
|
if !value_4 {
|
|
var value_5 bool = false
|
|
out.Data = append(out.Data, string(encoded[0:size:size])...)
|
|
out.Count = int64(len(out.Data))
|
|
out.Capacity = int64(cap(out.Data))
|
|
value_5 = true
|
|
value_4 = !value_5
|
|
}
|
|
if value_4 {
|
|
var value_6 JsonText = JsonText{}
|
|
value_0.Data = nil
|
|
value_0.Capacity = 0
|
|
value_0.Count = 0
|
|
return value_6
|
|
}
|
|
start = cursor
|
|
}
|
|
var value_7 bool = (out.Count+int64(span.End))-int64(start) > int64(max_bytes)
|
|
if !value_7 {
|
|
var value_8 bool = false
|
|
out.Data = append(out.Data, text[start:span.End]...)
|
|
out.Count = int64(len(out.Data))
|
|
out.Capacity = int64(cap(out.Data))
|
|
value_8 = true
|
|
value_7 = !value_8
|
|
}
|
|
if value_7 {
|
|
var value_9 JsonText = JsonText{}
|
|
value_0.Data = nil
|
|
value_0.Capacity = 0
|
|
value_0.Count = 0
|
|
return value_9
|
|
}
|
|
var value_10 __type_838711075b90279a = out
|
|
out.Data = nil
|
|
out.Capacity = 0
|
|
out.Count = 0
|
|
var value_11 JsonText = JsonText{Value: value_10, Valid: true}
|
|
value_0.Data = nil
|
|
value_0.Capacity = 0
|
|
value_0.Count = 0
|
|
return value_11
|
|
}
|
|
|
|
func StdJsonScan_SpanEqualsASCII(text string, span JsonSpan, expected string) bool {
|
|
if !span.Valid || span.End-span.Start != int32(int64(len(expected))) {
|
|
return false
|
|
}
|
|
var index int32 = 0
|
|
for index < int32(int64(len(expected))) {
|
|
if text[(span.Start+index)] != expected[index] {
|
|
return false
|
|
}
|
|
index = index + 1
|
|
}
|
|
return true
|
|
}
|
|
|
|
func StdJsonScan_SpanContainsFoldASCII(text string, span JsonSpan, needle string) bool {
|
|
if !span.Valid {
|
|
return false
|
|
}
|
|
if int32(int64(len(needle))) == 0 {
|
|
return true
|
|
}
|
|
if int32(int64(len(needle))) > span.End-span.Start {
|
|
return false
|
|
}
|
|
start := span.Start
|
|
for start <= span.End-int32(int64(len(needle))) {
|
|
var index int32 = 0
|
|
same := true
|
|
for index < int32(int64(len(needle))) {
|
|
if StdText_LowerASCII(text[(start+index)]) != StdText_LowerASCII(needle[index]) {
|
|
same = false
|
|
break
|
|
}
|
|
index = index + 1
|
|
}
|
|
if same {
|
|
return true
|
|
}
|
|
start = start + 1
|
|
}
|
|
return false
|
|
}
|
|
|
|
func StdJsonScan_ReadNumber(text string, at int32) JsonNumber {
|
|
var result JsonNumber = JsonNumber{}
|
|
cursor := at
|
|
if cursor < 0 || cursor >= int32(int64(len(text))) {
|
|
return result
|
|
}
|
|
negative := false
|
|
if text[cursor] == 45 {
|
|
negative = true
|
|
cursor = cursor + 1
|
|
if cursor >= int32(int64(len(text))) {
|
|
return result
|
|
}
|
|
}
|
|
if text[cursor] == 48 {
|
|
cursor = cursor + 1
|
|
var value_0 bool = cursor < int32(int64(len(text)))
|
|
if value_0 {
|
|
var value_1 bool = StdJsonScan_Digit(text[cursor])
|
|
value_0 = value_1
|
|
}
|
|
if value_0 {
|
|
return result
|
|
}
|
|
} else {
|
|
if text[cursor] < 49 || text[cursor] > 57 {
|
|
return result
|
|
}
|
|
for {
|
|
var value_2 bool = cursor < int32(int64(len(text)))
|
|
if value_2 {
|
|
var value_3 bool = StdJsonScan_Digit(text[cursor])
|
|
value_2 = value_3
|
|
}
|
|
if !value_2 {
|
|
break
|
|
}
|
|
result.Value = (result.Value * 10.0) + float64((text[cursor] - 48))
|
|
cursor = cursor + 1
|
|
}
|
|
}
|
|
if cursor < int32(int64(len(text))) && text[cursor] == 46 {
|
|
cursor = cursor + 1
|
|
var value_4 bool = cursor >= int32(int64(len(text)))
|
|
if !value_4 {
|
|
var value_5 bool = StdJsonScan_Digit(text[cursor])
|
|
value_4 = !value_5
|
|
}
|
|
if value_4 {
|
|
return result
|
|
}
|
|
var scale float64 = 0.1
|
|
for {
|
|
var value_6 bool = cursor < int32(int64(len(text)))
|
|
if value_6 {
|
|
var value_7 bool = StdJsonScan_Digit(text[cursor])
|
|
value_6 = value_7
|
|
}
|
|
if !value_6 {
|
|
break
|
|
}
|
|
result.Value = result.Value + (float64((text[cursor] - 48)) * scale)
|
|
scale = scale * 0.1
|
|
cursor = cursor + 1
|
|
}
|
|
}
|
|
if cursor < int32(int64(len(text))) && (text[cursor] == 101 || text[cursor] == 69) {
|
|
cursor = cursor + 1
|
|
exponent_negative := false
|
|
if cursor < int32(int64(len(text))) && (text[cursor] == 45 || text[cursor] == 43) {
|
|
exponent_negative = text[cursor] == 45
|
|
cursor = cursor + 1
|
|
}
|
|
var value_8 bool = cursor >= int32(int64(len(text)))
|
|
if !value_8 {
|
|
var value_9 bool = StdJsonScan_Digit(text[cursor])
|
|
value_8 = !value_9
|
|
}
|
|
if value_8 {
|
|
return result
|
|
}
|
|
var exponent int32 = 0
|
|
for {
|
|
var value_10 bool = cursor < int32(int64(len(text)))
|
|
if value_10 {
|
|
var value_11 bool = StdJsonScan_Digit(text[cursor])
|
|
value_10 = value_11
|
|
}
|
|
if !value_10 {
|
|
break
|
|
}
|
|
if exponent > 30 {
|
|
return result
|
|
}
|
|
exponent = (exponent * 10) + int32((text[cursor] - 48))
|
|
if exponent > 308 {
|
|
return result
|
|
}
|
|
cursor = cursor + 1
|
|
}
|
|
for exponent > 0 {
|
|
if exponent_negative {
|
|
result.Value = result.Value / 10.0
|
|
} else {
|
|
result.Value = result.Value * 10.0
|
|
}
|
|
exponent = exponent - 1
|
|
}
|
|
}
|
|
if result.Value > 1.7976931348623157e308 {
|
|
return result
|
|
}
|
|
if negative {
|
|
result.Value = -result.Value
|
|
}
|
|
result.After = cursor
|
|
result.Valid = true
|
|
return result
|
|
}
|
|
|
|
func StdJsonScan_MatchLiteral(text string, at int32, literal string) bool {
|
|
if at < 0 || int32(int64(len(literal))) > int32(int64(len(text)))-at {
|
|
return false
|
|
}
|
|
var index int32 = 0
|
|
for index < int32(int64(len(literal))) {
|
|
if text[(at+index)] != literal[index] {
|
|
return false
|
|
}
|
|
index = index + 1
|
|
}
|
|
return true
|
|
}
|
|
|
|
func StdJsonScan_ValueEnd(text string, at int32, depth int32) int32 {
|
|
cursor := StdJsonScan_Space(text, at)
|
|
if depth > 64 || cursor < 0 || cursor >= int32(int64(len(text))) {
|
|
return -1
|
|
}
|
|
ch := text[cursor]
|
|
if ch == 34 {
|
|
span := StdJsonScan_ReadString(text, cursor)
|
|
if span.Valid {
|
|
return span.After
|
|
}
|
|
return -1
|
|
}
|
|
if ch == 123 || ch == 91 {
|
|
object := ch == 123
|
|
var close uint8 = 93
|
|
if object {
|
|
close = 125
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
if cursor < int32(int64(len(text))) && text[cursor] == close {
|
|
return cursor + 1
|
|
}
|
|
for cursor < int32(int64(len(text))) {
|
|
if object {
|
|
key := StdJsonScan_ReadString(text, cursor)
|
|
if !key.Valid {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, key.After)
|
|
if cursor >= int32(int64(len(text))) || text[cursor] != 58 {
|
|
return -1
|
|
}
|
|
cursor = cursor + 1
|
|
}
|
|
cursor = StdJsonScan_ValueEnd(text, cursor, depth+1)
|
|
if cursor < 0 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor)
|
|
if cursor >= int32(int64(len(text))) {
|
|
return -1
|
|
}
|
|
if text[cursor] == close {
|
|
return cursor + 1
|
|
}
|
|
if text[cursor] != 44 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
}
|
|
return -1
|
|
}
|
|
if StdJsonScan_MatchLiteral(text, cursor, "true") {
|
|
return cursor + 4
|
|
}
|
|
if StdJsonScan_MatchLiteral(text, cursor, "false") {
|
|
return cursor + 5
|
|
}
|
|
if StdJsonScan_MatchLiteral(text, cursor, "null") {
|
|
return cursor + 4
|
|
}
|
|
number := StdJsonScan_ReadNumber(text, cursor)
|
|
if number.Valid {
|
|
return number.After
|
|
}
|
|
return -1
|
|
}
|
|
|
|
func StdJsonScan_FieldAt(text string, object_at int32, name string) int32 {
|
|
cursor := StdJsonScan_Space(text, object_at)
|
|
if cursor < 0 || cursor >= int32(int64(len(text))) || text[cursor] != 123 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
for cursor < int32(int64(len(text))) && text[cursor] != 125 {
|
|
key := StdJsonScan_ReadString(text, cursor)
|
|
if !key.Valid {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, key.After)
|
|
if cursor >= int32(int64(len(text))) || text[cursor] != 58 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
if StdJsonScan_SpanEqualsASCII(text, key, name) {
|
|
return cursor
|
|
}
|
|
cursor = StdJsonScan_ValueEnd(text, cursor, 0)
|
|
if cursor < 0 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor)
|
|
if cursor >= int32(int64(len(text))) || text[cursor] != 44 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
}
|
|
return -1
|
|
}
|
|
|
|
func StdJsonScan_ObjectPositions(text string, object_at int32, names []string, output []int32) bool {
|
|
if int64(len(output)) < int64(len(names)) {
|
|
return false
|
|
}
|
|
{
|
|
var range_first_3 int32 = 0
|
|
range_last_3 := int32(int64(len(names))) - 1
|
|
i := range_first_3
|
|
_ = i
|
|
for i <= range_last_3 {
|
|
output[i] = -1
|
|
if i == range_last_3 {
|
|
break
|
|
}
|
|
i++
|
|
}
|
|
}
|
|
cursor := StdJsonScan_Space(text, object_at)
|
|
if cursor < 0 || cursor >= int32(int64(len(text))) || text[cursor] != 123 {
|
|
return false
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
if cursor < int32(int64(len(text))) && text[cursor] == 125 {
|
|
return true
|
|
}
|
|
for cursor < int32(int64(len(text))) {
|
|
key := StdJsonScan_ReadString(text, cursor)
|
|
if !key.Valid {
|
|
return false
|
|
}
|
|
cursor = StdJsonScan_Space(text, key.After)
|
|
if cursor >= int32(int64(len(text))) || text[cursor] != 58 {
|
|
return false
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
{
|
|
var range_first_24 int32 = 0
|
|
range_last_24 := int32(int64(len(names))) - 1
|
|
i := range_first_24
|
|
_ = i
|
|
for i <= range_last_24 {
|
|
var value_0 bool = output[i] < 0
|
|
var value_1 bool = value_0
|
|
if value_1 {
|
|
var value_2 bool = StdJsonScan_SpanEqualsASCII(text, key, names[i])
|
|
value_1 = value_2
|
|
}
|
|
if value_1 {
|
|
output[i] = cursor
|
|
}
|
|
if i == range_last_24 {
|
|
break
|
|
}
|
|
i++
|
|
}
|
|
}
|
|
cursor = StdJsonScan_ValueEnd(text, cursor, 0)
|
|
if cursor < 0 {
|
|
return false
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor)
|
|
if cursor >= int32(int64(len(text))) {
|
|
return false
|
|
}
|
|
if text[cursor] == 125 {
|
|
return true
|
|
}
|
|
if text[cursor] != 44 {
|
|
return false
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
}
|
|
return false
|
|
}
|
|
|
|
func StdJsonScan_ElementAt(text string, array_at int32, index int32) int32 {
|
|
cursor := StdJsonScan_Space(text, array_at)
|
|
if cursor < 0 || cursor >= int32(int64(len(text))) || text[cursor] != 91 || index < 0 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
var count int32 = 0
|
|
for cursor < int32(int64(len(text))) && text[cursor] != 93 {
|
|
if count == index {
|
|
return cursor
|
|
}
|
|
cursor = StdJsonScan_ValueEnd(text, cursor, 0)
|
|
if cursor < 0 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor)
|
|
if cursor >= int32(int64(len(text))) || text[cursor] != 44 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
count = count + 1
|
|
}
|
|
return -1
|
|
}
|
|
|
|
func StdJsonScan_ArrayPositions(text string, array_at int32, output []int32) int32 {
|
|
var ranges []JsonRange = nil
|
|
var previous []JsonRange = nil
|
|
return StdJsonScan_WalkArray(text, array_at, output, ranges, "", previous)
|
|
}
|
|
|
|
func StdJsonScan_ArrayRanges(text string, array_at int32, output []JsonRange) int32 {
|
|
var positions []int32 = nil
|
|
var previous []JsonRange = nil
|
|
return StdJsonScan_WalkArray(text, array_at, positions, output, "", previous)
|
|
}
|
|
|
|
func StdJsonScan_ArrayRangesReuse(text string, array_at int32, output []JsonRange, previous_text string, previous_ranges []JsonRange) int32 {
|
|
var positions []int32 = nil
|
|
return StdJsonScan_WalkArray(text, array_at, positions, output, previous_text, previous_ranges)
|
|
}
|
|
|
|
func StdJsonScan_WalkArray(text string, array_at int32, positions []int32, ranges []JsonRange, previous_text string, previous_ranges []JsonRange) int32 {
|
|
cursor := StdJsonScan_Space(text, array_at)
|
|
if cursor < 0 || cursor >= int32(int64(len(text))) || text[cursor] != 91 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
if cursor < int32(int64(len(text))) && text[cursor] == 93 {
|
|
return 0
|
|
}
|
|
var count int32 = 0
|
|
for cursor < int32(int64(len(text))) {
|
|
start := cursor
|
|
if count < int32(int64(len(positions))) {
|
|
positions[count] = start
|
|
}
|
|
var after int32 = -1
|
|
if count < int32(int64(len(previous_ranges))) {
|
|
old := previous_ranges[count]
|
|
if old.Start >= 0 && old.End > old.Start && old.End <= int32(int64(len(previous_text))) {
|
|
size := old.End - old.Start
|
|
if size <= int32(int64(len(text)))-start && text[start:(start+size)] == previous_text[old.Start:old.End] {
|
|
boundary := StdJsonScan_Space(text, start+size)
|
|
if boundary < int32(int64(len(text))) && (text[boundary] == 44 || text[boundary] == 93) {
|
|
after = start + size
|
|
}
|
|
}
|
|
}
|
|
}
|
|
var value_0 int32 = 0
|
|
if after >= 0 {
|
|
value_0 = after
|
|
} else {
|
|
var value_1 int32 = StdJsonScan_ValueEnd(text, cursor, 0)
|
|
value_0 = value_1
|
|
}
|
|
cursor = value_0
|
|
if cursor < 0 {
|
|
return -1
|
|
}
|
|
if count < int32(int64(len(ranges))) {
|
|
ranges[count] = JsonRange{Start: start, End: cursor}
|
|
}
|
|
count++
|
|
cursor = StdJsonScan_Space(text, cursor)
|
|
if cursor >= int32(int64(len(text))) {
|
|
return -1
|
|
}
|
|
if text[cursor] == 93 {
|
|
return count
|
|
}
|
|
if text[cursor] != 44 {
|
|
return -1
|
|
}
|
|
cursor = StdJsonScan_Space(text, cursor+1)
|
|
if cursor >= int32(int64(len(text))) || text[cursor] == 93 {
|
|
return -1
|
|
}
|
|
}
|
|
return -1
|
|
}
|
|
|
|
func StdJsonScan_ArrayCount(text string, array_at int32) int32 {
|
|
var positions []int32 = nil
|
|
return StdJsonScan_ArrayPositions(text, array_at, positions)
|
|
}
|