1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
// #define RCPP_STRING_DEBUG_LEVEL 0
// #define RCPP_DEBUG_LEVEL 0
#include <Rcpp.h>
using namespace Rcpp ;
// [[Rcpp::export]]
String String_replace_all( String z, String x, String y){
z.replace_all( x, y ) ;
return z ;
}
// [[Rcpp::export]]
String String_replace_first( String z, String x, String y){
z.replace_first( x, y ) ;
return z ;
}
// [[Rcpp::export]]
String String_replace_last( String z, String x, String y){
z.replace_last( x, y ) ;
return z ;
}
class StringConv{
public:
typedef String result_type ;
StringConv( CharacterVector old_, CharacterVector new__):
nr(old_.size()), old(old_), new_(new__){}
String operator()(String text) const {
for( int i=0; i<nr; i++){
text.replace_all( old[i], new_[i] ) ;
}
return text ;
}
private:
int nr ;
CharacterVector old ;
CharacterVector new_ ;
} ;
// [[Rcpp::export]]
CharacterVector test_sapply_string( CharacterVector text, CharacterVector old , CharacterVector new_){
CharacterVector res = sapply( text, StringConv( old, new_ ) ) ;
return res ;
}
// [[Rcpp::export]]
List test_compare_Strings( String aa, String bb ){
return List::create(
_["a < b" ] = aa < bb,
_["a > b" ] = aa > bb,
_["a == b"] = aa == bb,
_["a == a"] = aa == aa
) ;
}
|