diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-12-16 20:29:05 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2021-02-24 16:40:04 +0300 |
commit | 8e761289a2446367267c6c0d9a26e734f0f78306 (patch) | |
tree | fb495d8c18801f271d124ee48731f10df396ca89 /libcutl/re/re.txx | |
parent | 4c8104756b92b9fa16b3a725e8a6aa620dfd606e (diff) |
Get rid of legacy build systems and rename cutl/ to libcutl/
Diffstat (limited to 'libcutl/re/re.txx')
-rw-r--r-- | libcutl/re/re.txx | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/libcutl/re/re.txx b/libcutl/re/re.txx new file mode 100644 index 0000000..d125ad8 --- /dev/null +++ b/libcutl/re/re.txx @@ -0,0 +1,68 @@ +// file : libcutl/re/re.txx +// license : MIT; see accompanying LICENSE file + +namespace cutl +{ + namespace re + { + // + // basic_regexsub + // + template <typename C> + void basic_regexsub<C>:: + init (string_type const& s) + { + string_type r; + typename string_type::size_type p (parse (s, 0, r)); + regex_ = r; + p = parse (s, p, sub_); + if (p + 1 < s.size ()) + throw basic_format<C> (s, "junk after third delimiter"); + } + + // + // parse() + // + template <typename C> + typename std::basic_string<C>::size_type + parse (std::basic_string<C> const& s, + typename std::basic_string<C>::size_type p, + std::basic_string<C>& r) + { + r.clear (); + typename std::basic_string<C>::size_type n (s.size ()); + + if (p >= n) + throw basic_format<C> (s, "empty expression"); + + C d (s[p++]); + + for (; p < n; ++p) + { + if (s[p] == d) + break; + + if (s[p] == '\\') + { + if (++p < n) + { + // Pass the escape sequence through unless it is the delimiter. + // + if (s[p] != d) + r += '\\'; + + r += s[p]; + } + // else {We ran out of stuff before finding the delimiter.} + } + else + r += s[p]; + } + + if (p == n) + throw basic_format<C> (s, "missing closing delimiter"); + + return p; + } + } +} |