| 88 | |
| 89 | |
| 90 | inline 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 | |
| 135 | inline Matrix<STRSXP> trimws(const Matrix<STRSXP>& x, const char* which = "both") { |
| 136 | R_xlen_t i = 0, sz = x.size(); |
no test coverage detected