diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2017-09-22 23:32:28 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2017-09-22 23:32:28 +0200 |
commit | c09cd7512491cee1e82c1ad8128ce9fd4bc3f79b (patch) | |
tree | a659ed768d849130ab5780a11b7f791a463a1a91 /libbutl/regex.mxx | |
parent | 2a00871f07067f8f9e2de08bb9c8f50e1bf6a650 (diff) |
Initial modularization with both Clang and VC hacks
Note: gave up on VC about half way though.
Diffstat (limited to 'libbutl/regex.mxx')
-rw-r--r-- | libbutl/regex.mxx | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/libbutl/regex.mxx b/libbutl/regex.mxx new file mode 100644 index 0000000..ca677a5 --- /dev/null +++ b/libbutl/regex.mxx @@ -0,0 +1,98 @@ +// file : libbutl/regex.mxx -*- C++ -*- +// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef __cpp_modules +#pragma once +#endif + +// C includes. + +#ifndef __cpp_lib_modules +#include <regex> +#include <iosfwd> +#include <string> +#include <utility> // pair + +#include <locale> +#include <cstddef> // size_t +#include <utility> // move(), make_pair() +#endif + +#if defined(__clang__) && __has_include(<__config>) +# include <__config> // _LIBCPP_VERSION +#endif + +// Other includes. + +#ifdef __cpp_modules +export module butl.regex; +#ifdef __cpp_lib_modules +import std.core; +import std.io; +//@@ MOD TODO import std.regex; +#endif +#endif + +#include <libbutl/export.hxx> + +LIBBUTL_MODEXPORT namespace butl +{ + // Call specified append() function for non-matched substrings and matched + // substring replacements returning true if search succeeded. The function + // must be callable with the following signature: + // + // void + // append(basic_string<C>::iterator begin, basic_string<C>::iterator end); + // + // The regex semantics is like that of std::regex_replace() extended the + // standard ECMA-262 substitution escape sequences with a subset of Perl + // sequences: + // + // \\, \u, \l, \U, \L, \E, \1, ..., \9 + // + // Notes and limitations: + // + // - The only valid regex_constants flags are match_default, + // format_first_only and format_no_copy. + // + // - If backslash doesn't start any of the listed sequences then it is + // silently dropped and the following character is copied as is. + // + // - The character case conversion is performed according to the global + // C++ locale (which is, unless changed, is the same as C locale and + // both default to the POSIX locale aka "C"). + // + template <typename C, typename F> + bool + regex_replace_ex (const std::basic_string<C>&, + const std::basic_regex<C>&, + const std::basic_string<C>& fmt, + F&& append, + std::regex_constants::match_flag_type = + std::regex_constants::match_default); + + // As above but concatenate non-matched substrings and matched substring + // replacements into a string returning it as well as whether the search + // succeeded. + // + template <typename C> + std::pair<std::basic_string<C>, bool> + regex_replace_ex (const std::basic_string<C>&, + const std::basic_regex<C>&, + const std::basic_string<C>& fmt, + std::regex_constants::match_flag_type = + std::regex_constants::match_default); +} + +LIBBUTL_MODEXPORT namespace std +{ + // Print regex error description but only if it is meaningful (this is also + // why we have to print leading colon). + // + LIBBUTL_SYMEXPORT ostream& + operator<< (ostream&, const regex_error&); +} + +#include <libbutl/regex.ixx> +#include <libbutl/regex.txx> |