Update of /cvsroot/boost/boost/boost/xpressive
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21135
Modified Files:
match_results.hpp regex_constants.hpp regex_error.hpp
Log Message:
preliminary implementation of format_all flag
Index: match_results.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/match_results.hpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- match_results.hpp 18 Mar 2007 05:01:18 -0000 1.9
+++ match_results.hpp 18 Mar 2007 07:07:00 -0000 1.10
@@ -162,6 +162,35 @@
return true;
}
+///////////////////////////////////////////////////////////////////////////////
+// noop_output_iterator
+//
+struct noop_output_iterator
+ : std::iterator<std::output_iterator_tag, void, void, void, void>
+{
+ noop_output_iterator &operator ++()
+ {
+ return *this;
+ }
+
+ noop_output_iterator &operator ++(int)
+ {
+ return *this;
+ }
+
+ noop_output_iterator &operator *()
+ {
+ return *this;
+ }
+
+ template<typename T>
+ noop_output_iterator &operator =(T const &)
+ {
+ return *this;
+ }
+};
+
+
} // namespace detail
///////////////////////////////////////////////////////////////////////////////
@@ -408,6 +437,10 @@
{
return this->format_sed_(cur, end, out);
}
+ else if(0 != (regex_constants::format_all & flags))
+ {
+ return this->format_all_(cur, end, out);
+ }
return this->format_ecma_262_(cur, end, out);
}
@@ -637,6 +670,82 @@
/// INTERNAL ONLY
///
+ template<typename ForwardIterator, typename OutputIterator>
+ OutputIterator format_all_(ForwardIterator cur, ForwardIterator end,
OutputIterator out) const
+ {
+ detail::case_converting_iterator<OutputIterator, char_type> iout(out,
this->traits_.get());
+ iout = this->format_all_impl_(cur, end, iout);
+ detail::ensure(cur == end
+ , regex_constants::error_paren, "unbalanced parentheses in format
string");
+ return iout.base();
+ }
+
+ /// INTERNAL ONLY
+ ///
+ template<typename ForwardIterator, typename OutputIterator>
+ OutputIterator format_all_impl_(ForwardIterator &cur, ForwardIterator end,
OutputIterator out, bool metacolon = false) const
+ {
+ int max = 0, sub = 0;
+ detail::noop_output_iterator noop;
+
+ while(cur != end)
+ {
+ switch(*cur)
+ {
+ case BOOST_XPR_CHAR_(char_type, '$'):
+ out = this->format_backref_(++cur, end, out);
+ break;
+
+ case BOOST_XPR_CHAR_(char_type, '\\'):
+ out = this->format_escape_(++cur, end, out);
+ break;
+
+ case BOOST_XPR_CHAR_(char_type, '('):
+ out = this->format_all_impl_(++cur, end, out);
+ detail::ensure(BOOST_XPR_CHAR_(char_type, ')') == *(cur-1)
+ , regex_constants::error_paren, "unbalanced parentheses in
format string");
+ break;
+
+ case BOOST_XPR_CHAR_(char_type, '?'):
+ detail::ensure(++cur != end
+ , regex_constants::error_subreg, "malformed conditional in
format string");
+ max = static_cast<int>(this->size() - 1);
+ sub = detail::toi(cur, end, *this->traits_, 10, max);
+ detail::ensure(0 != sub, regex_constants::error_subreg,
"invalid back-reference");
+ if(this->sub_matches_[ sub ].matched)
+ {
+ out = this->format_all_impl_(cur, end, out, true);
+ if(BOOST_XPR_CHAR_(char_type, ':') == *(cur-1))
+ this->format_all_impl_(cur, end, noop);
+ }
+ else
+ {
+ this->format_all_impl_(cur, end, noop, true);
+ if(BOOST_XPR_CHAR_(char_type, ':') == *(cur-1))
+ out = this->format_all_impl_(cur, end, out);
+ }
+ return out;
+
+ case BOOST_XPR_CHAR_(char_type, ':'):
+ if(metacolon)
+ {
+ case BOOST_XPR_CHAR_(char_type, ')'):
+ ++cur;
+ return out;
+ }
+ // else fall-through
+
+ default:
+ *out++ = *cur++;
+ break;
+ }
+ }
+
+ return out;
+ }
+
+ /// INTERNAL ONLY
+ ///
template<typename OutputIterator>
OutputIterator format_backref_
(
@@ -673,7 +782,8 @@
int max = static_cast<int>(this->size() - 1);
int sub = detail::toi(cur, end, *this->traits_, 10, max);
detail::ensure(0 != sub, regex_constants::error_subreg, "invalid
back-reference");
- out = std::copy(this->sub_matches_[ sub ].first,
this->sub_matches_[ sub ].second, out);
+ if(this->sub_matches_[ sub ].matched)
+ out = std::copy(this->sub_matches_[ sub ].first,
this->sub_matches_[ sub ].second, out);
}
else
{
@@ -811,7 +921,8 @@
if(0 < this->traits_->value(ch, 10))
{
int sub = this->traits_->value(ch, 10);
- out = std::copy(this->sub_matches_[ sub ].first,
this->sub_matches_[ sub ].second, out);
+ if(this->sub_matches_[ sub ].matched)
+ out = std::copy(this->sub_matches_[ sub ].first,
this->sub_matches_[ sub ].second, out);
}
else
{
Index: regex_constants.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/regex_constants.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- regex_constants.hpp 18 Mar 2007 05:01:18 -0000 1.6
+++ regex_constants.hpp 18 Mar 2007 07:07:00 -0000 1.7
@@ -176,7 +176,11 @@
///< then only the first occurrence of
the regular
///< expression is replaced.
///<
- format_literal = 1 << 17 ///< Treat the format string as a
literal.
+ format_literal = 1 << 17, ///< Treat the format string as a
literal.
+ ///<
+ format_all = 1 << 18 ///< Specifies that all syntax
extensions are enabled,
+ ///< including conditional
(?ddexpression1:expression2)
+ ///< replacements.
///<
};
Index: regex_error.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/regex_error.hpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- regex_error.hpp 18 Mar 2006 04:50:24 -0000 1.4
+++ regex_error.hpp 18 Mar 2007 07:07:00 -0000 1.5
@@ -74,7 +74,11 @@
/// INTERNAL ONLY
inline bool ensure(bool predicate, regex_constants::error_type code, char
const *str = "")
{
- return predicate ? true : throw regex_error(code, str);
+ if(!predicate)
+ {
+ throw regex_error(code, str);
+ }
+ return true;
}
}}} // namespace boost::xpressive::detail
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs