Skip to content

Commit

Permalink
simplify index seek end condition
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrd committed Mar 29, 2023
1 parent 609ee97 commit a9530f2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dictdatabase/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ def seek_index_through_value_bytes(json_bytes: bytes, index: int) -> int:
dict_depth -= 1
if dict_depth <= 0 and list_depth == 0:
return i + 1 + dict_depth # dict_depth is -1 in case: {"a": {}}
elif list_depth == 0 and ((dict_depth == 0 and (current == byte_codes.COMMA or current == byte_codes.NEWLINE)) or dict_depth == -1):
# Handle commas and newline as exit points
return i
elif list_depth == 0:
if dict_depth == -1:
return i
if dict_depth == 0 and current in [byte_codes.COMMA, byte_codes.NEWLINE]:
# Handle commas and newline as exit points
return i
i += 1

raise TypeError("Invalid JSON")
Expand Down

0 comments on commit a9530f2

Please sign in to comment.