json-repair 0.52.4__py3-none-any.whl → 0.52.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -158,23 +158,32 @@ class JSONParser:
158
158
 
159
159
  def skip_to_character(self, character: str | list[str], idx: int = 0) -> int:
160
160
  """
161
- This function quickly iterates to find a character, syntactic sugar to make the code more concise
161
+ Advance from (self.index + idx) until we hit an *unescaped* target character.
162
+ Returns the offset (idx) from self.index to that position, or the distance to the end if not found.
162
163
  """
163
- try:
164
- char = self.json_str[self.index + idx]
165
- except IndexError:
166
- return idx
167
- character_list = character if isinstance(character, list) else [character]
168
- while char not in character_list:
169
- idx += 1
170
- try:
171
- char = self.json_str[self.index + idx]
172
- except IndexError:
173
- return idx
174
- if self.json_str[self.index + idx - 1] == "\\":
175
- # Ah shoot this was actually escaped, continue
176
- return self.skip_to_character(character, idx + 1)
177
- return idx
164
+ targets = set(character) if isinstance(character, list) else {character}
165
+ i = self.index + idx
166
+ n = len(self.json_str)
167
+ backslashes = 0 # count of consecutive '\' immediately before current char
168
+
169
+ while i < n:
170
+ ch = self.json_str[i]
171
+
172
+ if ch == "\\":
173
+ backslashes += 1
174
+ i += 1
175
+ continue
176
+
177
+ # ch is not a backslash; if it's a target and not escaped (even backslashes), we're done
178
+ if ch in targets and (backslashes % 2 == 0):
179
+ return i - self.index
180
+
181
+ # reset backslash run when we see a non-backslash
182
+ backslashes = 0
183
+ i += 1
184
+
185
+ # not found; return distance to end
186
+ return n - self.index
178
187
 
179
188
  def _log(self, text: str) -> None:
180
189
  window: int = 10
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_repair
3
- Version: 0.52.4
3
+ Version: 0.52.5
4
4
  Summary: A package to repair broken json strings
5
5
  Author-email: Stefano Baccianella <4247706+mangiucugna@users.noreply.github.com>
6
6
  License-Expression: MIT
@@ -2,7 +2,7 @@ json_repair/__init__.py,sha256=JdJIZNCKV3MfIviryqK8NH8yGssCta2-192CekcwH-o,174
2
2
  json_repair/__main__.py,sha256=EsJb-y89uZEvGQQg1GdIDWzfDwfOMvVekKEtdguQXCM,67
3
3
  json_repair/constants.py,sha256=cv2gvyosuq0me0600WyTysM9avrtfXPuXYR26tawcuo,158
4
4
  json_repair/json_context.py,sha256=WsMOjqpGSr6aaDONcrk8UFtTurzWon2Qq9AoBBYseoI,934
5
- json_repair/json_parser.py,sha256=S4Ogczq42CiYbuF06EsDGkVJx05ePgTvrKIUQsZrBzM,7674
5
+ json_repair/json_parser.py,sha256=vy5Z8aiJUVhVmvYEgy0dkYy5WgUmyOeS6PEFiR3cW44,7948
6
6
  json_repair/json_repair.py,sha256=sDhXzDZxu0QmaFzICPTtf_q7yOY1A1Lf_iQG6Potsco,11572
7
7
  json_repair/object_comparer.py,sha256=XKV3MRab8H7_v4sm-wpEa5le0XX9OeycWo5S-MFm-GI,1716
8
8
  json_repair/parse_array.py,sha256=-rh65JcfT-FtXiR6s8RYlMfI-6LzVr08ytlDh6Z2CFE,2181
@@ -13,9 +13,9 @@ json_repair/parse_object.py,sha256=xMpO64sYW0JmUtW75BTD0EdPQjY7PYVgu4tHVXrWB6s,5
13
13
  json_repair/parse_string.py,sha256=banF0nNbONvO4C_SDQMDuCZO99UIQvKzRVki9xWVpfU,25686
14
14
  json_repair/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  json_repair/string_file_wrapper.py,sha256=tGkWBEUPE-CZPf4uSM5NE9oSDTpskX0myJiXsl-gbds,4333
16
- json_repair-0.52.4.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
17
- json_repair-0.52.4.dist-info/METADATA,sha256=x1rE0e8rADu8qoy4k4vE2iKEamEsfh-ykMu7xMngX7I,11027
18
- json_repair-0.52.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
- json_repair-0.52.4.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
20
- json_repair-0.52.4.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
21
- json_repair-0.52.4.dist-info/RECORD,,
16
+ json_repair-0.52.5.dist-info/licenses/LICENSE,sha256=wrjQo8MhNrNCicXtMe3MHmS-fx8AmQk1ue8AQwiiFV8,1076
17
+ json_repair-0.52.5.dist-info/METADATA,sha256=KcP9eWpjKssTAXdp8VSyVzzRnCgpGmK6AcdBnlZAT84,11027
18
+ json_repair-0.52.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
+ json_repair-0.52.5.dist-info/entry_points.txt,sha256=SNfge3zPSP-ASqriYU9r3NAPaXdseYr7ciPMKdV2uSw,57
20
+ json_repair-0.52.5.dist-info/top_level.txt,sha256=7-VZwZN2CgB_n0NlSLk-rEUFh8ug21lESbsblOYuZqw,12
21
+ json_repair-0.52.5.dist-info/RECORD,,