1 #include <Rcpp.h>
2 using namespace Rcpp;
3 
rightstrip(std::string input_str,std::string chars)4 std::string rightstrip(std::string input_str, std::string chars){
5   unsigned int input_size = input_str.size();
6   unsigned int final_size = input_size;
7   for( int i= (input_size-1); i>=0; i--){
8     std::size_t found = chars.find( input_str[i] );
9     //if string is found
10     if(found != std::string::npos)
11       final_size --;
12     else
13       break;
14   }
15 
16   if(final_size==input_size)
17     return input_str;
18   else
19     return input_str.substr(0, final_size);
20 }
21 
22 
23 //[[Rcpp::export]]
pystr_rstrip_(CharacterVector strs,std::string chars)24 CharacterVector pystr_rstrip_(CharacterVector strs, std::string chars){
25   unsigned int vector_size = strs.size();
26   for(unsigned int i=0;i<vector_size;i++){
27     if( strs[i].size()!=0 && strs[i]!=NA_STRING)
28       strs[i] = rightstrip( Rcpp::as<std::string>(strs[i]), chars );
29   }
30   return strs;
31 }
32