| 74 | } |
| 75 | |
| 76 | char *regex_replace(u32regex& re, const char *replacement, const char *str, size_t len, int max_count) { |
| 77 | // Can't just use regex_replace here since it can only do one or infinite replacements |
| 78 | auto match = boost::u32regex_iterator<const char *>(str, str + len, re); |
| 79 | auto end_it = boost::u32regex_iterator<const char *>(); |
| 80 | |
| 81 | auto suffix = str; |
| 82 | |
| 83 | std::string ret; |
| 84 | auto out = back_inserter(ret); |
| 85 | while (match != end_it && max_count > 0) { |
| 86 | copy(suffix, match->prefix().second, out); |
| 87 | match->format(out, replacement); |
| 88 | suffix = match->suffix().first; |
| 89 | ++match; |
| 90 | --max_count; |
| 91 | } |
| 92 | |
| 93 | ret += suffix; |
| 94 | return agi::lua::strndup(ret); |
| 95 | } |
| 96 | |
| 97 | u32regex *regex_compile(const char *pattern, int flags, char **err) { |
| 98 | auto re = std::make_unique<u32regex>(); |
no test coverage detected