Skip to content

Commit c0ad307

Browse files
committed
Second step of merging #529 (close #263)
2 parents d18a0bc + 0460f08 commit c0ad307

File tree

4 files changed

+83
-122
lines changed

4 files changed

+83
-122
lines changed

ChangeLog

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
2016-08-02 James J Balamuta <[email protected]>
22

33
* R/Rcpp.package.skeleton.R: Added autogeneration warning
4-
* src/attributes.cpp: Fixed invalid C++ Identifiers and modified
5-
export header to warn against hand edits
4+
* src/attributes.cpp: Fixed invalid C++ Identifiers and modified export
5+
header to warn against hand edits
66
* vignettes/Rcpp-package.Rnw: Updated code generation snippets
77
* man/Rcpp.package.skeleton.Rd: Add warning on hand edits to the
88
autogenerated RcppExports files.
99
* man/compileAttributes.Rd: Idem
1010

11+
2016-08-02 Qiang Kou <[email protected]>
12+
13+
* inst/include/Rcpp/String.h: CE_UTF8 as default encoding
14+
* inst/unitTests/cpp/String.cpp: Update unit test
15+
* inst/unitTests/runit.String.R: Idem
16+
1117
2016-08-01 Nathan Russell <[email protected]>
1218

13-
* inst/include/Rcpp/vector/Vector.h: Added decreasing option for Vector
14-
sort
19+
* inst/include/Rcpp/vector/Vector.h: Added decreasing option for Vector
20+
sort
1521
* inst/include/Rcpp/internal/NAComparator.h: Idem
1622
* inst/unitTests/cpp/Vector.cpp: Idem
1723
* inst/unitTests/runit.Vector.R: Idem
@@ -163,12 +169,12 @@
163169

164170
* DESCRIPTION: Release 0.12.5
165171
* inst/NEWS.Rd: Release 0.12.5
166-
* vignettes/Rcpp.bib: Release 0.12.5
172+
* vignettes/Rcpp.bib: Release 0.12.5
167173
* inst/include/Rcpp/config.h: Release 0.12.5
168174

169175
* debian/*: Changes for Debian release of 0.12.5
170176

171-
* vignettes/Rcpp.bib: Updated references
177+
* vignettes/Rcpp.bib: Updated references
172178

173179
2016-05-13 Dirk Eddelbuettel <[email protected]>
174180

@@ -280,14 +286,14 @@
280286

281287
* DESCRIPTION: Release 0.12.4
282288
* inst/NEWS.Rd: Release 0.12.4
283-
* vignettes/Rcpp.bib: Release 0.12.4
289+
* vignettes/Rcpp.bib: Release 0.12.4
284290
* inst/include/Rcpp/config.h: Release 0.12.4
285291

286292
* debian/*: Changes for Debian release of 0.12.4
287293

288294
2016-03-19 Dirk Eddelbuettel <[email protected]>
289295

290-
* README.md: Use canonical CRAN URL to please R-devel CMD check
296+
* README.md: Use canonical CRAN URL to please R-devel CMD check
291297

292298
2016-03-12 Nathan Russell <[email protected]>
293299

@@ -333,24 +339,24 @@
333339

334340
2016-03-07 Dirk Eddelbuettel <[email protected]>
335341

336-
* inst/include/Rcpp/stats/beta.h: Updated Emacs header and copyright
337-
* inst/include/Rcpp/stats/binom.h: Idem
338-
* inst/include/Rcpp/stats/cauchy.h: Idem
339-
* inst/include/Rcpp/stats/chisq.h: Idem
340-
* inst/include/Rcpp/stats/f.h: Idem
341-
* inst/include/Rcpp/stats/gamma.h: Idem
342-
* inst/include/Rcpp/stats/geom.h: Idem
343-
* inst/include/Rcpp/stats/hyper.h: Idem
344-
* inst/include/Rcpp/stats/nbeta.h: Idem
345-
* inst/include/Rcpp/stats/nbinom.h: Idem
346-
* inst/include/Rcpp/stats/nbinom_mu.h: Idem
347-
* inst/include/Rcpp/stats/nchisq.h: Idem
348-
* inst/include/Rcpp/stats/nf.h: Idem
349-
* inst/include/Rcpp/stats/nt.h: Idem
350-
* inst/include/Rcpp/stats/pois.h: Idem
351-
* inst/include/Rcpp/stats/stats.h: Idem
352-
* inst/include/Rcpp/stats/t.h: Idem
353-
* inst/include/Rcpp/stats/unif.h: Idem
342+
* inst/include/Rcpp/stats/beta.h: Updated Emacs header and copyright
343+
* inst/include/Rcpp/stats/binom.h: Idem
344+
* inst/include/Rcpp/stats/cauchy.h: Idem
345+
* inst/include/Rcpp/stats/chisq.h: Idem
346+
* inst/include/Rcpp/stats/f.h: Idem
347+
* inst/include/Rcpp/stats/gamma.h: Idem
348+
* inst/include/Rcpp/stats/geom.h: Idem
349+
* inst/include/Rcpp/stats/hyper.h: Idem
350+
* inst/include/Rcpp/stats/nbeta.h: Idem
351+
* inst/include/Rcpp/stats/nbinom.h: Idem
352+
* inst/include/Rcpp/stats/nbinom_mu.h: Idem
353+
* inst/include/Rcpp/stats/nchisq.h: Idem
354+
* inst/include/Rcpp/stats/nf.h: Idem
355+
* inst/include/Rcpp/stats/nt.h: Idem
356+
* inst/include/Rcpp/stats/pois.h: Idem
357+
* inst/include/Rcpp/stats/stats.h: Idem
358+
* inst/include/Rcpp/stats/t.h: Idem
359+
* inst/include/Rcpp/stats/unif.h: Idem
354360
* inst/include/Rcpp/stats/dpq/dpq.h: Idem
355361

356362
2016-03-05 Dirk Eddelbuettel <[email protected]>
@@ -499,12 +505,12 @@
499505

500506
* DESCRIPTION: Release 0.12.3
501507
* inst/NEWS.Rd: Release 0.12.3
502-
* vignettes/Rcpp.bib: Release 0.12.3
508+
* vignettes/Rcpp.bib: Release 0.12.3
503509
* inst/include/Rcpp/config.h: Release 0.12.3
504510

505511
* debian/*: Changes for Debian release of 0.12.3
506512

507-
* vignettes/Rcpp.bib: Updated all CRAN reference to current versions
513+
* vignettes/Rcpp.bib: Updated all CRAN reference to current versions
508514

509515
2016-01-09 Dirk Eddelbuettel <[email protected]>
510516

@@ -561,12 +567,12 @@
561567

562568
* DESCRIPTION: Release 0.12.2
563569
* inst/NEWS.Rd: Release 0.12.2
564-
* vignettes/Rcpp.bib: Release 0.12.2
570+
* vignettes/Rcpp.bib: Release 0.12.2
565571
* inst/include/Rcpp/config.h: Release 0.12.2
566572

567573
* debian/*: Changes for Debian release of 0.12.2
568574

569-
* vignettes/Rcpp.bib: Updated all CRAN reference to current versions
575+
* vignettes/Rcpp.bib: Updated all CRAN reference to current versions
570576

571577
2015-11-13 Dirk Eddelbuettel <[email protected]>
572578

@@ -656,7 +662,7 @@
656662

657663
* DESCRIPTION: Release 0.12.1
658664
* inst/NEWS.Rd: Release 0.12.1
659-
* vignettes/Rcpp.bib: Release 0.12.1
665+
* vignettes/Rcpp.bib: Release 0.12.1
660666
* inst/include/Rcpp/config.h: Release 0.12.1
661667

662668
* debian/*: Changes for Debian release of 0.12.1
@@ -801,7 +807,7 @@
801807

802808
* DESCRIPTION: Release 0.12.0
803809
* inst/NEWS.Rd: Release 0.12.0
804-
* vignettes/Rcpp.bib: Release 0.12.0
810+
* vignettes/Rcpp.bib: Release 0.12.0
805811
* inst/include/Rcpp/config.h: Release 0.12.0
806812

807813
* debian/*: Changes for Debian release of 0.12.0
@@ -871,9 +877,9 @@
871877

872878
2015-06-25 Kevin Ushey <[email protected]>
873879

874-
* inst/include/Rcpp/api/meat/Rcpp_eval.h: reset error after Rcpp_eval
875-
* inst/unitTests/cpp/Function.cpp: unit tests
876-
* inst/unitTests/runit.Function.R: unit tests
880+
* inst/include/Rcpp/api/meat/Rcpp_eval.h: reset error after Rcpp_eval
881+
* inst/unitTests/cpp/Function.cpp: unit tests
882+
* inst/unitTests/runit.Function.R: unit tests
877883
* inst/include/Rcpp/Function.h: catch empty error messages
878884
* inst/include/Rcpp/api/meat/Rcpp_eval.h: protect call
879885

@@ -1746,24 +1752,24 @@
17461752

17471753
2014-01-23 Dirk Eddelbuettel <[email protected]>
17481754

1749-
* inst/announce/ANNOUNCE-0.11.0.txt: Added for next release
1755+
* inst/announce/ANNOUNCE-0.11.0.txt: Added for next release
17501756

17511757
2014-01-21 Dirk Eddelbuettel <[email protected]>
17521758

1753-
* R/Rcpp.package.skeleton.R: Update skeleton package to add proper
1754-
Imports: to DESCRIPTION, and importFrom() to NAMESPACE
1759+
* R/Rcpp.package.skeleton.R: Update skeleton package to add proper
1760+
Imports: to DESCRIPTION, and importFrom() to NAMESPACE
17551761

17561762
2014-01-19 Kevin Ushey <[email protected]>
17571763

1758-
* inst/include/Rcpp/api/meat/Vector.h: Add missing UNPROTECT in
1759-
push_back_name__impl
1764+
* inst/include/Rcpp/api/meat/Vector.h: Add missing UNPROTECT in
1765+
push_back_name__impl
17601766

17611767
2014-01-18 Kevin Ushey <[email protected]>
17621768

1763-
* inst/unitTests/runit.S4.R: Add a test for ctor from slot proxy
1764-
* inst/unitTests/cpp/S4.cpp: Add a test for ctor from slot proxy
1765-
* inst/include/Rcpp/vector/Vector.h: Add missing r_cast to vector
1766-
ctor from proxy
1769+
* inst/unitTests/runit.S4.R: Add a test for ctor from slot proxy
1770+
* inst/unitTests/cpp/S4.cpp: Add a test for ctor from slot proxy
1771+
* inst/include/Rcpp/vector/Vector.h: Add missing r_cast to vector
1772+
ctor from proxy
17671773

17681774
2014-01-18 JJ Allaire <[email protected]>
17691775

@@ -1772,14 +1778,14 @@
17721778

17731779
2014-01-18 Kevin Ushey <[email protected]>
17741780

1775-
* inst/unitTests/cpp/Matrix.cpp: Add unit test
1776-
* inst/unitTests/runit.Matrix.R: Add unit test
1777-
* inst/include/Rcpp/api/meat/Matrix.h: Bug fix in operator=
1781+
* inst/unitTests/cpp/Matrix.cpp: Add unit test
1782+
* inst/unitTests/runit.Matrix.R: Add unit test
1783+
* inst/include/Rcpp/api/meat/Matrix.h: Bug fix in operator=
17781784

17791785
2014-01-17 Dirk Eddelbuettel <[email protected]>
17801786

1781-
* R/RcppLdpath.R (RcppCxxFlags): Restore function to supply values
1782-
for include files for packages not yet converted to LinkingTo:
1787+
* R/RcppLdpath.R (RcppCxxFlags): Restore function to supply values
1788+
for include files for packages not yet converted to LinkingTo:
17831789

17841790
2014-01-16 JJ Allaire <[email protected]>
17851791

@@ -1790,7 +1796,7 @@
17901796

17911797
2014-01-15 Dirk Eddelbuettel <[email protected]>
17921798

1793-
* inst/include/Rcpp/exceptions.h: Move stop() into Rcpp namespace
1799+
* inst/include/Rcpp/exceptions.h: Move stop() into Rcpp namespace
17941800

17951801
2014-01-03 JJ Allaire <[email protected]>
17961802

@@ -1804,7 +1810,7 @@
18041810

18051811
2013-12-31 Dirk Eddelbuettel <[email protected]>
18061812

1807-
* vignettes/Rcpp.bib: Updated CRAN package references
1813+
* vignettes/Rcpp.bib: Updated CRAN package references
18081814

18091815
2013-12-20 Kevin Ushey <[email protected]>
18101816

inst/include/Rcpp/String.h

Lines changed: 20 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#define RCPP_STRING_DEBUG_3(fmt, M1, M2, M3)
4141
#endif
4242

43-
4443
namespace Rcpp {
4544

4645
/**
@@ -53,7 +52,7 @@ namespace Rcpp {
5352
typedef internal::const_string_proxy<STRSXP> const_StringProxy;
5453

5554
/** default constructor */
56-
String(): data(Rf_mkChar("")), buffer(), valid(true), buffer_ready(true), enc(CE_NATIVE) {
55+
String(): data(Rf_mkCharCE("", CE_UTF8)), buffer(), valid(true), buffer_ready(true), enc(CE_UTF8) {
5756
Rcpp_PreserveObject(data);
5857
RCPP_STRING_DEBUG("String()");
5958
}
@@ -64,12 +63,6 @@ namespace Rcpp {
6463
RCPP_STRING_DEBUG("String(const String&)");
6564
}
6665

67-
String(const String& other, const std::string& enc) : data(other.get_sexp()), valid(true), buffer_ready(false) {
68-
Rcpp_PreserveObject(data);
69-
set_encoding(enc);
70-
RCPP_STRING_DEBUG("String(const String&)");
71-
}
72-
7366
/** construct a string from a single CHARSXP SEXP */
7467
String(SEXP charsxp) : data(R_NilValue) {
7568
if (TYPEOF(charsxp) == STRSXP) {
@@ -88,33 +81,16 @@ namespace Rcpp {
8881
RCPP_STRING_DEBUG("String(SEXP)");
8982
}
9083

91-
String(SEXP charsxp, const std::string& enc) : data(R_NilValue) {
92-
if (TYPEOF(charsxp) == STRSXP) {
93-
data = STRING_ELT(charsxp, 0);
94-
} else if (TYPEOF(charsxp) == CHARSXP) {
95-
data = charsxp;
96-
}
97-
98-
if (::Rf_isString(data) && ::Rf_length(data) != 1)
99-
throw ::Rcpp::not_compatible("expecting a single value");
100-
101-
valid = true;
102-
buffer_ready = false;
103-
Rcpp_PreserveObject(data);
104-
set_encoding(enc);
105-
RCPP_STRING_DEBUG("String(SEXP)");
106-
}
107-
10884
/** from string proxy */
10985
String(const StringProxy& proxy): data(proxy.get()), valid(true), buffer_ready(false), enc(Rf_getCharCE(proxy.get())) {
11086
Rcpp_PreserveObject(data);
11187
RCPP_STRING_DEBUG("String(const StringProxy&)");
11288
}
11389

114-
String(const StringProxy& proxy, const std::string& enc): data(proxy.get()), valid(true), buffer_ready(false) {
90+
String(const StringProxy& proxy, cetype_t enc): data(proxy.get()), valid(true), buffer_ready(false) {
11591
Rcpp_PreserveObject(data);
11692
set_encoding(enc);
117-
RCPP_STRING_DEBUG("String(const StringProxy&)");
93+
RCPP_STRING_DEBUG("String(const StringProxy&, cetype_t)");
11894
}
11995

12096
/** from string proxy */
@@ -123,40 +99,40 @@ namespace Rcpp {
12399
RCPP_STRING_DEBUG("String(const const_StringProxy&)");
124100
}
125101

126-
String(const const_StringProxy& proxy, const std::string& enc): data(proxy.get()), valid(true), buffer_ready(false) {
102+
String(const const_StringProxy& proxy, cetype_t enc): data(proxy.get()), valid(true), buffer_ready(false) {
127103
Rcpp_PreserveObject(data);
128104
set_encoding(enc);
129-
RCPP_STRING_DEBUG("String(const const_StringProxy&)");
105+
RCPP_STRING_DEBUG("String(const const_StringProxy&, cetype_t)");
130106
}
131107

132108
/** from a std::string */
133-
String(const std::string& s) : buffer(s), valid(false), buffer_ready(true), enc(CE_NATIVE) {
109+
String(const std::string& s, cetype_t enc = CE_UTF8) : buffer(s), valid(false), buffer_ready(true), enc(enc) {
134110
data = R_NilValue;
135-
RCPP_STRING_DEBUG("String(const std::string&)");
111+
RCPP_STRING_DEBUG("String(const std::string&, cetype_t)");
136112
}
137113

138-
String(const std::wstring& s) : data(internal::make_charsexp(s)), valid(true), buffer_ready(false), enc(CE_NATIVE) {
114+
String(const std::wstring& s, cetype_t enc = CE_UTF8) : data(internal::make_charsexp(s)), valid(true), buffer_ready(false), enc(enc) {
139115
Rcpp_PreserveObject(data);
140-
RCPP_STRING_DEBUG("String(const std::wstring&)");
116+
RCPP_STRING_DEBUG("String(const std::wstring&, cetype_t)");
141117
}
142118

143119
/** from a const char* */
144-
String(const char* s) : buffer(s), valid(false), buffer_ready(true), enc(CE_NATIVE) {
120+
String(const char* s, cetype_t enc = CE_UTF8) : buffer(s), valid(false), buffer_ready(true), enc(enc) {
145121
data = R_NilValue;
146-
RCPP_STRING_DEBUG("String(const char*)");
122+
RCPP_STRING_DEBUG("String(const char*, cetype_t)");
147123
}
148124

149-
String(const wchar_t* s) : data(internal::make_charsexp(s)), valid(true), buffer_ready(false), enc(CE_NATIVE) {
125+
String(const wchar_t* s, cetype_t enc = CE_UTF8) : data(internal::make_charsexp(s)), valid(true), buffer_ready(false), enc(enc) {
150126
Rcpp_PreserveObject(data);
151-
RCPP_STRING_DEBUG("String(const wchar_t* s)");
127+
RCPP_STRING_DEBUG("String(const wchar_t* s, cetype_t)");
152128
}
153129

154130
/** constructors from R primitives */
155-
String(int x) : data(internal::r_coerce<INTSXP,STRSXP>(x)), valid(true), buffer_ready(false), enc(CE_NATIVE) {Rcpp_PreserveObject(data);}
156-
String(double x) : data(internal::r_coerce<REALSXP,STRSXP>(x)), valid(true), buffer_ready(false), enc(CE_NATIVE) {Rcpp_PreserveObject(data);}
157-
String(bool x) : data(internal::r_coerce<LGLSXP,STRSXP>(x)), valid(true) , buffer_ready(false), enc(CE_NATIVE) {Rcpp_PreserveObject(data);}
158-
String(Rcomplex x) : data(internal::r_coerce<CPLXSXP,STRSXP>(x)), valid(true), buffer_ready(false), enc(CE_NATIVE) {Rcpp_PreserveObject(data);}
159-
String(Rbyte x) : data(internal::r_coerce<RAWSXP,STRSXP>(x)), valid(true), buffer_ready(false), enc(CE_NATIVE) {Rcpp_PreserveObject(data);}
131+
String(int x) : data(internal::r_coerce<INTSXP,STRSXP>(x)), valid(true), buffer_ready(false), enc(CE_UTF8) {Rcpp_PreserveObject(data);}
132+
String(double x) : data(internal::r_coerce<REALSXP,STRSXP>(x)), valid(true), buffer_ready(false), enc(CE_UTF8) {Rcpp_PreserveObject(data);}
133+
String(bool x) : data(internal::r_coerce<LGLSXP,STRSXP>(x)), valid(true) , buffer_ready(false), enc(CE_UTF8) {Rcpp_PreserveObject(data);}
134+
String(Rcomplex x) : data(internal::r_coerce<CPLXSXP,STRSXP>(x)), valid(true), buffer_ready(false), enc(CE_UTF8) {Rcpp_PreserveObject(data);}
135+
String(Rbyte x) : data(internal::r_coerce<RAWSXP,STRSXP>(x)), valid(true), buffer_ready(false), enc(CE_UTF8) {Rcpp_PreserveObject(data);}
160136

161137
~String() {
162138
Rcpp_ReleaseObject(data);
@@ -406,17 +382,8 @@ namespace Rcpp {
406382
return buffer_ready ? buffer.c_str() : CHAR(data);
407383
}
408384

409-
inline const std::string get_encoding() const {
410-
switch (enc) {
411-
case CE_BYTES:
412-
return "bytes";
413-
case CE_LATIN1:
414-
return "latin1";
415-
case CE_UTF8:
416-
return "UTF-8";
417-
default:
418-
return "unknown";
419-
}
385+
inline cetype_t get_encoding() const {
386+
return enc;
420387
}
421388

422389
inline void set_encoding(cetype_t encoding) {
@@ -431,18 +398,6 @@ namespace Rcpp {
431398
}
432399
}
433400

434-
inline void set_encoding(const std::string & encoding) {
435-
if (encoding == "bytes") {
436-
set_encoding(CE_BYTES);
437-
} else if (encoding == "latin1") {
438-
set_encoding(CE_LATIN1);
439-
} else if (encoding == "UTF-8") {
440-
set_encoding(CE_UTF8);
441-
} else {
442-
set_encoding(CE_ANY);
443-
}
444-
}
445-
446401
bool operator<(const Rcpp::String& other) const {
447402
return strcmp(get_cstring(), other.get_cstring()) < 0;
448403
}

0 commit comments

Comments
 (0)