Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2008-07-30 19:21:43


Author: eric_niebler
Date: 2008-07-30 19:21:43 EDT (Wed, 30 Jul 2008)
New Revision: 47901
URL: http://svn.boost.org/trac/boost/changeset/47901

Log:
ok, really fix end-of-line handling (fixes #2157)
Text files modified:
   trunk/boost/xpressive/detail/core/matcher/assert_bol_matcher.hpp | 18 ++++++++++++++++--
   trunk/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp | 17 +++++++++++++++--
   trunk/boost/xpressive/detail/core/matcher/assert_line_base.hpp | 20 --------------------
   trunk/libs/xpressive/test/regress.ipp | 5 +++++
   trunk/libs/xpressive/test/regress.txt | 14 ++++++++++++++
   5 files changed, 50 insertions(+), 24 deletions(-)

Modified: trunk/boost/xpressive/detail/core/matcher/assert_bol_matcher.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/matcher/assert_bol_matcher.hpp (original)
+++ trunk/boost/xpressive/detail/core/matcher/assert_bol_matcher.hpp 2008-07-30 19:21:43 EDT (Wed, 30 Jul 2008)
@@ -13,6 +13,7 @@
 # pragma once
 #endif
 
+#include <boost/next_prior.hpp>
 #include <boost/xpressive/detail/detail_fwd.hpp>
 #include <boost/xpressive/detail/core/quant_style.hpp>
 #include <boost/xpressive/detail/core/state.hpp>
@@ -28,6 +29,8 @@
     struct assert_bol_matcher
       : assert_line_base<Traits>
     {
+ typedef typename Traits::char_type char_type;
+
         assert_bol_matcher(Traits const &traits)
           : assert_line_base<Traits>(traits)
         {
@@ -43,9 +46,20 @@
                     return false;
                 }
             }
- else if(!this->is_line_break(state, state.cur_))
+ else
             {
- return false;
+ char_type ch = *boost::prior(state.cur_);
+
+ // If the previous character is not a newline, we're not at the start of a line
+ if(!traits_cast<Traits>(state).isctype(ch, this->newline_))
+ {
+ return false;
+ }
+ // There is no line-break between \r and \n
+ else if(ch == this->cr_ && !state.eos() && *state.cur_ == this->nl_)
+ {
+ return false;
+ }
             }
 
             return next.match(state);

Modified: trunk/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp (original)
+++ trunk/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp 2008-07-30 19:21:43 EDT (Wed, 30 Jul 2008)
@@ -29,6 +29,8 @@
     struct assert_eol_matcher
       : assert_line_base<Traits>
     {
+ typedef typename Traits::char_type char_type;
+
         assert_eol_matcher(Traits const &traits)
           : assert_line_base<Traits>(traits)
         {
@@ -44,9 +46,20 @@
                     return false;
                 }
             }
- else if((state.bos() && !state.flags_.match_prev_avail_) || !this->is_line_break(state, boost::next(state.cur_)))
+ else
             {
- return false;
+ char_type ch = *state.cur_;
+
+ // If the current character is not a newline, we're not at the end of a line
+ if(!traits_cast<Traits>(state).isctype(ch, this->newline_))
+ {
+ return false;
+ }
+ // There is no line-break between \r and \n
+ else if(ch == this->nl_ && (!state.bos() || state.flags_.match_prev_avail_) && *boost::prior(state.cur_) == this->cr_)
+ {
+ return false;
+ }
             }
 
             return next.match(state);

Modified: trunk/boost/xpressive/detail/core/matcher/assert_line_base.hpp
==============================================================================
--- trunk/boost/xpressive/detail/core/matcher/assert_line_base.hpp (original)
+++ trunk/boost/xpressive/detail/core/matcher/assert_line_base.hpp 2008-07-30 19:21:43 EDT (Wed, 30 Jul 2008)
@@ -38,26 +38,6 @@
         {
         }
 
- template<typename BidiIter>
- bool is_line_break(match_state<BidiIter> &state, BidiIter where) const
- {
- BOOST_ASSERT(where != state.begin_ || state.flags_.match_prev_avail_);
- BidiIter tmp = where;
- char_type ch = *--tmp;
-
- if(traits_cast<Traits>(state).isctype(ch, this->newline_))
- {
- // there is no line-break between \r and \n
- if(this->cr_ != ch || where == state.end_ || this->nl_ != *where)
- {
- return true;
- }
- }
-
- return false;
- }
-
- private:
         char_class_type newline_;
         char_type nl_, cr_;
     };

Modified: trunk/libs/xpressive/test/regress.ipp
==============================================================================
--- trunk/libs/xpressive/test/regress.ipp (original)
+++ trunk/libs/xpressive/test/regress.ipp 2008-07-30 19:21:43 EDT (Wed, 30 Jul 2008)
@@ -173,6 +173,11 @@
     {
         std::getline(in, line);
 
+ if(!line.empty() && '\r' == line[line.size()-1])
+ {
+ line.erase(line.size()-1);
+ }
+
         if(regex_match(line, what, rx_sec))
         {
             if(!first)

Modified: trunk/libs/xpressive/test/regress.txt
==============================================================================
--- trunk/libs/xpressive/test/regress.txt (original)
+++ trunk/libs/xpressive/test/regress.txt 2008-07-30 19:21:43 EDT (Wed, 30 Jul 2008)
@@ -3724,3 +3724,17 @@
 flg=
 br0=i
 [end]
+
+[track2157.5]
+str=abc\r\ndef\r\nghi
+pat=^.+$
+flg=m
+br0=abc
+[end]
+
+[track2157.6]
+str=abc\r\ndef\r\nghi
+pat=.$
+flg=m
+br0=c
+[end]


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk