mirror of
https://github.com/nlohmann/json.git
synced 2025-07-31 10:24:23 +03:00
fixes issue 4691 (#4693)
* bugfix removeprefix not available in python version < 3.9 there was a problem in my cLion gdb that comes with python version 3.8. the pretty printer script do not work because the removeprefix function is added in version 3.9. therefore we need a fix for that. Signed-off-by: Matthias Popp <mpopp@arri.at> * fix indentation, use the same indentation size at in class JsonValuePrinter the indentation size was a mix up, we should use always the same indentation size of 4 Signed-off-by: Matthias Popp <mpopp@arri.at> * use prefix as variable easier handling or easier to change Signed-off-by: Matthias Popp <mpopp@arri.at> * add variables for easier access Signed-off-by: Matthias Popp <mpopp@arri.at> --------- Signed-off-by: Matthias Popp <mpopp@arri.at> Co-authored-by: Matthias Popp <mpopp@arri.at>
This commit is contained in:
@ -15,18 +15,21 @@ class JsonValuePrinter:
|
|||||||
|
|
||||||
def json_lookup_function(val):
|
def json_lookup_function(val):
|
||||||
if m := ns_pattern.fullmatch(str(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_data"]['m_type']))
|
m_data = val['m_data']
|
||||||
t = m.group('name')
|
m_type = m_data['m_type']
|
||||||
if t and t.startswith('detail::value_t::'):
|
m = ns_pattern.fullmatch(str(m_type))
|
||||||
try:
|
t = m.group('name')
|
||||||
union_val = val["m_data"]['m_value'][t.removeprefix('detail::value_t::')]
|
prefix = 'detail::value_t::'
|
||||||
if union_val.type.code == gdb.TYPE_CODE_PTR:
|
if t and t.startswith(prefix):
|
||||||
return gdb.default_visualizer(union_val.dereference())
|
try:
|
||||||
else:
|
union_val = m_data['m_value'][t.replace(prefix, '', 1)]
|
||||||
return JsonValuePrinter(union_val)
|
if union_val.type.code == gdb.TYPE_CODE_PTR:
|
||||||
except Exception:
|
return gdb.default_visualizer(union_val.dereference())
|
||||||
return JsonValuePrinter(val["m_data"]['m_type'])
|
else:
|
||||||
|
return JsonValuePrinter(union_val)
|
||||||
|
except Exception:
|
||||||
|
return JsonValuePrinter(m_type)
|
||||||
|
|
||||||
gdb.pretty_printers.append(json_lookup_function)
|
gdb.pretty_printers.append(json_lookup_function)
|
||||||
|
Reference in New Issue
Block a user