Remove goto statement

This commit is contained in:
Masaaki Goshima 2020-05-07 13:51:17 +09:00
parent 3574217593
commit ceed634708
2 changed files with 42 additions and 39 deletions

View File

@ -23,46 +23,46 @@ func (d *stringDecoder) decode(buf []byte, cursor int, p uintptr) (int, error) {
}
func (d *stringDecoder) decodeByte(buf []byte, cursor int) ([]byte, int, error) {
LOOP:
switch buf[cursor] {
case '\000':
return nil, 0, errors.New("unexpected error key delimiter")
case ' ', '\n', '\t', '\r':
cursor++
goto LOOP
case '"':
cursor++
start := cursor
for {
switch buf[cursor] {
case '\\':
cursor++
case '"':
literal := buf[start:cursor]
cursor++
return literal, cursor, nil
case '\000':
return nil, 0, errors.New("unexpected error string")
}
for {
switch buf[cursor] {
case '\000':
return nil, 0, errors.New("unexpected error key delimiter")
case ' ', '\n', '\t', '\r':
cursor++
case '"':
cursor++
start := cursor
for {
switch buf[cursor] {
case '\\':
cursor++
case '"':
literal := buf[start:cursor]
cursor++
return literal, cursor, nil
case '\000':
return nil, 0, errors.New("unexpected error string")
}
cursor++
}
return nil, 0, errors.New("unexpected error string")
case 'n':
buflen := len(buf)
if cursor+3 >= buflen {
return nil, 0, errors.New("unexpected error. invalid bool character")
}
if buf[cursor+1] != 'u' {
return nil, 0, errors.New("unexpected error. invalid bool character")
}
if buf[cursor+2] != 'l' {
return nil, 0, errors.New("unexpected error. invalid bool character")
}
if buf[cursor+3] != 'l' {
return nil, 0, errors.New("unexpected error. invalid bool character")
}
cursor += 5
return []byte{'n', 'u', 'l', 'l'}, cursor, nil
}
return nil, 0, errors.New("unexpected error string")
case 'n':
buflen := len(buf)
if cursor+3 >= buflen {
return nil, 0, errors.New("unexpected error. invalid bool character")
}
if buf[cursor+1] != 'u' {
return nil, 0, errors.New("unexpected error. invalid bool character")
}
if buf[cursor+2] != 'l' {
return nil, 0, errors.New("unexpected error. invalid bool character")
}
if buf[cursor+3] != 'l' {
return nil, 0, errors.New("unexpected error. invalid bool character")
}
cursor += 5
return []byte{'n', 'u', 'l', 'l'}, cursor, nil
}
return nil, 0, errors.New("unexpected error key delimiter")
}

View File

@ -27,8 +27,10 @@ func (d *structDecoder) skipValue(buf []byte, cursor int) (int, error) {
braceCount := 0
bracketCount := 0
buflen := len(buf)
for ; cursor < buflen; cursor++ {
for {
switch buf[cursor] {
case '\000':
return cursor, errors.New("unexpected error value")
case '{':
braceCount++
case '[':
@ -59,6 +61,7 @@ func (d *structDecoder) skipValue(buf []byte, cursor int) (int, error) {
}
QUOTE_END:
}
cursor++
}
return cursor, errors.New("unexpected error value")
}