19
19
20
20
std_namespaces = ('std' , 'stdext' , '__gnu_cxx' )
21
21
22
+ # Take into account different equivalences (with or without spaces)
23
+ string_equivalences = type_traits .string_equivalences + \
24
+ type_traits .normalized_string_equivalences
25
+ string_equivalences = [
26
+ v for v in string_equivalences if not v == "std::string" ]
27
+ wstring_equivalences = type_traits .wstring_equivalences + \
28
+ type_traits .normalized_wstring_equivalences
29
+ wstring_equivalences = [
30
+ v for v in wstring_equivalences if not v == "std::wstring" ]
31
+
32
+
33
+ def _replace_basic_string (cls_name ):
34
+ strings = {
35
+ "std::string" : string_equivalences ,
36
+ "std::wstring" : wstring_equivalences
37
+ }
38
+
39
+ new_name = cls_name
40
+ for short_name , long_names in strings .items ():
41
+ for lname in long_names :
42
+ new_name = new_name .replace (lname , short_name )
43
+
44
+ return new_name
45
+
22
46
23
47
class defaults_eraser (object ):
24
48
@@ -29,24 +53,7 @@ def normalize(self, type_str):
29
53
return type_str .replace (' ' , '' )
30
54
31
55
def replace_basic_string (self , cls_name ):
32
- # Replace all the variations of strings by the smallest one.
33
- strings = {
34
- "std::string" :
35
- [v for v in
36
- type_traits .normalized_string_equivalences
37
- if not v == "std::string" ],
38
- "std::wstring" :
39
- [v for v in
40
- type_traits .normalized_wstring_equivalences
41
- if not v == "std::wstring" ]
42
- }
43
-
44
- new_name = cls_name
45
- for short_name , long_names in strings .items ():
46
- for lname in long_names :
47
- new_name = new_name .replace (lname , short_name )
48
-
49
- return new_name
56
+ return _replace_basic_string (cls_name )
50
57
51
58
def decorated_call_prefix (self , cls_name , text , doit ):
52
59
has_text = cls_name .startswith (text )
@@ -69,7 +76,7 @@ def decorated_call_suffix(self, cls_name, text, doit):
69
76
def erase_call (self , cls_name ):
70
77
c_traits = find_container_traits (cls_name )
71
78
if not c_traits :
72
- return cls_name
79
+ return
73
80
return c_traits .remove_defaults (cls_name )
74
81
75
82
def no_std (self , cls_name ):
@@ -96,7 +103,6 @@ def erase_recursive(self, cls_name):
96
103
return self .no_end_const (cls_name )
97
104
98
105
def erase_allocator (self , cls_name , default_allocator = 'std::allocator' ):
99
- cls_name = self .replace_basic_string (cls_name )
100
106
c_name , c_args = templates .split (cls_name )
101
107
if len (c_args ) != 2 :
102
108
return
@@ -113,7 +119,6 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
113
119
c_name , [self .erase_recursive (value_type )])
114
120
115
121
def erase_container (self , cls_name , default_container_name = 'std::deque' ):
116
- cls_name = self .replace_basic_string (cls_name )
117
122
c_name , c_args = templates .split (cls_name )
118
123
if len (c_args ) != 2 :
119
124
return
@@ -130,7 +135,6 @@ def erase_container_compare(
130
135
cls_name ,
131
136
default_container_name = 'std::vector' ,
132
137
default_compare = 'std::less' ):
133
- cls_name = self .replace_basic_string (cls_name )
134
138
c_name , c_args = templates .split (cls_name )
135
139
if len (c_args ) != 3 :
136
140
return
@@ -150,7 +154,6 @@ def erase_compare_allocator(
150
154
cls_name ,
151
155
default_compare = 'std::less' ,
152
156
default_allocator = 'std::allocator' ):
153
- cls_name = self .replace_basic_string (cls_name )
154
157
c_name , c_args = templates .split (cls_name )
155
158
if len (c_args ) != 3 :
156
159
return
@@ -173,7 +176,6 @@ def erase_map_compare_allocator(
173
176
cls_name ,
174
177
default_compare = 'std::less' ,
175
178
default_allocator = 'std::allocator' ):
176
- cls_name = self .replace_basic_string (cls_name )
177
179
c_name , c_args = templates .split (cls_name )
178
180
if len (c_args ) != 4 :
179
181
return
@@ -203,7 +205,6 @@ def erase_map_compare_allocator(
203
205
self .erase_recursive (mapped_type )])
204
206
205
207
def erase_hash_allocator (self , cls_name ):
206
- cls_name = self .replace_basic_string (cls_name )
207
208
c_name , c_args = templates .split (cls_name )
208
209
if len (c_args ) < 3 :
209
210
return
@@ -241,7 +242,6 @@ def erase_hash_allocator(self, cls_name):
241
242
c_name , [self .erase_recursive (value_type )])
242
243
243
244
def erase_hashmap_compare_allocator (self , cls_name ):
244
- cls_name = self .replace_basic_string (cls_name )
245
245
c_name , c_args = templates .split (cls_name )
246
246
247
247
if self .unordered_maps_and_sets :
@@ -523,6 +523,7 @@ def remove_defaults(self, type_or_string):
523
523
name = self .class_declaration (type_or_string ).name
524
524
if not self .remove_defaults_impl :
525
525
return name
526
+ name = _replace_basic_string (name )
526
527
no_defaults = self .remove_defaults_impl (name )
527
528
if not no_defaults :
528
529
return name
0 commit comments