@@ -71,39 +71,33 @@ def print_struct_val_starting_from(field_start_index, val, internal_dict):
71
71
t = val .GetType ()
72
72
has_field_names = type_has_field_names (t )
73
73
type_name = extract_type_name (t .GetName ())
74
- output = ""
75
-
76
- if not type_name .startswith ("(" ):
77
- # this is a tuple, so don't print the type name
78
- output += type_name
79
74
80
75
if has_field_names :
81
- output += " { \n "
76
+ template = "%(type_name)s {\n %(body)s\n }"
77
+ separator = ", \n "
82
78
else :
83
- output += "("
79
+ template = "%(type_name)s(%(body)s)"
80
+ separator = ", "
81
+
82
+ if type_name .startswith ("(" ):
83
+ # this is a tuple, so don't print the type name
84
+ type_name = ""
84
85
85
86
num_children = val .num_children
86
87
87
- for child_index in range (field_start_index , num_children ):
88
+ def render_child (child_index ):
89
+ this = ""
88
90
if has_field_names :
89
91
field_name = t .GetFieldAtIndex (child_index ).GetName ()
90
- output += field_name + ": "
92
+ this += field_name + ": "
91
93
92
94
field_val = val .GetChildAtIndex (child_index )
93
- output += print_val (field_val , internal_dict )
95
+ return this + print_val (field_val , internal_dict )
94
96
95
- if child_index != num_children - 1 :
96
- output += ", "
97
+ body = separator .join ([render_child (idx ) for idx in range (field_start_index , num_children )])
97
98
98
- if has_field_names :
99
- output += "\n "
100
-
101
- if has_field_names :
102
- output += "}"
103
- else :
104
- output += ")"
105
-
106
- return output
99
+ return template % {"type_name" : type_name ,
100
+ "body" : body }
107
101
108
102
109
103
def print_enum_val (val , internal_dict ):
0 commit comments