22#ifndef Rcpp__sugar__trimws_h
23#define Rcpp__sugar__trimws_h
36inline bool isws(
const char c) {
37 return c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'\r';
52inline const char*
trim_right(
const char* str, R_len_t sz, std::string* buff) {
58 const char* ptr = str + sz - 1;
60 for (; ptr > str &&
isws(*ptr); --sz, --ptr);
62 buff->append(str, sz -
isws(*ptr));
66inline const char*
trim_both(
const char* str, R_len_t sz, std::string* buff) {
77 const char* ptr = str + sz - 1;
79 for (; ptr > str &&
isws(*ptr); --sz, --ptr);
81 buff->append(str, sz);
91 R_xlen_t i = 0, sz = x.
size();
107 }
else if (*which ==
'l') {
108 for (; i < sz; i++) {
115 }
else if (*which ==
'r') {
116 for (; i < sz; i++) {
128 stop(
"Invalid `which` argument '%s'!", which);
136 R_xlen_t i = 0, sz = x.
size();
142 for (; i < sz; i++) {
153 }
else if (*which ==
'l') {
154 for (; i < sz; i++) {
161 }
else if (*which ==
'r') {
162 for (; i < sz; i++) {
174 stop(
"Invalid `which` argument '%s'!", which);
213 stop(
"Invalid `which` argument '%s'!", which);
214 return String(
"Unreachable");
const char * get_cstring() const
const char * trim_right(const char *str, R_len_t sz, std::string *buff)
const char * trim_both(const char *str, R_len_t sz, std::string *buff)
const char * trim_left(const char *str)
bool is_na(typename storage_type< RTYPE >::type)
void NORET stop(const std::string &message)
no_init_vector no_init(R_xlen_t size)
Vector< STRSXP > trimws(const Vector< STRSXP > &x, const char *which="both")