File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -373,9 +373,11 @@ namespace Rcpp {
373
373
}
374
374
375
375
inline void set_encoding ( cetype_t encoding ) {
376
- enc = encoding;
377
- if (data != NULL )
378
- data = Rf_mkCharCE (Rf_translateCharUTF8 (data), enc);
376
+ if (enc != encoding) {
377
+ enc = encoding;
378
+ if (data != NULL )
379
+ data = Rf_mkCharCE (Rf_translateCharUTF8 (data), enc);
380
+ }
379
381
}
380
382
381
383
inline void set_encoding (const char * encoding) {
Original file line number Diff line number Diff line change @@ -61,3 +61,21 @@ String test_push_front(String x) {
61
61
x.push_front (" abc" );
62
62
return x;
63
63
}
64
+
65
+ // [[Rcpp::export]]
66
+ String test_String_encoding (String x) {
67
+ return x.get_encoding ();
68
+ }
69
+
70
+ // [[Rcpp::export]]
71
+ String test_String_set_encoding (String x) {
72
+ String y (x);
73
+ y.set_encoding (" UTF-8" );
74
+ return y;
75
+ }
76
+
77
+ // [[Rcpp::export]]
78
+ String test_String_ctor_encoding (String x) {
79
+ String y (x, " UTF-8" );
80
+ return y;
81
+ }
Original file line number Diff line number Diff line change @@ -54,4 +54,15 @@ if (.runThisTest) {
54
54
res <- test_push_front(" def" )
55
55
checkIdentical(res , " abcdef" )
56
56
}
57
+
58
+ test.String.encoding <- function () {
59
+ a <- b <- " å"
60
+ Encoding(a ) <- " unknown"
61
+ Encoding(b ) <- " UTF-8"
62
+ checkEquals(test_String_encoding(a ), " unknown" )
63
+ checkEquals(test_String_encoding(b ), " UTF-8" )
64
+ checkEquals(Encoding(test_String_set_encoding(a )), " UTF-8" )
65
+ checkEquals(Encoding(test_String_ctor_encoding(a )), " UTF-8" )
66
+ }
67
+
57
68
}
You can’t perform that action at this time.
0 commit comments