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

Function trimws

inst/include/Rcpp/sugar/functions/strings/trimws.h:90–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88
89
90inline Vector<STRSXP> trimws(const Vector<STRSXP>& x, const char* which = "both") {
91 R_xlen_t i = 0, sz = x.size();
92 Vector<STRSXP> res = no_init(sz);
93 std::string buffer;
94
95 if (*which == 'b') {
96 for (; i < sz; i++) {
97 if (traits::is_na<STRSXP>(x[i])) {
98 res[i] = x[i];
99 } else {
100 res[i] = sugar::detail::trim_both(
101 x[i],
102 LENGTH(x[i]),
103 &buffer
104 );
105 }
106 }
107 } else if (*which == 'l') {
108 for (; i < sz; i++) {
109 if (traits::is_na<STRSXP>(x[i])) {
110 res[i] = x[i];
111 } else {
112 res[i] = sugar::detail::trim_left(x[i]);
113 }
114 }
115 } else if (*which == 'r') {
116 for (; i < sz; i++) {
117 if (traits::is_na<STRSXP>(x[i])) {
118 res[i] = x[i];
119 } else {
120 res[i] = sugar::detail::trim_right(
121 x[i],
122 LENGTH(x[i]),
123 &buffer
124 );
125 }
126 }
127 } else {
128 stop("Invalid `which` argument '%s'!", which);
129 return Vector<STRSXP>::create("Unreachable");
130 }
131
132 return res;
133}
134
135inline Matrix<STRSXP> trimws(const Matrix<STRSXP>& x, const char* which = "both") {
136 R_xlen_t i = 0, sz = x.size();

Callers 3

vtrimwsFunction · 0.85
mtrimwsFunction · 0.85
strimwsFunction · 0.85

Calls 12

no_initFunction · 0.85
is_na<STRSXP>Function · 0.85
trim_bothFunction · 0.85
trim_leftFunction · 0.85
trim_rightFunction · 0.85
stopFunction · 0.85
get_cstringMethod · 0.80
StringClass · 0.50
sizeMethod · 0.45
nrowMethod · 0.45
ncolMethod · 0.45
get_sexpMethod · 0.45

Tested by

no test coverage detected