From 4f979d764ef7e42fee95619d6dc2a0cb085c0ded Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Thu, 7 May 2020 20:02:55 +0900 Subject: [PATCH] Refactor skipValue --- decode_struct.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/decode_struct.go b/decode_struct.go index e9bd700..13d510c 100644 --- a/decode_struct.go +++ b/decode_struct.go @@ -48,18 +48,20 @@ func (d *structDecoder) skipValue(buf []byte, cursor int) (int, error) { } case '"': cursor++ + for ; cursor < buflen; cursor++ { - switch buf[cursor] { - case '\\': - cursor++ - case '"': - if bracketCount == 0 && braceCount == 0 { - return cursor + 1, nil - } - goto QUOTE_END + if buf[cursor] != '"' { + continue } + if buf[cursor-1] == '\\' { + continue + } + if bracketCount == 0 && braceCount == 0 { + return cursor + 1, nil + } + break } - QUOTE_END: + } cursor++ }