mirror of https://github.com/nlohmann/json
PrettyPrinter: Check if match is valid before accessing group (#3920)
parent
4c6cde72e5
commit
da6b908c4f
|
@ -14,19 +14,19 @@ class JsonValuePrinter:
|
||||||
return self.val
|
return self.val
|
||||||
|
|
||||||
def json_lookup_function(val):
|
def json_lookup_function(val):
|
||||||
m = ns_pattern.fullmatch(val.type.strip_typedefs().name)
|
if m := ns_pattern.fullmatch(str(val.type.strip_typedefs().name)):
|
||||||
name = m.group('name')
|
name = m.group('name')
|
||||||
if name and name.startswith('basic_json<') and name.endswith('>'):
|
if name and name.startswith('basic_json<') and name.endswith('>'):
|
||||||
m = ns_pattern.fullmatch(str(val['m_type']))
|
m = ns_pattern.fullmatch(str(val['m_type']))
|
||||||
t = m.group('name')
|
t = m.group('name')
|
||||||
if t and t.startswith('detail::value_t::'):
|
if t and t.startswith('detail::value_t::'):
|
||||||
try:
|
try:
|
||||||
union_val = val['m_value'][t.removeprefix('detail::value_t::')]
|
union_val = val['m_value'][t.removeprefix('detail::value_t::')]
|
||||||
if union_val.type.code == gdb.TYPE_CODE_PTR:
|
if union_val.type.code == gdb.TYPE_CODE_PTR:
|
||||||
return gdb.default_visualizer(union_val.dereference())
|
return gdb.default_visualizer(union_val.dereference())
|
||||||
else:
|
else:
|
||||||
return JsonValuePrinter(union_val)
|
return JsonValuePrinter(union_val)
|
||||||
except Exception:
|
except Exception:
|
||||||
return JsonValuePrinter(val['m_type'])
|
return JsonValuePrinter(val['m_type'])
|
||||||
|
|
||||||
gdb.pretty_printers.append(json_lookup_function)
|
gdb.pretty_printers.append(json_lookup_function)
|
||||||
|
|
Loading…
Reference in New Issue