25 namespace fv_converter {
28 const std::string& replace)
31 const UChar* pattern =
reinterpret_cast<const UChar*
>(regexp.c_str());
32 if (ONIG_NORMAL != onig_new(®_, pattern, pattern + regexp.size(),
33 ONIG_OPTION_DEFAULT, ONIG_ENCODING_UTF8, ONIG_SYNTAX_PERL, NULL)) {
35 "invalid regular expression: " + regexp));
38 int num_captures = onig_number_of_captures(reg_);
39 for (std::size_t i = 0; i < replace.size(); ++i) {
42 if (i == replace.size() - 1) {
44 "invalid replacement expression. 0-9 or \\ are required after \\"));
49 }
else if (
'0' <= c && c <=
'9') {
51 if (group > num_captures) {
53 "invalid number of capture group"));
57 "invalid replacement expression. 0-9 or \\ are required after \\"));
70 const std::string& input,
71 const OnigRegion* region,
72 std::ostream& out)
const {
73 for (std::size_t i = 0; i <
replace_.size(); ++i) {
81 "invalid replacement expression. 0-9 or \\ are required after \\"));
86 }
else if (
'0' <= c && c <=
'9') {
88 std::size_t len = region->end[group] - region->beg[group];
89 out << input.substr(region->beg[group], len);
94 "invalid replacement expression. 0-9 or \\ are required after \\"));
103 const std::string& input, std::string& output)
const {
104 std::stringstream ss;
106 const UChar* head =
reinterpret_cast<const UChar*
>(input.c_str());
107 const UChar* cur = head, *end = head + input.size();
109 OnigRegion* region = onig_region_new();
113 int r = onig_match(
reg_, head, end, cur, region, ONIG_OPTION_NONE);
118 onig_region_clear(region);
127 onig_region_free(region, 1);
#define JUBATUS_EXCEPTION(e)
void replace(const std::string &input, const OnigRegion *region, std::ostream &out) const
void filter(const std::string &input, std::string &output) const