Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions inst/include/Rcpp/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace Rcpp {

/** from a std::string */
String( const std::string& s) : buffer(s), valid(false), buffer_ready(true), enc(CE_NATIVE) {
data = R_NilValue ;
RCPP_STRING_DEBUG( "String(const std::string& )" ) ;
}

Expand All @@ -118,6 +119,7 @@ namespace Rcpp {

/** from a const char* */
String( const char* s) : buffer(s), valid(false), buffer_ready(true), enc(CE_NATIVE){
data = R_NilValue ;
RCPP_STRING_DEBUG( "String(const char*)" ) ;
}

Expand Down
7 changes: 7 additions & 0 deletions inst/unitTests/cpp/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ CharacterVector test_sapply_string( CharacterVector text, CharacterVector old ,
return res ;
}

// [[Rcpp::export]]
String test_ctor(String x) {
String test = "test";
test = x;
return test;
}

// [[Rcpp::export]]
List test_compare_Strings( String aa, String bb ){
return List::create(
Expand Down
6 changes: 5 additions & 1 deletion inst/unitTests/runit.String.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# along with Rcpp. If not, see <http://www.gnu.org/licenses/>.

.runThisTest <- Sys.getenv("RunAllRcppTests") == "yes"

if (.runThisTest) {

.setUp <- Rcpp:::unitTestSetup("String.cpp")
Expand Down Expand Up @@ -50,6 +49,11 @@ if (.runThisTest) {
checkEquals( res, target )
}

test.String.ctor <- function() {
res <- test_ctor("abc")
checkIdentical(res, "abc")
}

test.push.front <- function() {
res <- test_push_front("def")
checkIdentical(res, "abcdef")
Expand Down