[Rcpp-commits] r838 - in pkg/Rcpp: inst src/Rcpp

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Mar 5 17:58:42 CET 2010


Author: romain
Date: 2010-03-05 17:58:41 +0100 (Fri, 05 Mar 2010)
New Revision: 838

Modified:
   pkg/Rcpp/inst/ChangeLog
   pkg/Rcpp/src/Rcpp/Vector.h
Log:
string_proxy gains begin(), end(), size() and operator[](int)

Modified: pkg/Rcpp/inst/ChangeLog
===================================================================
--- pkg/Rcpp/inst/ChangeLog	2010-03-05 03:18:09 UTC (rev 837)
+++ pkg/Rcpp/inst/ChangeLog	2010-03-05 16:58:41 UTC (rev 838)
@@ -1,3 +1,8 @@
+2010-03-05  Romain Francois <romain at r-enthusiasts.com>
+
+	* src/Rcpp/Vector.h: string_proxy gains begin(), end(), 
+	size(), and operator[] for iterating over characters of the CHARSXP 
+
 2010-03-02  Romain Francois <romain at r-enthusiasts.com>
 
 	* src/Rcpp/Vector.h: Vector gains a nested r_type type that is an 

Modified: pkg/Rcpp/src/Rcpp/Vector.h
===================================================================
--- pkg/Rcpp/src/Rcpp/Vector.h	2010-03-05 03:18:09 UTC (rev 837)
+++ pkg/Rcpp/src/Rcpp/Vector.h	2010-03-05 16:58:41 UTC (rev 838)
@@ -1156,6 +1156,8 @@
 	public:
 		
 		typedef typename ::Rcpp::Vector<RTYPE> VECTOR ;
+		typedef char* iterator ;
+		typedef char& reference ;
 		
 		string_proxy() : parent(0), index(-1){};
 		
@@ -1258,8 +1260,13 @@
 		}
 		inline void set(SEXP x){
 			SET_STRING_ELT( *parent, index, x ) ;
-		}	
+		}
 		
+		inline iterator begin(){ return CHAR( STRING_ELT( *parent, index ) ) ; }
+		inline iterator end(){ return begin() + size() ; }
+		inline int size(){ return strlen( begin() ) ; }
+		inline reference operator[]( int n ){ return *( begin() + n ) ; }
+		
 	} ;
 	
 	inline std::ostream& operator<<(std::ostream& os, const string_proxy<STRSXP>& proxy) {



More information about the Rcpp-commits mailing list