MCPcopy Create free account
hub / github.com/GRAnimated/MinecraftLCE / string_ids

Method string_ids

tools/lint.py:280–319  ·  view source on GitHub ↗
(self, id_file)

Source from the content-addressed store, hash-verified

278 self.c = "\n".join(new_lines)
279
280 def string_ids(self, id_file):
281 lines = self.c.splitlines()
282 new_lines = []
283 changed = False
284
285 for line in lines:
286 original_line = line
287
288 # 0xXXXXXXXX, signed, and unsigned ints
289 pattern = r'(0x[0-9A-Fa-f]{8}|\b-?\d+\b)'
290 matches = re.finditer(pattern, line)
291
292 for match in matches:
293 num_str = match.group(0)
294
295 if num_str.startswith("0x") or num_str.startswith("0X"):
296 hex_id = num_str[2:].upper()
297 else:
298 try:
299 num = int(num_str)
300 # handle signed wrapping if necessary
301 if num < 0:
302 num &= 0xFFFFFFFF
303 hex_id = f"{num:08X}"
304 except ValueError:
305 continue
306
307 new_line, const_name, found = self.replace_id(id_file, line, hex_id, num_str)
308
309 if found:
310 FAIL(f"{num_str} (0x{hex_id}) should be replaced with StringIDs::{const_name}!",
311 original_line, self.path)
312 if self.fix:
313 changed = True
314 line = new_line
315
316 new_lines.append(line)
317
318 if changed:
319 self.c = "\n".join(new_lines)
320
321
322 def replace_id(self, id_file, line, hex_id, num_str):

Callers 1

runMethod · 0.95

Calls 2

replace_idMethod · 0.95
FAILFunction · 0.85

Tested by

no test coverage detected