[Rcpp-commits] r4058 - in pkg/Rcpp/inst: include/Rcpp unitTests/cpp
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Dec 3 12:34:17 CET 2012
Author: romain
Date: 2012-12-03 12:34:17 +0100 (Mon, 03 Dec 2012)
New Revision: 4058
Modified:
pkg/Rcpp/inst/include/Rcpp/String.h
pkg/Rcpp/inst/unitTests/cpp/String.cpp
Log:
String::push_back, String::push_front
Modified: pkg/Rcpp/inst/include/Rcpp/String.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/String.h 2012-12-03 10:06:18 UTC (rev 4057)
+++ pkg/Rcpp/inst/include/Rcpp/String.h 2012-12-03 11:34:17 UTC (rev 4058)
@@ -98,7 +98,7 @@
inline String& operator=( const std::string& s){ buffer = s ; valid = false ; buffer_ready = true ; return *this ; }
inline String& operator=( const char* s){ buffer = s ; valid = false ; buffer_ready = true ; return *this ; }
inline String& operator=( const StringProxy& proxy){ data = proxy.get() ; valid = true ; buffer_ready=false ; return *this ; }
- inline String& operator=( const String& other ){ data = other.data ; valid = true ; buffer_ready = false ; return *this ; }
+ inline String& operator=( const String& other ){ data = other.get_sexp() ; valid = true ; buffer_ready = false ; return *this ; }
inline String& operator+=( const std::string& s){
RCPP_STRING_DEBUG( "String::operator+=( std::string )" ) ;
@@ -210,8 +210,40 @@
return replace_all( s.get_cstring(), news.get_cstring() ) ;
}
+ inline String& push_back( const char* s){
+ if( is_na() ) return *this ;
+ setBuffer() ; valid = false ; buffer += s ;
+ return *this ;
+ }
+ inline String& push_back( const std::string& s){
+ return push_back( s.c_str() ) ;
+ }
+ inline String& push_back( const Rcpp::String& s){
+ if( is_na() ) return *this ;
+ if( s.is_na() ){ set_na(); return *this ; }
+ return push_back( s.get_cstring() ) ;
+ }
+ inline String& push_front( const char* s){
+ if( is_na() ) return *this ;
+ setBuffer() ; valid = false ; buffer += s ;
+ return *this ;
+ }
+ inline String& push_front( const std::string& s){
+ return push_front( s.c_str() ) ;
+ }
+ inline String& push_front( const Rcpp::String& s){
+ if( is_na() ) return *this ;
+ if( s.is_na() ){ set_na(); return *this ; }
+ return push_front( s.get_cstring() ) ;
+ }
+
+ inline void set_na(){
+ data = NA_STRING ; valid = true; buffer_ready = false ;
+ }
+
+
inline SEXP get_sexp() const {
RCPP_STRING_DEBUG_1( "String::get_sexp const ( valid = %d) ", valid ) ;
return valid ? data : Rf_mkChar( buffer.c_str() ) ;
Modified: pkg/Rcpp/inst/unitTests/cpp/String.cpp
===================================================================
--- pkg/Rcpp/inst/unitTests/cpp/String.cpp 2012-12-03 10:06:18 UTC (rev 4057)
+++ pkg/Rcpp/inst/unitTests/cpp/String.cpp 2012-12-03 11:34:17 UTC (rev 4058)
@@ -25,9 +25,7 @@
public:
typedef String result_type ;
StringConv( CharacterVector old_, CharacterVector new__):
- nr(old_.size()), old(old_), new_(new__)
- {
- }
+ nr(old_.size()), old(old_), new_(new__){}
String operator()(String text) const {
for( int i=0; i<nr; i++){
More information about the Rcpp-commits
mailing list