Skip to content

Commit 15d2fa6

Browse files
committed
fix string.push_front() (#230)
1 parent cadaaee commit 15d2fa6

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2015-01-16 Kevin Ushey <[email protected]>
2+
3+
* inst/include/Rcpp/String.h: fix push_front()
4+
* inst/unitTests/runit.String.R: test
5+
* inst/unitTests/cpp/String.cpp: test
6+
17
2015-01-15 Kevin Ushey <[email protected]>
28

39
* inst/include/Rcpp/platform/sysmacros.h: remove leaked macros

inst/include/Rcpp/String.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ namespace Rcpp {
292292

293293
inline String& push_front( const char* s){
294294
if( is_na() ) return *this ;
295-
setBuffer() ; valid = false ; buffer += s ;
295+
setBuffer() ; valid = false ; buffer = s + buffer;
296296
return *this ;
297297
}
298298
inline String& push_front( const std::string& s){

inst/unitTests/cpp/String.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ List test_compare_Strings( String aa, String bb ){
5656
) ;
5757
}
5858

59+
// [[Rcpp::export]]
60+
String test_push_front(String x) {
61+
x.push_front("abc");
62+
return x;
63+
}

inst/unitTests/runit.String.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,9 @@ if (.runThisTest) {
4949
)
5050
checkEquals( res, target )
5151
}
52-
52+
53+
test.push.front <- function() {
54+
res <- test_push_front("def")
55+
checkIdentical(res, "abcdef")
56+
}
5357
}

0 commit comments

Comments
 (0)