@@ -62,7 +62,7 @@ namespace Rcpp {
62
62
RCPP_STRING_DEBUG ( " String(const String&)" ) ;
63
63
}
64
64
65
- String ( const String& other, const char * enc) : data( other.get_sexp()), valid(true ), buffer_ready(false ) {
65
+ String ( const String& other, const std::string& enc) : data( other.get_sexp()), valid(true ), buffer_ready(false ) {
66
66
set_encoding (enc);
67
67
RCPP_STRING_DEBUG ( " String(const String&)" ) ;
68
68
}
@@ -72,7 +72,7 @@ namespace Rcpp {
72
72
RCPP_STRING_DEBUG ( " String(SEXP)" ) ;
73
73
}
74
74
75
- String (SEXP charsxp, const char * enc) : data(charsxp), valid(true ), buffer_ready(false ) {
75
+ String (SEXP charsxp, const std::string& enc) : data(charsxp), valid(true ), buffer_ready(false ) {
76
76
set_encoding (enc);
77
77
RCPP_STRING_DEBUG ( " String(SEXP)" ) ;
78
78
}
@@ -82,7 +82,7 @@ namespace Rcpp {
82
82
RCPP_STRING_DEBUG ( " String( const StringProxy&)" ) ;
83
83
}
84
84
85
- String ( const StringProxy& proxy, const char * enc ): data( proxy.get() ), valid(true ), buffer_ready(false ) {
85
+ String ( const StringProxy& proxy, const std::string& enc ): data( proxy.get() ), valid(true ), buffer_ready(false ) {
86
86
set_encoding (enc);
87
87
RCPP_STRING_DEBUG ( " String( const StringProxy&)" ) ;
88
88
}
@@ -92,7 +92,7 @@ namespace Rcpp {
92
92
RCPP_STRING_DEBUG ( " String( const const_StringProxy&)" ) ;
93
93
}
94
94
95
- String ( const const_StringProxy& proxy, const char * enc ): data( proxy.get() ), valid(true ), buffer_ready(false ) {
95
+ String ( const const_StringProxy& proxy, const std::string& enc ): data( proxy.get() ), valid(true ), buffer_ready(false ) {
96
96
set_encoding (enc);
97
97
RCPP_STRING_DEBUG ( " String( const const_StringProxy&)" ) ;
98
98
}
@@ -177,8 +177,8 @@ namespace Rcpp {
177
177
178
178
public:
179
179
180
- inline String& operator +=( const std::wstring& s){ return append_wide_string ( s ); }
181
- inline String& operator +=( const wchar_t * s){ return append_wide_string ( s ); }
180
+ inline String& operator +=( const std::wstring& s){ return append_wide_string ( s ); }
181
+ inline String& operator +=( const wchar_t * s){ return append_wide_string ( s ); }
182
182
183
183
inline String& operator +=( const String& other ){
184
184
RCPP_STRING_DEBUG ( " String::operator+=( const char*)" ) ;
@@ -366,21 +366,25 @@ namespace Rcpp {
366
366
367
367
inline void set_encoding ( cetype_t encoding ) {
368
368
enc = encoding;
369
- if (data != NULL )
370
- data = Rf_mkCharCE (Rf_translateCharUTF8 (data), enc);
369
+
370
+ if (valid) {
371
+ data = Rf_mkCharCE (Rf_translateCharUTF8 (data), encoding);
372
+ } else {
373
+ data = Rf_mkCharCE (buffer.c_str (), encoding) ;
374
+ valid = true ;
375
+ }
371
376
}
372
377
373
378
inline void set_encoding (const std::string & encoding) {
374
379
if ( encoding == " bytes" ) {
375
- enc = CE_BYTES;
380
+ set_encoding ( CE_BYTES ) ;
376
381
} else if ( encoding == " latin1" ) {
377
- enc = CE_LATIN1;
382
+ set_encoding ( CE_LATIN1 ) ;
378
383
} else if ( encoding == " UTF-8" ) {
379
- enc = CE_UTF8;
384
+ set_encoding ( CE_UTF8 ) ;
380
385
} else {
381
- enc = CE_ANY;
386
+ set_encoding ( CE_ANY ) ;
382
387
}
383
- set_encoding (enc);
384
388
}
385
389
386
390
bool operator <( const Rcpp::String& other ) const {
@@ -455,8 +459,8 @@ namespace Rcpp {
455
459
return s.get_sexp () ;
456
460
}
457
461
458
- template <int RTYPE>
459
- template <typename T>
462
+ template <int RTYPE>
463
+ template <typename T>
460
464
string_proxy<RTYPE>& string_proxy<RTYPE>::operator +=(const T& rhs) {
461
465
String tmp = get () ;
462
466
tmp += rhs ;
@@ -467,7 +471,7 @@ namespace Rcpp {
467
471
}
468
472
469
473
470
- template <>
474
+ template <>
471
475
inline SEXP wrap<Rcpp::String>( const Rcpp::String& object) {
472
476
RCPP_STRING_DEBUG ( " wrap<String>()" ) ;
473
477
Shield<SEXP> res ( Rf_allocVector ( STRSXP, 1 ) ) ;
0 commit comments