...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::log::expressions::pattern_replacer
// In header: <boost/log/expressions/formatters/char_decorator.hpp> template<typename CharT> class pattern_replacer { public: // types typedef void result_type; // Result type. typedef CharT char_type; // Character type. typedef std::basic_string< char_type > string_type; // String type. // member classes/structs/unions // Lengths of source pattern and replacement. struct string_lengths { // public data members unsigned int from_len; unsigned int to_len; }; // construct/copy/destruct template<typename RangeT> explicit pattern_replacer(RangeT const &); template<typename FromRangeT, typename ToRangeT> pattern_replacer(FromRangeT const &, ToRangeT const &); pattern_replacer(pattern_replacer const &); // public member functions result_type operator()(string_type &, typename string_type::size_type = 0) const; // private static functions static char_type * string_begin(char_type *); static const char_type * string_begin(const char_type *); template<typename RangeT> static range_const_iterator< RangeT >::type string_begin(RangeT const &); static char_type * string_end(char_type *); static const char_type * string_end(const char_type *); template<typename RangeT> static range_const_iterator< RangeT >::type string_end(RangeT const &); };
A simple character decorator implementation. This implementation replaces string patterns in the source string with the fixed replacements. Source patterns and replacements can be specified at the object construction.
pattern_replacer
public
construct/copy/destructtemplate<typename RangeT> explicit pattern_replacer(RangeT const & decorations);
Initializing constructor. Creates a pattern replacer with the specified decorations. The provided decorations must be a sequence of std::pair
of strings. The first element of each pair is the source pattern, and the second one is the corresponding replacement.
template<typename FromRangeT, typename ToRangeT> pattern_replacer(FromRangeT const & from, ToRangeT const & to);
Initializing constructor. Creates a pattern replacer with decorations specified in form of two same-sized string sequences. Each i
'th decoration will be from[i]
-> to[i]
.
pattern_replacer(pattern_replacer const & that);Copy constructor.
pattern_replacer
private static functionsstatic char_type * string_begin(char_type * p);
static const char_type * string_begin(const char_type * p);
template<typename RangeT> static range_const_iterator< RangeT >::type string_begin(RangeT const & r);
static char_type * string_end(char_type * p);
static const char_type * string_end(const char_type * p);
template<typename RangeT> static range_const_iterator< RangeT >::type string_end(RangeT const & r);