@@ -480,40 +480,58 @@ def is_fundamental(type_):
480480 (cpptypes .volatile_t , cpptypes .const_t ))
481481
482482
483+ def _normalize (equivalences ):
484+ return [
485+ eq .replace (' ' , '' ).replace ("::std" , "std" ) for eq in equivalences
486+ ]
487+
488+
483489string_equivalences = [
484490 (
485- '::std::basic_string<char,std::char_traits<char>,'
486- 'std::allocator<char>>' ),
487- '::std::basic_string<char>' , '::std::string' ]
491+ '::std::basic_string<char, std::char_traits<char>, '
492+ 'std::allocator<char>>'
493+ ),
494+ '::std::basic_string<char>' ,
495+ '::std::string'
496+ ]
488497
489498wstring_equivalences = [
490499 (
491- '::std::basic_string<wchar_t,std::char_traits<wchar_t>,' +
492- 'std::allocator<wchar_t>>' ),
493- '::std::basic_string<wchar_t>' , '::std::wstring' ]
500+ '::std::basic_string<wchar_t, std::char_traits<wchar_t>, '
501+ 'std::allocator<wchar_t>>'
502+ ),
503+ '::std::basic_string<wchar_t>' ,
504+ '::std::wstring'
505+ ]
494506
495507ostream_equivalences = [
496- '::std::basic_ostream<char,std::char_traits<char>>' ,
508+ '::std::basic_ostream<char, std::char_traits<char>>' ,
497509 '::std::basic_ostream<char>' , '::std::ostream' ]
498510
499511wostream_equivalences = [
500- '::std::basic_ostream<wchar_t,std::char_traits<wchar_t>>' ,
512+ '::std::basic_ostream<wchar_t, std::char_traits<wchar_t>>' ,
501513 '::std::basic_ostream<wchar_t>' , '::std::wostream' ]
502514
503515
516+ normalized_string_equivalences = _normalize (string_equivalences )
517+ normalized_wstring_equivalences = _normalize (wstring_equivalences )
518+ normalized_ostream_equivalences = _normalize (ostream_equivalences )
519+ normalized_wostream_equivalences = _normalize (wostream_equivalences )
520+
521+
504522def is_std_string (type_ ):
505523 """
506524 Returns True, if type represents C++ `std::string`, False otherwise.
507525
508526 """
509527
510528 if isinstance (type_ , str ):
511- return type_ in string_equivalences
529+ return _normalize ( type_ ) in normalized_string_equivalences
512530
513531 type_ = remove_alias (type_ )
514532 type_ = remove_reference (type_ )
515533 type_ = remove_cv (type_ )
516- return type_ .decl_string . replace ( ' ' , '' ) in string_equivalences
534+ return _normalize ( type_ .decl_string ) in normalized_string_equivalences
517535
518536
519537def is_std_wstring (type_ ):
@@ -523,12 +541,12 @@ def is_std_wstring(type_):
523541 """
524542
525543 if isinstance (type_ , str ):
526- return type_ in wstring_equivalences
544+ return _normalize ( type_ ) in normalized_wstring_equivalences
527545
528546 type_ = remove_alias (type_ )
529547 type_ = remove_reference (type_ )
530548 type_ = remove_cv (type_ )
531- return type_ .decl_string . replace ( ' ' , '' ) in wstring_equivalences
549+ return _normalize ( type_ .decl_string ) in normalized_wstring_equivalences
532550
533551
534552def is_std_ostream (type_ ):
@@ -538,12 +556,12 @@ def is_std_ostream(type_):
538556 """
539557
540558 if isinstance (type_ , str ):
541- return type_ in ostream_equivalences
559+ return _normalize ( type_ ) in normalized_ostream_equivalences
542560
543561 type_ = remove_alias (type_ )
544562 type_ = remove_reference (type_ )
545563 type_ = remove_cv (type_ )
546- return type_ .decl_string . replace ( ' ' , '' ) in ostream_equivalences
564+ return _normalize ( type_ .decl_string ) in normalized_ostream_equivalences
547565
548566
549567def is_std_wostream (type_ ):
@@ -553,9 +571,9 @@ def is_std_wostream(type_):
553571 """
554572
555573 if isinstance (type_ , str ):
556- return type_ in wostream_equivalences
574+ return _normalize ( type_ ) in normalized_wostream_equivalences
557575
558576 type_ = remove_alias (type_ )
559577 type_ = remove_reference (type_ )
560578 type_ = remove_cv (type_ )
561- return type_ .decl_string . replace ( ' ' , '' ) in wostream_equivalences
579+ return _normalize ( type_ .decl_string ) in normalized_wostream_equivalences
0 commit comments