-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtokenizer.cpp
More file actions
36 lines (30 loc) · 929 Bytes
/
Copy pathtokenizer.cpp
File metadata and controls
36 lines (30 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// [[Rcpp::depends(BH)]]
#include <Rcpp.h>
#include <boost/tokenizer.hpp>
using namespace Rcpp;
// [[Rcpp::export]]
StringVector Boost_Tokenizer(const StringVector strings) {
std::vector<std::string> tokens;
std::vector<unsigned int> places;
for (unsigned int index = 0; index < strings.size(); index++) {
if(StringVector::is_na(strings[index])) {
places.push_back(tokens.size());
tokens.push_back("");
continue;
}
std::string str = std::string(strings(index));
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(" \f\n\r\t\v");
tokenizer tok(str, sep);
for (tokenizer::iterator it = tok.begin();
it != tok.end();
++it) {
tokens.push_back(*it);
}
}
StringVector y = wrap(tokens);
for(unsigned int i = 0; i < places.size(); i++) {
y[places[i]] = NA_STRING;
}
return y;
}