MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / String

Class String

inst/include/Rcpp/String.h:49–671  ·  view source on GitHub ↗

* A single string, i.e. an element of a character vector. * This represents CHARSXP SEXP */

Source from the content-addressed store, hash-verified

47 * This represents CHARSXP SEXP
48 */
49 class String {
50 public:
51 typedef internal::string_proxy<STRSXP> StringProxy;
52 typedef internal::const_string_proxy<STRSXP> const_StringProxy;
53
54 /** default constructor */
55 String(): data(Rf_mkCharCE("", CE_UTF8)), token(R_NilValue), buffer(), valid(true), buffer_ready(true), enc(CE_UTF8) {
56 token = Rcpp_PreciousPreserve(data);
57 RCPP_STRING_DEBUG("String()");
58 }
59
60 /** copy constructor */
61 String(const String& s) : data(R_NilValue), token(R_NilValue), buffer(s.buffer), valid(s.valid), buffer_ready(s.buffer_ready), enc(s.enc) {
62 if (!buffer_ready) {
63 data = s.get_sexp();
64 token = Rcpp_PreciousPreserve(data);
65 }
66 RCPP_STRING_DEBUG("String(const String&)");
67 }
68
69 /** construct a string from a single CHARSXP SEXP */
70 String(SEXP charsxp) : data(R_NilValue), token(R_NilValue) {
71 if (TYPEOF(charsxp) == STRSXP) {
72 data = STRING_ELT(charsxp, 0);
73 } else if (TYPEOF(charsxp) == CHARSXP) {
74 data = charsxp;
75 }
76
77 if (::Rf_isString(data) && ::Rf_length(data) != 1) {
78 const char* fmt = "Expecting a single string value: "
79 "[type=%s; extent=%i].";
80 throw ::Rcpp::not_compatible(fmt,
81 Rf_type2char(TYPEOF(data)),
82 ::Rf_length(data));
83 }
84
85 valid = true;
86 buffer_ready = false;
87 enc = Rf_getCharCE(data);
88 token = Rcpp_PreciousPreserve(data);
89 RCPP_STRING_DEBUG("String(SEXP)");
90 }
91
92 /** from string proxy */
93 String(const StringProxy& proxy): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false), enc(Rf_getCharCE(proxy.get())) {
94 token = Rcpp_PreciousPreserve(data);
95 RCPP_STRING_DEBUG("String(const StringProxy&)");
96 }
97
98 String(const StringProxy& proxy, cetype_t enc): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false) {
99 token = Rcpp_PreciousPreserve(data);
100 set_encoding(enc);
101 RCPP_STRING_DEBUG("String(const StringProxy&, cetype_t)");
102 }
103
104 /** from string proxy */
105 String(const const_StringProxy& proxy): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false), enc(Rf_getCharCE(proxy.get())) {
106 token = Rcpp_PreciousPreserve(data);

Callers 1

trimwsFunction · 0.50

Calls 11

Rcpp_PreciousReleaseFunction · 0.85
Rcpp_PreciousPreserveFunction · 0.85
make_charsexpFunction · 0.85
replaceMethod · 0.80
get_cstringMethod · 0.80
is_naFunction · 0.50
getMethod · 0.45
get_sexpMethod · 0.45
is_naMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected