I am having problems with the format function in boost::regex_replace . I can call it one parameter, but not two parameters:
e = "(^|>)([^<>]+)"; h_str = regex_replace(h_str, e, repl_quot, boost::match_default);
Where repl_quot is defined as
std::string const &repl_quot(boost::smatch const &what) { boost::regex e("\""); std::string repl("""); static std::string; str = regex_replace(what[0].str(), e, repl, boost::match_default); return str; }
The above works, but I really do not want to use this static variable, so I tried what I considered an acceptable alternative version of two parameters:
std::string const &repl_quot2(boost::smatch const &what, std::string &out) { boost::regex e("\""); std::string repl("""); out = regex_replace(what[0].str(), e, repl, boost::match_default); return out; }
But regex_replace will not accept this (confusing compiler error). I am trying to use two versions of the parameters based on the following from the Boost::Regex documentation:
template basic_string regex_replace (Const basic_string & s, const basic_regex & , Formatter fmt, match_flag_type flags = match_default);
Required The Formatter type must be either ... a unary, binary or triple functor that computes the replacement string from the function call: either fmt (what), which should return the char_type's container for use as replacement text, or either fmt (what, out) or fmt (that, out, flags), both of which write replace the text with * out, and then return a new OutputIterator position. In each case, what is the match_results object that represents the match found.
The requests for the compiler error message were repeated, so here it is (be careful what you ask for):
c: \ boost \ boost \ regex \ v4 \ regex_format.hpp In the member function `OutputIter boost :: re_detail :: format_functor_container :: operator () (const Match &, OutputIter, boost :: regex_constants :: match_flag_type, const Traits & ) [with OutputIter = boost :: re_detail :: string_out_iterator, std :: allocator →, Container = const std :: string & (*) (const boost :: smatch &, std :: string &), Match = boost :: match_results <__ gnu_cxx :: __ normal_iterator, std :: allocator →, std :: allocator, std :: allocator → →, Traits = boost :: regex_traits_wrapper →]:
356 c: \ boost \ boost \ regex \ v4 \ match_results.hpp, created from `OutputIterator boost :: match_results :: format (OutputIterator, Functor, boost :: regex_constants :: match_flag_type, const RegexT &) const [with OutputIterator = boost :: re_detail :: string_out_iterator, std :: allocator →, Functor = const std :: string & (*) (const boost :: smatch &, std :: string &), RegexT = boost :: basic_regex →, BidiIterator = __gnu_cxx :: __ normal_iterator, std :: allocator →, Allocator = std :: allocator, std :: allocator → →]
60 c: \ boost \ boost \ regex \ v4 \ regex_replace.hpp, created from `OutputIterator boost :: regex_replace (OutputIterator, BidirectionalIterator, BidirectionalIterator, const boost :: basic_regex &, Formatter, boost :: regex_constants :: match_flag_type [ OutputIterator = boost :: re_detail :: string_out_iterator, std :: allocator →, BidirectionalIterator = __gnu_cxx :: __ normal_iterator, std :: allocator →, traits = boost :: regex_traits>, charT = char, Formatter = const std :: string & (*) (const boost :: smatch &, std :: string &)] '
80 c: \ boost \ boost \ regex \ v4 \ regex_replace.hpp, created from `std :: basic_string, std :: allocator <_T2 → boost :: regex_replace (const std :: basic_string, std :: allocator <_T2 → & , const boost :: basic_regex &, Formatter, boost :: regex_constants :: match_flag_type) [with traits = boost :: regex_traits>, charT = char, Formatter = const std :: string & (*) (const boost :: smatch & , std :: string &)] '
327 C: \ Dev-Cpp \ Examples \ wordrad \ xhtml_open.cpp created here
1064 c: \ boost \ boost \ regex \ v4 \ regex_format.hpp request for the begin' in member ((boost :: re_detail :: format_functor_container, std :: allocator →, std :: allocator, std :: allocator → →>, boost :: regex_traits_wrapper →>)) → boost :: re_detail :: format_functor_container, std :: allocator →, std :: allocator, std :: allocator → →> boost :: regex_traits_wrapper →> :: func ', which refers to non-class class `const std :: string & (* const) (const boost :: smatch &, std :: string &) '
1064 c: \ boost \ boost \ regex \ v4 \ regex_format.hpp request for member end' in ((boost :: re_detail :: format_functor_container, std :: allocator →, std :: allocator, std :: allocator → →>, boost :: regex_traits_wrapper →>)) → boost :: re_detail :: format_functor_container, std :: allocator →, std :: allocator, std :: allocator → →> boost :: regex_traits_wrapper →> :: func ', which refers to non-class class `const std :: string & (* const) (const boost :: smatch &, std :: string &) '