Skip to content

Commit e0bfd09

Browse files
committed
Merge pull request #27 from pendo-io/fix-stringend-escaping
Improve performance of PR #21
2 parents 81fa7c3 + b2c438f commit e0bfd09

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

parser.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ func nextValue(data []byte, skipComma bool) int {
3232
// Tries to find the end of string
3333
// Support if string contains escaped quote symbols.
3434
func stringEnd(data []byte) int {
35-
escaped := false
3635
for i, c := range data {
37-
switch c {
38-
case '\\':
39-
escaped = !escaped
40-
case '"':
41-
if !escaped {
42-
return i + 1
36+
if c == '"' {
37+
j := i - 1
38+
for {
39+
if j < 0 || data[j] != '\\' {
40+
return i + 1 // even number of backslashes
41+
}
42+
j--
43+
if j < 0 || data[j] != '\\' {
44+
break // odd number of backslashes
45+
}
46+
j--
4347
}
44-
escaped = false
45-
default:
46-
escaped = false
4748
}
4849
}
4950

0 commit comments

Comments
 (0)