Skip to content

Commit d88820a

Browse files
author
qkou
committed
unit test
1 parent 6621930 commit d88820a

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

inst/include/Rcpp/String.h

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ namespace Rcpp {
5858
}
5959

6060
/** copy constructor */
61-
String( const String& other) : data( other.get_sexp()), valid(true), buffer_ready(false),
62-
enc(Rf_getCharCE(other.get_sexp())) {
61+
String( const String& other) : data( other.get_sexp()), valid(true), buffer_ready(false), enc(Rf_getCharCE(other.get_sexp())) {
6362
RCPP_STRING_DEBUG( "String(const String&)" ) ;
6463
}
6564

@@ -69,46 +68,41 @@ namespace Rcpp {
6968
}
7069

7170
/** construct a string from a single CHARSXP SEXP */
72-
String(SEXP charsxp) : data(charsxp), valid(true), buffer_ready(false),
73-
enc(Rf_getCharCE(charsxp)) {
71+
String(SEXP charsxp) : data(charsxp), valid(true), buffer_ready(false), enc(Rf_getCharCE(charsxp)) {
7472
RCPP_STRING_DEBUG( "String(SEXP)" ) ;
7573
}
7674

7775
String(SEXP charsxp, const char * enc) : data(charsxp), valid(true), buffer_ready(false) {
78-
set_encoding(enc);
76+
set_encoding(enc);
7977
RCPP_STRING_DEBUG( "String(SEXP)" ) ;
8078
}
8179

8280
/** from string proxy */
83-
String( const StringProxy& proxy ): data( proxy.get() ), valid(true), buffer_ready(false),
84-
enc(Rf_getCharCE(proxy.get())){
81+
String( const StringProxy& proxy ): data( proxy.get() ), valid(true), buffer_ready(false), enc(Rf_getCharCE(proxy.get())){
8582
RCPP_STRING_DEBUG( "String( const StringProxy&)" ) ;
8683
}
8784

8885
String( const StringProxy& proxy, const char * enc ): data( proxy.get() ), valid(true), buffer_ready(false) {
89-
set_encoding(enc);
86+
set_encoding(enc);
9087
RCPP_STRING_DEBUG( "String( const StringProxy&)" ) ;
9188
}
9289

9390
/** from string proxy */
94-
String( const const_StringProxy& proxy ): data( proxy.get() ), valid(true), buffer_ready(false),
95-
enc(Rf_getCharCE(proxy.get())){
91+
String( const const_StringProxy& proxy ): data( proxy.get() ), valid(true), buffer_ready(false), enc(Rf_getCharCE(proxy.get())){
9692
RCPP_STRING_DEBUG( "String( const const_StringProxy&)" ) ;
9793
}
9894

9995
String( const const_StringProxy& proxy, const char * enc ): data( proxy.get() ), valid(true), buffer_ready(false) {
100-
set_encoding(enc);
96+
set_encoding(enc);
10197
RCPP_STRING_DEBUG( "String( const const_StringProxy&)" ) ;
10298
}
10399

104100
/** from a std::string */
105-
String( const std::string& s) : buffer(s), valid(false), buffer_ready(true),
106-
enc(CE_NATIVE) {
101+
String( const std::string& s) : buffer(s), valid(false), buffer_ready(true), enc(CE_NATIVE) {
107102
RCPP_STRING_DEBUG( "String(const std::string& )" ) ;
108103
}
109104

110-
String( const std::wstring& s) : data(internal::make_charsexp(s)), valid(true), buffer_ready(false),
111-
enc(CE_NATIVE) {
105+
String( const std::wstring& s) : data(internal::make_charsexp(s)), valid(true), buffer_ready(false), enc(CE_NATIVE) {
112106
RCPP_STRING_DEBUG( "String(const std::wstring& )" ) ;
113107
}
114108

@@ -117,8 +111,7 @@ namespace Rcpp {
117111
RCPP_STRING_DEBUG( "String(const char*)" ) ;
118112
}
119113

120-
String( const wchar_t* s) : data(internal::make_charsexp(s)), valid(true), buffer_ready(false),
121-
enc(CE_NATIVE) {
114+
String( const wchar_t* s) : data(internal::make_charsexp(s)), valid(true), buffer_ready(false), enc(CE_NATIVE) {
122115
RCPP_STRING_DEBUG( "String(const wchar_t* s)" ) ;
123116
}
124117

@@ -160,7 +153,7 @@ namespace Rcpp {
160153
setBuffer() ; buffer += s ; valid = false ;
161154
return *this ;
162155
}
163-
156+
164157
inline String& operator+=( const char* s){
165158
RCPP_STRING_DEBUG( "String::operator+=( const char*)" ) ;
166159
if( is_na() ) return *this ;
@@ -357,7 +350,7 @@ namespace Rcpp {
357350
inline const char* get_cstring() const {
358351
return buffer_ready ? buffer.c_str() : CHAR(data) ;
359352
}
360-
353+
361354
inline const std::string get_encoding() const {
362355
switch (enc) {
363356
case CE_BYTES:
@@ -370,7 +363,7 @@ namespace Rcpp {
370363
return "unknown";
371364
}
372365
}
373-
366+
374367
inline void set_encoding( cetype_t encoding ) {
375368
enc = encoding;
376369
if (data != NULL)
@@ -386,9 +379,8 @@ namespace Rcpp {
386379
enc = CE_UTF8;
387380
} else {
388381
enc = CE_ANY;
389-
Rcout << "Unknown encoding" << std::endl;
390382
}
391-
set_encoding(enc);
383+
set_encoding(enc);
392384
}
393385

394386
bool operator<( const Rcpp::String& other ) const {
@@ -410,7 +402,7 @@ namespace Rcpp {
410402

411403
/** the CHARSXP this String encapsulates */
412404
SEXP data ;
413-
405+
414406
/** the encoding of encapsulated CHARSXP */
415407
cetype_t enc;
416408

inst/unitTests/cpp/String.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ String test_String_encoding(String x) {
6969

7070
// [[Rcpp::export]]
7171
String test_String_set_encoding(String x) {
72-
String y(x);
73-
y.set_encoding("UTF-8");
74-
return y;
72+
x.set_encoding("UTF-8");
73+
return x;
7574
}
7675

7776
// [[Rcpp::export]]
7877
String test_String_ctor_encoding(String x) {
79-
String y(x, "UTF-8");
78+
String y(x);
79+
y.set_encoding("UTF-8");
8080
return y;
8181
}

0 commit comments

Comments
 (0)