Skip to content

Commit

Permalink
refactor: Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
romshark committed Jan 15, 2022
1 parent 1465ebc commit c4392a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
13 changes: 2 additions & 11 deletions jscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ func Validate(s string) Error {
}
i.expect = expectValOrArrTerm

i.ValueEnd = -1

i.KeyStart, i.KeyEnd = -1, -1

i.st.Push(stack.NodeTypeArray, 0, 0, 0)
Expand All @@ -331,16 +329,12 @@ func Validate(s string) Error {
i.errCode = ErrorCodeMalformedNumber
return i.getError()
}
i.ValueEnd += i.ValueStart

i.ValueStart += i.ValueEnd
i.KeyStart, i.KeyEnd = -1, -1
i.ValueStart = i.ValueEnd

case '"': // String
i.ValueStart++
i.ValueEnd = strfind.IndexTerm(s, i.ValueStart)
i.ValueEnd = strfind.IndexTerm(s, i.ValueStart+1)
if i.ValueEnd < 0 {
i.ValueStart--
i.errCode = ErrorCodeUnexpectedEOF
return i.getError()
}
Expand All @@ -350,7 +344,6 @@ func Validate(s string) Error {
// Array item string value
if i.expect != expectValOrArrTerm {
i.errCode = ErrorCodeUnexpectedToken
i.ValueStart--
return i.getError()
}
i.expect = expectCommaOrArrTerm
Expand All @@ -359,7 +352,6 @@ func Validate(s string) Error {
// String field value
if i.expect != expectVal {
i.errCode = ErrorCodeUnexpectedToken
i.ValueStart--
return i.getError()
}
if t != nil {
Expand All @@ -376,7 +368,6 @@ func Validate(s string) Error {
// Key
if i.expect != expectKeyOrObjTerm {
i.errCode = ErrorCodeUnexpectedToken
i.ValueStart--
return i.getError()
}
i.expect = expectVal
Expand Down
13 changes: 2 additions & 11 deletions jscan_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@ func ValidateBytes(s []byte) ErrorBytes {
}
i.expect = expectValOrArrTerm

i.ValueEnd = -1

i.KeyStart, i.KeyEnd = -1, -1

i.st.Push(stack.NodeTypeArray, 0, 0, 0)
Expand All @@ -325,16 +323,12 @@ func ValidateBytes(s []byte) ErrorBytes {
i.errCode = ErrorCodeMalformedNumber
return i.getError()
}
i.ValueEnd += i.ValueStart

i.ValueStart += i.ValueEnd
i.KeyStart, i.KeyEnd = -1, -1
i.ValueStart = i.ValueEnd

case '"': // String
i.ValueStart++
i.ValueEnd = strfind.IndexTermBytes(s, i.ValueStart)
i.ValueEnd = strfind.IndexTermBytes(s, i.ValueStart+1)
if i.ValueEnd < 0 {
i.ValueStart--
i.errCode = ErrorCodeUnexpectedEOF
return i.getError()
}
Expand All @@ -344,7 +338,6 @@ func ValidateBytes(s []byte) ErrorBytes {
// Array item string value
if i.expect != expectValOrArrTerm {
i.errCode = ErrorCodeUnexpectedToken
i.ValueStart--
return i.getError()
}
i.expect = expectCommaOrArrTerm
Expand All @@ -353,7 +346,6 @@ func ValidateBytes(s []byte) ErrorBytes {
// String field value
if i.expect != expectVal {
i.errCode = ErrorCodeUnexpectedToken
i.ValueStart--
return i.getError()
}
if t != nil {
Expand All @@ -370,7 +362,6 @@ func ValidateBytes(s []byte) ErrorBytes {
// Key
if i.expect != expectKeyOrObjTerm {
i.errCode = ErrorCodeUnexpectedToken
i.ValueStart--
return i.getError()
}
i.expect = expectVal
Expand Down

0 comments on commit c4392a6

Please sign in to comment.