-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoiprefixes.cpp
More file actions
55 lines (47 loc) · 954 Bytes
/
Copy pathdoiprefixes.cpp
File metadata and controls
55 lines (47 loc) · 954 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::depends(piton)]]
#include <pegtl.hpp>
using namespace tao::TAOCPP_PEGTL_NAMESPACE;
namespace doiprefixes
{
struct name
: plus< alpha >
{};
// rule to match doi prefix
struct doiPrefix
: seq<
::string< '1', '0' >,
::string< '.' >,
rep_min_max< 4, 9, digit >
>{};
// Parsing grammar
struct grammar
: star< doiPrefix >
{};
template< typename Rule >
struct action
: nothing< Rule >
{};
template<>
struct action< doiPrefix >
{
template< typename Input >
static void apply( const Input& in, std::string& v)
{
v = in.string();
}
};
} // namespace doiprefixes
//[[Rcpp::export]]
CharacterVector doi_prefixes_many(CharacterVector x){
const int n = x.size();
CharacterVector y(n);
for (int i=0; i < n; ++i) {
std::string z;
memory_input<> din(x[i], "moot");
parse< doiprefixes::grammar, doiprefixes::action >( din, z );
y[i] = z;
}
return y;
}