Skip to content
Closed
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
3 changes: 2 additions & 1 deletion inst/include/Rcpp/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ namespace Rcpp {
}

/** construct a string from a single CHARSXP SEXP */
String(SEXP charsxp) : data(charsxp), valid(true), buffer_ready(false) {
String(SEXP charsxp) : valid(true), buffer_ready(false) {
data = Rf_mkCharCE(Rf_translateCharUTF8(charsxp), CE_UTF8) ;
RCPP_STRING_DEBUG( "String(SEXP)" ) ;
}

Expand Down
8 changes: 4 additions & 4 deletions inst/include/Rcpp/internal/wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ namespace internal{
inline SEXP make_charsexp__impl__wstring( const wchar_t* data ){
char* buffer = get_string_buffer() ;
wcstombs( buffer, data, MAXELTSIZE ) ;
return Rf_mkChar(buffer) ;
return Rf_mkCharCE( Rf_translateCharUTF8(Rf_mkChar(buffer)), CE_UTF8) ;
}
inline SEXP make_charsexp__impl__wstring( wchar_t data ){
wchar_t x[2] ; x[0] = data ; x[1] = '\0' ;
char* buffer = get_string_buffer() ;
wcstombs( buffer, x, MAXELTSIZE ) ;
return Rf_mkChar(buffer) ;
return Rf_mkCharCE( Rf_translateCharUTF8(Rf_mkChar(buffer)), CE_UTF8) ;
}
inline SEXP make_charsexp__impl__wstring( const std::wstring& st ){
return make_charsexp__impl__wstring( st.data()) ;
}
inline SEXP make_charsexp__impl__cstring( const char* data ){
return Rf_mkChar( data ) ;
return Rf_mkCharCE( data, CE_UTF8 ) ;
}
inline SEXP make_charsexp__impl__cstring( char data ){
char x[2]; x[0] = data ; x[1] = '\0' ;
return Rf_mkChar( x ) ;
return Rf_mkCharCE( x, CE_UTF8 ) ;
}

inline SEXP make_charsexp__impl__cstring( const std::string& st ){
Expand Down
5 changes: 5 additions & 0 deletions inst/unitTests/cpp/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@ String test_push_front(String x) {
x.push_front("abc");
return x;
}

// [[Rcpp::export]]
bool test_String_encoding_equality(String a, String b){
return a == b ;
}
8 changes: 8 additions & 0 deletions inst/unitTests/runit.String.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,12 @@ if (.runThisTest) {
res <- test_push_front("def")
checkIdentical(res, "abcdef")
}

test.string.encoding.equal <- function() {
a <- b <- "å"
Encoding(a) <- "unknown"
Encoding(b) <- "UTF-8"
checkTrue(test_String_encoding_equality(a,b))
}

}