File tree Expand file tree Collapse file tree 3 files changed +76
-1
lines changed Expand file tree Collapse file tree 3 files changed +76
-1
lines changed Original file line number Diff line number Diff line change @@ -417,6 +417,22 @@ namespace Rcpp {
417
417
bool operator !=( const Rcpp::String& other) const {
418
418
return get_sexp () != other.get_sexp () ;
419
419
}
420
+
421
+ bool operator ==( const StringProxy& other) const {
422
+ return get_sexp () == other.get ();
423
+ }
424
+
425
+ bool operator !=( const StringProxy& other) const {
426
+ return get_sexp () != other.get ();
427
+ }
428
+
429
+ bool operator ==( const const_StringProxy& other) const {
430
+ return get_sexp () == other.get ();
431
+ }
432
+
433
+ bool operator !=( const const_StringProxy& other) const {
434
+ return get_sexp () != other.get ();
435
+ }
420
436
421
437
bool operator >( const Rcpp::String& other ) const {
422
438
return strcmp ( get_cstring (), other.get_cstring () ) > 0 ;
@@ -501,7 +517,22 @@ namespace Rcpp {
501
517
SET_STRING_ELT ( res, 0 , data ) ;
502
518
return res ;
503
519
}
504
-
520
+
521
+ inline bool operator ==(const String::StringProxy& lhs, const String& rhs) {
522
+ return rhs == lhs;
523
+ }
524
+
525
+ inline bool operator !=(const String::StringProxy& lhs, const String& rhs) {
526
+ return rhs != lhs;
527
+ }
528
+
529
+ inline bool operator ==(const String::const_StringProxy& lhs, const String& rhs) {
530
+ return rhs == lhs;
531
+ }
532
+
533
+ inline bool operator !=(const String::const_StringProxy& lhs, const String& rhs) {
534
+ return rhs != lhs;
535
+ }
505
536
506
537
} // Rcpp
507
538
Original file line number Diff line number Diff line change @@ -63,6 +63,26 @@ List test_compare_Strings( String aa, String bb ){
63
63
) ;
64
64
}
65
65
66
+ // [[Rcpp::export]]
67
+ List test_compare_String_string_proxy ( String aa, CharacterVector bb ){
68
+ return List::create (
69
+ _[" a == b" ] = aa == bb[0 ],
70
+ _[" a != b" ] = aa != bb[0 ],
71
+ _[" b == a" ] = bb[0 ] == aa,
72
+ _[" b != a" ] = bb[0 ] != aa
73
+ ) ;
74
+ }
75
+
76
+ // [[Rcpp::export]]
77
+ List test_compare_String_const_string_proxy ( String aa, const CharacterVector bb ){
78
+ return List::create (
79
+ _[" a == b" ] = aa == bb[0 ],
80
+ _[" a != b" ] = aa != bb[0 ],
81
+ _[" b == a" ] = bb[0 ] == aa,
82
+ _[" b != a" ] = bb[0 ] != aa
83
+ ) ;
84
+ }
85
+
66
86
// [[Rcpp::export]]
67
87
String test_push_front (String x) {
68
88
x.push_front (" abc" );
Original file line number Diff line number Diff line change @@ -48,6 +48,30 @@ if (.runThisTest) {
48
48
)
49
49
checkEquals( res , target )
50
50
}
51
+
52
+ test.compare.String.string_proxy <- function (){
53
+ v <- c(" aab" )
54
+ res <- test_compare_String_string_proxy( " aaa" , v )
55
+ target <- list (
56
+ " a == b" = FALSE ,
57
+ " a != b" = TRUE ,
58
+ " b == a" = FALSE ,
59
+ " b != a" = TRUE
60
+ )
61
+ checkEquals( res , target )
62
+ }
63
+
64
+ test.compare.String.const_string_proxy <- function (){
65
+ v <- c(" aab" )
66
+ res <- test_compare_String_const_string_proxy( " aaa" , v )
67
+ target <- list (
68
+ " a == b" = FALSE ,
69
+ " a != b" = TRUE ,
70
+ " b == a" = FALSE ,
71
+ " b != a" = TRUE
72
+ )
73
+ checkEquals( res , target )
74
+ }
51
75
52
76
test.String.ctor <- function () {
53
77
res <- test_ctor(" abc" )
You can’t perform that action at this time.
0 commit comments