-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoisuffixes.cpp
More file actions
93 lines (79 loc) · 1.52 KB
/
Copy pathdoisuffixes.cpp
File metadata and controls
93 lines (79 loc) · 1.52 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::depends(piton)]]
#include <pegtl.hpp>
using namespace tao::TAOCPP_PEGTL_NAMESPACE;
namespace doisuffixes
{
struct name
: plus< alpha >
{};
// rule to match a forward slash
struct forwardSlash
: one<'/'>
{};
// any symbols
struct txtany
: sor<
seq< plus< tao::TAOCPP_PEGTL_NAMESPACE::any > >,
not_one< '\r', '\n', ' ' >
>
{};
struct spacetxt
: sor<
seq< space >,
seq< space, plus< alpha > >
>
{};
struct alphaSpace
: seq< plus< alpha >, space >
{};
struct txtspace
: sor<
// seq< plus< alpha >, space, opt< seq < > > >,
rep_min< 1, alphaSpace >,
seq< plus< space > >
>
{};
// rule to match doi prefix
struct doiPrefix
: seq<
::string< '1', '0' >,
::string< '.' >,
rep_min_max< 4, 9, digit >
>{};
// rule to match doi suffix
struct doiSuffix
: seq<
txtany
>{};
// Parsing grammar
struct grammar
: star< doiPrefix, forwardSlash, doiSuffix, opt<spacetxt> >
{};
template< typename Rule >
struct action
: nothing< Rule >
{};
template<>
struct action< doiSuffix >
{
template< typename Input >
static void apply( const Input& in, std::string& v)
{
v = in.string();
}
};
} // namespace doisuffixes
//[[Rcpp::export]]
CharacterVector doi_suffixes_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< doisuffixes::grammar, doisuffixes::action >( din, z );
y[i] = z;
}
return y;
}