Rcpp Version 1.1.2
Loading...
Searching...
No Matches
String.h
Go to the documentation of this file.
1
2// String.h: Rcpp R/C++ interface class library -- single string
3//
4// Copyright (C) 2012 - 2020 Dirk Eddelbuettel and Romain Francois
5// Copyright (C) 2021 - 2025 Dirk Eddelbuettel, Romain Francois and IƱaki Ucar
6//
7// This file is part of Rcpp.
8//
9// Rcpp is free software: you can redistribute it and/or modify it
10// under the terms of the GNU General Public License as published by
11// the Free Software Foundation, either version 2 of the License, or
12// (at your option) any later version.
13//
14// Rcpp is distributed in the hope that it will be useful, but
15// WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License
20// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
21
22#ifndef Rcpp__String_h
23#define Rcpp__String_h
24
25#ifndef RCPP_STRING_DEBUG_LEVEL
26#define RCPP_STRING_DEBUG_LEVEL 0
27#endif
28
29
30#if RCPP_STRING_DEBUG_LEVEL > 0
31 #define RCPP_STRING_DEBUG_FORMAT "%40s:%4d "
32 #define RCPP_STRING_DEBUG(MSG) Rprintf(RCPP_STRING_DEBUG_FORMAT "%s\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, MSG);
33 #define RCPP_STRING_DEBUG_1(fmt, MSG) Rprintf(RCPP_STRING_DEBUG_FORMAT fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, MSG);
34 #define RCPP_STRING_DEBUG_2(fmt, M1, M2) Rprintf(RCPP_STRING_DEBUG_FORMAT fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2);
35 #define RCPP_STRING_DEBUG_3(fmt, M1, M2, M3) Rprintf(RCPP_STRING_DEBUG_FORMAT fmt "\n" , ::Rcpp::internal::debug::short_file_name(__FILE__).c_str(), __LINE__, M1, M2, M3);
36#else
37 #define RCPP_STRING_DEBUG(MSG)
38 #define RCPP_STRING_DEBUG_1(fmt, MSG)
39 #define RCPP_STRING_DEBUG_2(fmt, M1, M2)
40 #define RCPP_STRING_DEBUG_3(fmt, M1, M2, M3)
41#endif
42
43namespace Rcpp {
44
49 class String {
50 public:
53
55 String(): data(Rf_mkCharCE("", CE_UTF8)), token(R_NilValue), buffer(), valid(true), buffer_ready(true), enc(CE_UTF8) {
57 RCPP_STRING_DEBUG("String()");
58 }
59
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();
65 }
66 RCPP_STRING_DEBUG("String(const String&)");
67 }
68
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);
89 RCPP_STRING_DEBUG("String(SEXP)");
90 }
91
93 String(const StringProxy& proxy): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false), enc(Rf_getCharCE(proxy.get())) {
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) {
101 RCPP_STRING_DEBUG("String(const StringProxy&, cetype_t)");
102 }
103
105 String(const const_StringProxy& proxy): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false), enc(Rf_getCharCE(proxy.get())) {
107 RCPP_STRING_DEBUG("String(const const_StringProxy&)");
108 }
109
110 String(const const_StringProxy& proxy, cetype_t enc): data(proxy.get()), token(R_NilValue), valid(true), buffer_ready(false) {
113 RCPP_STRING_DEBUG("String(const const_StringProxy&, cetype_t)");
114 }
115
117 String(const std::string& s, cetype_t enc = CE_UTF8) : data(R_NilValue), token(R_NilValue), buffer(s), valid(false), buffer_ready(true), enc(enc) {
118 RCPP_STRING_DEBUG("String(const std::string&, cetype_t)");
119 }
120
123 // Erase s.
124 s.data = R_NilValue;
125 s.token = R_NilValue;
126 s.buffer = std::string();
127 s.valid = false;
128 s.buffer_ready = true;
129 s.enc = CE_UTF8;
130 RCPP_STRING_DEBUG("String(String&&)");
131 }
132
134 String(std::string&& s, cetype_t enc = CE_UTF8) : data(R_NilValue), token(R_NilValue), buffer(s), valid(false), buffer_ready(true), enc(enc) {
135 RCPP_STRING_DEBUG("String(std::string&&, cetype_t)");
136 }
137
138 String(const std::wstring& s, cetype_t enc = CE_UTF8) : data(internal::make_charsexp(s)), token(R_NilValue), valid(true), buffer_ready(false), enc(enc) {
140 RCPP_STRING_DEBUG("String(const std::wstring&, cetype_t)");
141 }
142
144 String(const char* s, cetype_t enc = CE_UTF8) : buffer(s), valid(false), buffer_ready(true), enc(enc) {
145 data = R_NilValue;
146 token = R_NilValue;
147 RCPP_STRING_DEBUG("String(const char*, cetype_t)");
148 }
149
150 String(const wchar_t* s, cetype_t enc = CE_UTF8) : data(internal::make_charsexp(s)), token(R_NilValue), valid(true), buffer_ready(false), enc(enc) {
152 RCPP_STRING_DEBUG("String(const wchar_t* s, cetype_t)");
153 }
154
156 String(int x) : data(internal::r_coerce<INTSXP,STRSXP>(x)), token(R_NilValue), valid(true), buffer_ready(false), enc(CE_UTF8) {
158 }
159 String(double x) : data(internal::r_coerce<REALSXP,STRSXP>(x)), token(R_NilValue), valid(true), buffer_ready(false), enc(CE_UTF8) {
161 }
162 String(bool x) : data(internal::r_coerce<LGLSXP,STRSXP>(x)), token(R_NilValue), valid(true) , buffer_ready(false), enc(CE_UTF8) {
164 }
165 String(Rcomplex x) : data(internal::r_coerce<CPLXSXP,STRSXP>(x)), token(R_NilValue), valid(true), buffer_ready(false), enc(CE_UTF8) {
167 }
168 String(Rbyte x) : data(internal::r_coerce<RAWSXP,STRSXP>(x)), token(R_NilValue), valid(true), buffer_ready(false), enc(CE_UTF8) {
170 }
171
174 data = R_NilValue;
175 token = R_NilValue;
176 }
177
178
179 inline String& operator=(int x) {
180 data = internal::r_coerce<INTSXP, STRSXP>(x);
183 valid = true;
184 buffer_ready = false;
185 return *this;
186 }
187 inline String& operator=(double x) {
188 data = internal::r_coerce<REALSXP, STRSXP>(x);
191 valid = true;
192 buffer_ready = false;
193 return *this;
194 }
195 inline String& operator=(Rbyte x) {
196 data = internal::r_coerce<RAWSXP, STRSXP>(x);
199 valid = true;
200 buffer_ready = false;
201 return *this;
202 }
203 inline String& operator=(bool x) {
204 data = internal::r_coerce<LGLSXP, STRSXP>(x);
207 valid = true;
208 buffer_ready = false;
209 return *this;
210 }
211 inline String& operator=(Rcomplex x) {
212 data = internal::r_coerce<CPLXSXP, STRSXP>(x);
215 valid = true;
216 buffer_ready = false;
217 return *this;
218 }
219 inline String& operator=(SEXP x) {
220 if (data != x) {
221 data = x;
224 }
225 valid = true;
226 buffer_ready = false;
227 return *this;
228 }
229 inline String& operator=(const StringProxy& proxy) {
230 SEXP x = proxy.get();
231 if (data != x) {
232 data = x;
235 }
236 valid = true;
237 buffer_ready = false;
238 return *this;
239 }
240 inline String& operator=(const String& other) {
241 if (other.buffer_ready) {
242 // Copy the buffer without creating a SEXP.
243 if (valid) {
245 valid = false;
246 }
247 data = R_NilValue;
248 token = R_NilValue;
249 buffer = other.buffer;
250 buffer_ready = true;
251 enc = other.enc;
252 } else {
253 SEXP x = other.get_sexp();
254 if (data != x) {
255 data = x;
258 }
259 valid = true;
260 buffer_ready = false;
261 }
262 return *this;
263 }
264 inline String& operator=(const std::string& s) {
265 buffer = s;
266 valid = false;
267 buffer_ready = true;
268 return *this;
269 }
270 inline String& operator=(String&& other) {
271 data = other.data;
272 token = other.token;
273 buffer = std::move(other.buffer);
274 valid = other.valid;
275 buffer_ready = other.buffer_ready;
276 enc = other.enc;
277 // Erase other.
278 other.data = R_NilValue;
279 other.token = R_NilValue;
280 other.buffer = std::string();
281 other.valid = false;
282 other.buffer_ready = true;
283 other.enc = CE_UTF8;
284 return *this;
285 }
286 inline String& operator=(std::string&& s) {
287 buffer = s;
288 valid = false;
289 buffer_ready = true;
290 return *this;
291 }
292 inline String& operator=(const char* s) {
293 buffer = s;
294 valid = false;
295 buffer_ready = true;
296 return *this;
297 }
298
299 private:
300 template <typename T>
301 inline String& assign_wide_string(const T& s) {
302 data = internal::make_charsexp(s);
305 valid = true;
306 buffer_ready = false;
307 return *this;
308 }
309
310 public:
311 inline String& operator=(const std::wstring& s) { return assign_wide_string(s); }
312 inline String& operator=(const wchar_t* s) { return assign_wide_string(s); }
313
314 inline String& operator+=(const std::string& s) {
315 RCPP_STRING_DEBUG("String::operator+=(std::string)");
316 if (is_na()) return *this;
317 setBuffer(); buffer += s; valid = false;
318 return *this;
319 }
320
321 inline String& operator+=(const char* s) {
322 RCPP_STRING_DEBUG("String::operator+=(const char*)");
323 if (is_na()) return *this;
324 setBuffer(); buffer += s; valid = false;
325 return *this;
326 }
327 private:
328 template <typename T>
329 inline String& append_wide_string(const T& s) {
330 RCPP_STRING_DEBUG_1("String::operator+=(%s)", DEMANGLE(T));
331 setData();
332 if (is_na()) return *this;
333 const char* buf = CHAR(data);
334 std::wstring tmp(buf, buf + strlen(buf));
335 tmp += s;
336 data = internal::make_charsexp(tmp);
339 valid = true;
340 buffer_ready = false;
341 return *this;
342 }
343
344 public:
345
346 inline String& operator+=(const std::wstring& s) { return append_wide_string(s); }
347 inline String& operator+=(const wchar_t* s) { return append_wide_string(s); }
348
349 inline String& operator+=(const String& other) {
350 RCPP_STRING_DEBUG("String::operator+=(const char*)");
351 if (is_na()) return *this;
352 if (other.is_na()) {
353 data = NA_STRING;
356 valid = true;
357 buffer_ready = false;
358 return *this;
359 }
360 setBuffer(); buffer += other; valid = false;
361 return *this;
362 }
363 inline String& operator+=(const StringProxy& proxy) {
364 RCPP_STRING_DEBUG("String::operator+=(const StringProxy&)");
365 if (is_na()) return *this;
366 SEXP proxy_sexp = proxy;
367 if (proxy_sexp == NA_STRING) {
368 data = NA_STRING;
371 valid = true;
372 buffer_ready = false;
373 return *this;
374 }
375 setBuffer(); buffer += CHAR(proxy_sexp); valid = false;
376 return *this;
377 }
378 inline String& operator+=(const const_StringProxy& proxy) {
379 RCPP_STRING_DEBUG("String::operator+=(const StringProxy&)");
380 if (is_na()) return *this;
381 SEXP proxy_sexp = proxy;
382 if (proxy_sexp == NA_STRING) {
383 data = NA_STRING;
386 valid = true;
387 buffer_ready = false;
388 return *this;
389 }
390 setBuffer(); buffer += CHAR(proxy_sexp); valid = false;
391 return *this;
392 }
393 inline String& operator+=(SEXP x) {
394 RCPP_STRING_DEBUG("String::operator+=(SEXP)");
395 if (is_na()) return *this;
396 if (x == NA_STRING) {
397 data = NA_STRING;
400 valid = true;
401 buffer_ready = false;
402 return *this;
403 }
404 setBuffer(); buffer += CHAR(x); valid = false;
405 return *this;
406 }
407 // inline String& operator+=(int x ) { data += char_nocheck(internal::r_coerce<INTSXP ,STRSXP>(x)); return *this; }
408 // inline String& operator+=(double x ) { data += char_nocheck(internal::r_coerce<REALSXP,STRSXP>(x)); return *this; }
409 // inline String& operator+=(Rbyte x ) { data += char_nocheck(internal::r_coerce<RAWSXP ,STRSXP>(x)); return *this; }
410 // inline String& operator+=(bool x ) { data += char_nocheck(internal::r_coerce<LGLSXP ,STRSXP>(x)); return *this; }
411 // inline String& operator+=(Rcomplex x) { data += char_nocheck(internal::r_coerce<CPLXSXP,STRSXP>(x)); return *this; }
412
413
414 inline String& replace_first(const char* s, const char* news) {
415 RCPP_STRING_DEBUG_2("String::replace_first(const char* = '%s' , const char* = '%s')", s, news);
416 if (is_na()) return *this;
417 setBuffer();
418 std::string s2 = std::string(s);
419 size_t index = std::distance(buffer.begin(), std::search(buffer.begin(), buffer.end(), s2.begin(), s2.end()));
420 if (index != std::string::npos) buffer.replace(index, strlen(s), news);
421 valid = false;
422 return *this;
423 }
424 inline String& replace_first(const Rcpp::String& s, const char* news) {
425 // replace NA -> do nothing
426 if (s.is_na()) return *this;
427 return replace_first(s.get_cstring(), news);
428 }
429 inline String& replace_first(const char* s, const Rcpp::String& news) {
430 // replace NA -> do nothing
431 if (news.is_na()) return *this;
432 return replace_first(s, news.get_cstring());
433 }
434 inline String& replace_first(const Rcpp::String& s, const Rcpp::String& news) {
435 // replace NA -> do nothing
436 if (s.is_na() || news.is_na()) return *this;
437 return replace_first(s.get_cstring(), news.get_cstring());
438 }
439
440 inline String& replace_last(const char* s, const char* news) {
441 RCPP_STRING_DEBUG_2("String::replace_last(const char* = '%s' , const char* = '%s')", s, news);
442 if (is_na()) return *this;
443 setBuffer();
444 std::string s2 = std::string(s);
445 size_t index = std::distance(buffer.begin(), std::find_end(buffer.begin(), buffer.end(), s2.begin(), s2.end()));
446 if (index != std::string::npos) buffer.replace(index, strlen(s), news);
447 valid = false;
448 return *this;
449 }
450 inline String& replace_last(const Rcpp::String& s, const char* news) {
451 // replace NA -> do nothing
452 if (s.is_na()) return *this;
453 return replace_last(s.get_cstring(), news);
454 }
455 inline String& replace_last(const char* s, const Rcpp::String& news) {
456 // replace NA -> do nothing
457 if (news.is_na()) return *this;
458 return replace_last(s, news.get_cstring());
459 }
460 inline String& replace_last(const Rcpp::String& s, const Rcpp::String& news) {
461 // replace NA -> do nothing
462 if (s.is_na() || news.is_na()) return *this;
463 return replace_last(s.get_cstring(), news.get_cstring());
464 }
465
466
467 inline String& replace_all(const char* s, const char* news) {
468 RCPP_STRING_DEBUG_2("String::replace_all(const char* = '%s' , const char* = '%s')", s, news);
469 if (is_na()) return *this;
470 setBuffer();
471 std::string s2 = std::string(s);
472 std::string::iterator iter = buffer.begin();
473 while(true) {
474 iter = std::search(iter, buffer.end(), s2.begin(), s2.end());
475 if (iter == buffer.end()) break;
476 size_t index = std::distance(buffer.begin(), iter);
477 if (index != std::string::npos) buffer.replace(index, strlen(s), news);
478 }
479 valid = false;
480 return *this;
481 }
482
483 template <typename LHS, typename RHS>
484 inline String& replace_all(const LHS& s, const RHS& news) {
485 return replace_all(String(s), String(news));
486 }
487
488 inline String& replace_all(const Rcpp::String& s, const char* news) {
489 // replace NA -> do nothing
490 if (s.is_na()) return *this;
491 return replace_all(s.get_cstring(), news);
492 }
493 inline String& replace_all(const char* s, const Rcpp::String& news) {
494 // replace NA -> do nothing
495 if (news.is_na()) return *this;
496 return replace_all(s, news.get_cstring());
497 }
498 inline String& replace_all(const Rcpp::String& s, const Rcpp::String& news) {
499 // replace NA -> do nothing
500 if (s.is_na() || news.is_na()) return *this;
501 return replace_all(s.get_cstring(), news.get_cstring());
502 }
503
504 inline String& push_back(const char* s) {
505 if (is_na()) return *this;
506 setBuffer(); valid = false; buffer += s;
507 return *this;
508 }
509 inline String& push_back(const std::string& s) {
510 return push_back(s.c_str());
511 }
512 inline String& push_back(const Rcpp::String& s) {
513 if (is_na()) return *this;
514 if (s.is_na()) { set_na(); return *this; }
515 return push_back(s.get_cstring());
516 }
517
518 inline String& push_front(const char* s) {
519 if (is_na()) return *this;
520 setBuffer(); valid = false; buffer = s + buffer;
521 return *this;
522 }
523 inline String& push_front(const std::string& s) {
524 return push_front(s.c_str());
525 }
526 inline String& push_front(const Rcpp::String& s) {
527 if (is_na()) return *this;
528 if (s.is_na()) { set_na(); return *this; }
529 return push_front(s.get_cstring());
530 }
531
532
533 inline void set_na() {
534 data = NA_STRING;
537 valid = true;
538 buffer_ready = false;
539 }
540
541
542 inline SEXP get_sexp_impl() const {
543
544 // workaround for h5 package (currently deprecated so updates
545 // to CRAN may not be timely)
546#ifdef __H5Cpp_H
547 return Rf_mkCharCE(buffer.c_str(), enc);
548#else
549 if (buffer.find('\0') != std::string::npos)
550 throw embedded_nul_in_string();
551 return Rf_mkCharLenCE(buffer.c_str(), static_cast<int>(buffer.size()), enc);
552#endif
553 }
554
555 inline SEXP get_sexp() const {
556 RCPP_STRING_DEBUG_1("String::get_sexp const (valid = %d) ", valid);
557 return valid ? data : get_sexp_impl();
558 }
559
560 inline SEXP get_sexp() {
561 RCPP_STRING_DEBUG_1("String::get_sexp (valid = %d) ", valid);
562 setData(); return data;
563 }
564
565 inline operator std::string() const {
566 return get_cstring();
567 }
568
569 inline operator std::wstring() const {
570 const char* s = get_cstring();
571 return std::wstring(s, s + strlen(s));
572 }
573
574 inline const char* get_cstring() const {
575 return buffer_ready ? buffer.c_str() : CHAR(data);
576 }
577
578 inline cetype_t get_encoding() const {
579 return enc;
580 }
581
582 inline void set_encoding(cetype_t encoding) {
583 enc = encoding;
584
585 if (valid) {
586 // TODO: may longjmp on failure to translate?
587 const char* translated = Rf_translateCharUTF8(data);
588 data = Rf_mkCharCE(translated, encoding);
591 } else {
594 valid = true;
595 }
596 }
597
598 bool operator<(const Rcpp::String& other) const {
599 return strcmp(get_cstring(), other.get_cstring()) < 0;
600 }
601
602 bool operator==(const Rcpp::String& other) const {
603 return get_sexp() == other.get_sexp();
604 }
605 bool operator!=(const Rcpp::String& other) const {
606 return get_sexp() != other.get_sexp();
607 }
608
609 bool operator==(const StringProxy& other) const {
610 return get_sexp() == other.get();
611 }
612
613 bool operator!=(const StringProxy& other) const {
614 return get_sexp() != other.get();
615 }
616
617 bool operator==(const const_StringProxy& other) const {
618 return get_sexp() == other.get();
619 }
620
621 bool operator!=(const const_StringProxy& other) const {
622 return get_sexp() != other.get();
623 }
624
625 bool operator>(const Rcpp::String& other) const {
626 return strcmp(get_cstring(), other.get_cstring()) > 0;
627 }
628
629 bool operator==(SEXP other) const {
630 return get_sexp() == other;
631 }
632
633 bool operator!=(SEXP other) const {
634 return get_sexp() != other;
635 }
636
637 private:
638
640 SEXP data;
641 SEXP token;
642
644 std::string buffer;
645
647 bool valid;
648
651
653 cetype_t enc;
654
655 inline bool is_na() const { return data == NA_STRING; }
656 inline void setBuffer() {
657 if (!buffer_ready) {
659 buffer_ready = true;
660 }
661 }
662 inline void setData() {
663 RCPP_STRING_DEBUG("setData");
664 if (!valid) {
667 valid = true;
668 }
669 }
670 template <typename T> void append(const T& s) { buffer += s;}
671 };
672
673 namespace traits{
675 template<> struct r_sexptype_traits<Rcpp::String>{ enum{ rtype = STRSXP }; };
676 }
677
678 namespace internal {
679 template <int RTYPE, template <class> class StoragePolicy>
684
685 template <int RTYPE>
687 RCPP_DEBUG("string_element_converter::get< Rcpp::String >()")
688 return input.get_sexp();
689 }
690
691 template <>
693 return s.get_sexp();
694 }
695
696 template <int RTYPE, template <class> class StoragePolicy>
697 template <typename T>
699 String tmp = get();
700 tmp += rhs;
701 set(tmp);
702 return *this;
703 }
704
705 }
706
707
708 template <>
709 inline SEXP wrap<Rcpp::String>(const Rcpp::String& object) {
710 RCPP_STRING_DEBUG("wrap<String>()");
711 Shield<SEXP> res(Rf_allocVector(STRSXP, 1));
712 SEXP data = object.get_sexp();
713 SET_STRING_ELT(res, 0, data);
714 return res;
715 }
716
717 inline bool operator==(const String::StringProxy& lhs, const String& rhs) {
718 return rhs == lhs;
719 }
720
721 inline bool operator!=(const String::StringProxy& lhs, const String& rhs) {
722 return rhs != lhs;
723 }
724
725 inline bool operator==(const String::const_StringProxy& lhs, const String& rhs) {
726 return rhs == lhs;
727 }
728
729 inline bool operator!=(const String::const_StringProxy& lhs, const String& rhs) {
730 return rhs != lhs;
731 }
732
733} // Rcpp
734
736namespace std {
737 template <>
738 struct hash<Rcpp::String> {
739 size_t operator()(const Rcpp::String & s) const{
740 return hash<string>()(s.get_cstring());
741 }
742 };
743}
744
745#endif
#define RCPP_STRING_DEBUG_2(fmt, M1, M2)
Definition String.h:39
#define RCPP_STRING_DEBUG_1(fmt, MSG)
Definition String.h:38
#define RCPP_STRING_DEBUG(MSG)
Definition String.h:37
const char * char_nocheck(SEXP)
Definition routines.h:258
String(Rcomplex x)
Definition String.h:165
String(const const_StringProxy &proxy)
Definition String.h:105
String & push_front(const std::string &s)
Definition String.h:523
String & operator=(std::string &&s)
Definition String.h:286
void append(const T &s)
Definition String.h:670
bool buffer_ready
Definition String.h:650
String & operator+=(const String &other)
Definition String.h:349
String & operator=(const StringProxy &proxy)
Definition String.h:229
String & replace_all(const Rcpp::String &s, const char *news)
Definition String.h:488
String & replace_last(const char *s, const Rcpp::String &news)
Definition String.h:455
bool operator==(const StringProxy &other) const
Definition String.h:609
String & operator=(double x)
Definition String.h:187
String & operator=(Rbyte x)
Definition String.h:195
String & push_front(const char *s)
Definition String.h:518
std::string buffer
Definition String.h:644
String(const char *s, cetype_t enc=CE_UTF8)
Definition String.h:144
String & assign_wide_string(const T &s)
Definition String.h:301
bool is_na() const
Definition String.h:655
String & replace_last(const char *s, const char *news)
Definition String.h:440
String & operator+=(const std::wstring &s)
Definition String.h:346
String & replace_last(const Rcpp::String &s, const Rcpp::String &news)
Definition String.h:460
bool operator>(const Rcpp::String &other) const
Definition String.h:625
String & operator=(const char *s)
Definition String.h:292
bool operator!=(const Rcpp::String &other) const
Definition String.h:605
String & operator=(Rcomplex x)
Definition String.h:211
String & replace_all(const Rcpp::String &s, const Rcpp::String &news)
Definition String.h:498
bool operator!=(const const_StringProxy &other) const
Definition String.h:621
String & replace_all(const LHS &s, const RHS &news)
Definition String.h:484
cetype_t get_encoding() const
Definition String.h:578
void set_encoding(cetype_t encoding)
Definition String.h:582
String(const StringProxy &proxy)
Definition String.h:93
String & operator+=(const std::string &s)
Definition String.h:314
String(double x)
Definition String.h:159
String(std::string &&s, cetype_t enc=CE_UTF8)
Definition String.h:134
String & operator=(const std::string &s)
Definition String.h:264
String & operator=(String &&other)
Definition String.h:270
String & operator=(const std::wstring &s)
Definition String.h:311
String & replace_first(const Rcpp::String &s, const Rcpp::String &news)
Definition String.h:434
internal::string_proxy< STRSXP > StringProxy
Definition String.h:51
String & operator+=(const wchar_t *s)
Definition String.h:347
String(const std::string &s, cetype_t enc=CE_UTF8)
Definition String.h:117
String(SEXP charsxp)
Definition String.h:70
String & operator+=(const const_StringProxy &proxy)
Definition String.h:378
String & operator+=(const char *s)
Definition String.h:321
bool operator==(const const_StringProxy &other) const
Definition String.h:617
String & replace_first(const Rcpp::String &s, const char *news)
Definition String.h:424
cetype_t enc
Definition String.h:653
internal::const_string_proxy< STRSXP > const_StringProxy
Definition String.h:52
String(const const_StringProxy &proxy, cetype_t enc)
Definition String.h:110
String & push_back(const Rcpp::String &s)
Definition String.h:512
String(const std::wstring &s, cetype_t enc=CE_UTF8)
Definition String.h:138
String & operator=(bool x)
Definition String.h:203
SEXP get_sexp() const
Definition String.h:555
String & replace_first(const char *s, const Rcpp::String &news)
Definition String.h:429
const char * get_cstring() const
Definition String.h:574
String & operator+=(const StringProxy &proxy)
Definition String.h:363
String(Rbyte x)
Definition String.h:168
bool operator!=(const StringProxy &other) const
Definition String.h:613
String & operator=(SEXP x)
Definition String.h:219
SEXP get_sexp_impl() const
Definition String.h:542
String & operator=(const wchar_t *s)
Definition String.h:312
String(String &&s)
Definition String.h:122
String(const wchar_t *s, cetype_t enc=CE_UTF8)
Definition String.h:150
bool operator==(const Rcpp::String &other) const
Definition String.h:602
String & operator=(int x)
Definition String.h:179
bool operator<(const Rcpp::String &other) const
Definition String.h:598
String & operator=(const String &other)
Definition String.h:240
String & push_back(const char *s)
Definition String.h:504
String(const StringProxy &proxy, cetype_t enc)
Definition String.h:98
String & push_front(const Rcpp::String &s)
Definition String.h:526
SEXP data
Definition String.h:640
bool operator!=(SEXP other) const
Definition String.h:633
String & operator+=(SEXP x)
Definition String.h:393
void setData()
Definition String.h:662
SEXP get_sexp()
Definition String.h:560
void setBuffer()
Definition String.h:656
String(bool x)
Definition String.h:162
String(int x)
Definition String.h:156
bool operator==(SEXP other) const
Definition String.h:629
String & replace_last(const Rcpp::String &s, const char *news)
Definition String.h:450
String & push_back(const std::string &s)
Definition String.h:509
String & replace_all(const char *s, const Rcpp::String &news)
Definition String.h:493
String & append_wide_string(const T &s)
Definition String.h:329
void set_na()
Definition String.h:533
String(const String &s)
Definition String.h:61
SEXP token
Definition String.h:641
bool valid
Definition String.h:647
String & replace_first(const char *s, const char *news)
Definition String.h:414
String & replace_all(const char *s, const char *news)
Definition String.h:467
static SEXP get(const T &input)
Definition converter.h:48
string_proxy & operator+=(const T &rhs)
string_proxy & operator=(const string_proxy< RTYPE, StoragePolicy > &other)
#define RCPP_DEBUG(MSG)
Definition debug.h:43
#define DEMANGLE(__TYPE__)
Definition exceptions.h:403
internal implementation details
Definition Date.h:43
SEXP make_charsexp< Rcpp::String >(const Rcpp::String &s)
Definition String.h:692
Rcpp API.
Definition algo.h:28
SEXP wrap< Rcpp::String >(const Rcpp::String &object)
Definition String.h:709
bool operator!=(const Date &d1, const Date &d2)
Definition Date.h:170
SEXP get(const std::string &name) const
Definition Environment.h:98
SEXP Rcpp_PreciousPreserve(SEXP object)
Definition RcppCommon.h:118
void Rcpp_PreciousRelease(SEXP token)
Definition RcppCommon.h:122
bool operator==(const Date &d1, const Date &d2)
Definition Date.h:167
Definition String.h:736
size_t operator()(const Rcpp::String &s) const
Definition String.h:739