88
99"""
1010
11+ import copy
1112import string
1213from . import cpptypes
1314from . import templates
1920
2021std_namespaces = ('std' , 'stdext' , '__gnu_cxx' )
2122
23+ # Take into account different equivalences (with or without spaces)
24+ string_equivalences = type_traits .string_equivalences + \
25+ type_traits .normalized_string_equivalences
26+ string_equivalences = [
27+ v for v in string_equivalences if not v == "std::string" ]
28+ wstring_equivalences = type_traits .wstring_equivalences + \
29+ type_traits .normalized_wstring_equivalences
30+ wstring_equivalences = [
31+ v for v in wstring_equivalences if not v == "std::wstring" ]
32+
33+
34+ def _replace_basic_string (cls_name ):
35+ strings = {
36+ "std::string" : string_equivalences ,
37+ "std::wstring" : wstring_equivalences
38+ }
39+
40+ new_name = copy .copy (cls_name )
41+ for short_name , long_names in strings .items ():
42+ for lname in long_names :
43+ new_name = new_name .replace (lname , short_name )
44+
45+ return new_name
46+
2247
2348class defaults_eraser (object ):
2449
@@ -29,24 +54,7 @@ def normalize(self, type_str):
2954 return type_str .replace (' ' , '' )
3055
3156 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
57+ return _replace_basic_string (cls_name )
5058
5159 def decorated_call_prefix (self , cls_name , text , doit ):
5260 has_text = cls_name .startswith (text )
@@ -96,7 +104,6 @@ def erase_recursive(self, cls_name):
96104 return self .no_end_const (cls_name )
97105
98106 def erase_allocator (self , cls_name , default_allocator = 'std::allocator' ):
99- cls_name = self .replace_basic_string (cls_name )
100107 c_name , c_args = templates .split (cls_name )
101108 if len (c_args ) != 2 :
102109 return
@@ -113,7 +120,6 @@ def erase_allocator(self, cls_name, default_allocator='std::allocator'):
113120 c_name , [self .erase_recursive (value_type )])
114121
115122 def erase_container (self , cls_name , default_container_name = 'std::deque' ):
116- cls_name = self .replace_basic_string (cls_name )
117123 c_name , c_args = templates .split (cls_name )
118124 if len (c_args ) != 2 :
119125 return
@@ -130,7 +136,6 @@ def erase_container_compare(
130136 cls_name ,
131137 default_container_name = 'std::vector' ,
132138 default_compare = 'std::less' ):
133- cls_name = self .replace_basic_string (cls_name )
134139 c_name , c_args = templates .split (cls_name )
135140 if len (c_args ) != 3 :
136141 return
@@ -150,7 +155,6 @@ def erase_compare_allocator(
150155 cls_name ,
151156 default_compare = 'std::less' ,
152157 default_allocator = 'std::allocator' ):
153- cls_name = self .replace_basic_string (cls_name )
154158 c_name , c_args = templates .split (cls_name )
155159 if len (c_args ) != 3 :
156160 return
@@ -173,7 +177,6 @@ def erase_map_compare_allocator(
173177 cls_name ,
174178 default_compare = 'std::less' ,
175179 default_allocator = 'std::allocator' ):
176- cls_name = self .replace_basic_string (cls_name )
177180 c_name , c_args = templates .split (cls_name )
178181 if len (c_args ) != 4 :
179182 return
@@ -203,7 +206,6 @@ def erase_map_compare_allocator(
203206 self .erase_recursive (mapped_type )])
204207
205208 def erase_hash_allocator (self , cls_name ):
206- cls_name = self .replace_basic_string (cls_name )
207209 c_name , c_args = templates .split (cls_name )
208210 if len (c_args ) < 3 :
209211 return
@@ -241,7 +243,6 @@ def erase_hash_allocator(self, cls_name):
241243 c_name , [self .erase_recursive (value_type )])
242244
243245 def erase_hashmap_compare_allocator (self , cls_name ):
244- cls_name = self .replace_basic_string (cls_name )
245246 c_name , c_args = templates .split (cls_name )
246247
247248 if self .unordered_maps_and_sets :
@@ -523,7 +524,8 @@ def remove_defaults(self, type_or_string):
523524 name = self .class_declaration (type_or_string ).name
524525 if not self .remove_defaults_impl :
525526 return name
526- no_defaults = self .remove_defaults_impl (name )
527+ cleaned_name = _replace_basic_string (name )
528+ no_defaults = self .remove_defaults_impl (cleaned_name )
527529 if not no_defaults :
528530 return name
529531 return no_defaults
0 commit comments