@@ -480,40 +480,58 @@ def is_fundamental(type_):
480
480
(cpptypes .volatile_t , cpptypes .const_t ))
481
481
482
482
483
+ def _normalize (equivalences ):
484
+ return [
485
+ eq .replace (' ' , '' ).replace ("::std" , "std" ) for eq in equivalences
486
+ ]
487
+
488
+
483
489
string_equivalences = [
484
490
(
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
+ ]
488
497
489
498
wstring_equivalences = [
490
499
(
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
+ ]
494
506
495
507
ostream_equivalences = [
496
- '::std::basic_ostream<char,std::char_traits<char>>' ,
508
+ '::std::basic_ostream<char, std::char_traits<char>>' ,
497
509
'::std::basic_ostream<char>' , '::std::ostream' ]
498
510
499
511
wostream_equivalences = [
500
- '::std::basic_ostream<wchar_t,std::char_traits<wchar_t>>' ,
512
+ '::std::basic_ostream<wchar_t, std::char_traits<wchar_t>>' ,
501
513
'::std::basic_ostream<wchar_t>' , '::std::wostream' ]
502
514
503
515
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
+
504
522
def is_std_string (type_ ):
505
523
"""
506
524
Returns True, if type represents C++ `std::string`, False otherwise.
507
525
508
526
"""
509
527
510
528
if isinstance (type_ , str ):
511
- return type_ in string_equivalences
529
+ return _normalize ( type_ ) in normalized_string_equivalences
512
530
513
531
type_ = remove_alias (type_ )
514
532
type_ = remove_reference (type_ )
515
533
type_ = remove_cv (type_ )
516
- return type_ .decl_string . replace ( ' ' , '' ) in string_equivalences
534
+ return _normalize ( type_ .decl_string ) in normalized_string_equivalences
517
535
518
536
519
537
def is_std_wstring (type_ ):
@@ -523,12 +541,12 @@ def is_std_wstring(type_):
523
541
"""
524
542
525
543
if isinstance (type_ , str ):
526
- return type_ in wstring_equivalences
544
+ return _normalize ( type_ ) in normalized_wstring_equivalences
527
545
528
546
type_ = remove_alias (type_ )
529
547
type_ = remove_reference (type_ )
530
548
type_ = remove_cv (type_ )
531
- return type_ .decl_string . replace ( ' ' , '' ) in wstring_equivalences
549
+ return _normalize ( type_ .decl_string ) in normalized_wstring_equivalences
532
550
533
551
534
552
def is_std_ostream (type_ ):
@@ -538,12 +556,12 @@ def is_std_ostream(type_):
538
556
"""
539
557
540
558
if isinstance (type_ , str ):
541
- return type_ in ostream_equivalences
559
+ return _normalize ( type_ ) in normalized_ostream_equivalences
542
560
543
561
type_ = remove_alias (type_ )
544
562
type_ = remove_reference (type_ )
545
563
type_ = remove_cv (type_ )
546
- return type_ .decl_string . replace ( ' ' , '' ) in ostream_equivalences
564
+ return _normalize ( type_ .decl_string ) in normalized_ostream_equivalences
547
565
548
566
549
567
def is_std_wostream (type_ ):
@@ -553,9 +571,9 @@ def is_std_wostream(type_):
553
571
"""
554
572
555
573
if isinstance (type_ , str ):
556
- return type_ in wostream_equivalences
574
+ return _normalize ( type_ ) in normalized_wostream_equivalences
557
575
558
576
type_ = remove_alias (type_ )
559
577
type_ = remove_reference (type_ )
560
578
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