MCPcopy Create free account
hub / github.com/TypesettingTools/Aegisub / regex_replace

Function regex_replace

libaegisub/lua/modules/re.cpp:76–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76char *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
97u32regex *regex_compile(const char *pattern, int flags, char **err) {
98 auto re = std::make_unique<u32regex>();

Callers 2

trim_textFunction · 0.85
add_stack_traceFunction · 0.85

Calls 1

strndupFunction · 0.85

Tested by

no test coverage detected