Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2008-07-31 12:53:29


Author: eric_niebler
Date: 2008-07-31 12:53:28 EDT (Thu, 31 Jul 2008)
New Revision: 47910
URL: http://svn.boost.org/trac/boost/changeset/47910

Log:
fix buggy eol matching behavior
Properties modified:
   branches/release/ (props changed)
Text files modified:
   branches/release/boost/xpressive/detail/core/matcher/assert_bol_matcher.hpp | 18 +++++++++++++++-
   branches/release/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp | 18 +++++++++++++++-
   branches/release/boost/xpressive/detail/core/matcher/assert_line_base.hpp | 20 -------------------
   branches/release/libs/xpressive/test/Jamfile.v2 | 4 +-
   branches/release/libs/xpressive/test/regress.ipp | 5 ++++
   branches/release/libs/xpressive/test/regress.txt | 41 ++++++++++++++++++++++++++++++++++++++++
   6 files changed, 80 insertions(+), 26 deletions(-)

Modified: branches/release/boost/xpressive/detail/core/matcher/assert_bol_matcher.hpp
==============================================================================
--- branches/release/boost/xpressive/detail/core/matcher/assert_bol_matcher.hpp (original)
+++ branches/release/boost/xpressive/detail/core/matcher/assert_bol_matcher.hpp 2008-07-31 12:53:28 EDT (Thu, 31 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))
+ 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: branches/release/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp
==============================================================================
--- branches/release/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp (original)
+++ branches/release/boost/xpressive/detail/core/matcher/assert_eol_matcher.hpp 2008-07-31 12:53:28 EDT (Thu, 31 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_eol_matcher
       : assert_line_base<Traits>
     {
+ typedef typename Traits::char_type char_type;
+
         assert_eol_matcher(Traits const &traits)
           : assert_line_base<Traits>(traits)
         {
@@ -43,9 +46,20 @@
                     return false;
                 }
             }
- else if((state.bos() && !state.flags_.match_prev_avail_) || !this->is_line_break(state))
+ 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: branches/release/boost/xpressive/detail/core/matcher/assert_line_base.hpp
==============================================================================
--- branches/release/boost/xpressive/detail/core/matcher/assert_line_base.hpp (original)
+++ branches/release/boost/xpressive/detail/core/matcher/assert_line_base.hpp 2008-07-31 12:53:28 EDT (Thu, 31 Jul 2008)
@@ -38,26 +38,6 @@
         {
         }
 
- template<typename BidiIter>
- bool is_line_break(match_state<BidiIter> &state) const
- {
- BOOST_ASSERT(!state.bos() || state.flags_.match_prev_avail_);
- BidiIter tmp = state.cur_;
- 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 || state.eos() || this->nl_ != *state.cur_)
- {
- return true;
- }
- }
-
- return false;
- }
-
- private:
         char_class_type newline_;
         char_type nl_, cr_;
     };

Modified: branches/release/libs/xpressive/test/Jamfile.v2
==============================================================================
--- branches/release/libs/xpressive/test/Jamfile.v2 (original)
+++ branches/release/libs/xpressive/test/Jamfile.v2 2008-07-31 12:53:28 EDT (Thu, 31 Jul 2008)
@@ -23,8 +23,8 @@
     ;
 
 test-suite "xpressive"
- : [ run regress.cpp ]
- [ run c_traits.cpp ]
+ : [ run regress.cpp : : : <dependency>regress.txt ]
+ [ run c_traits.cpp : : : <dependency>regress.txt ]
          [ run test1.cpp ]
          [ run test2.cpp ]
          [ run test3.cpp ]

Modified: branches/release/libs/xpressive/test/regress.ipp
==============================================================================
--- branches/release/libs/xpressive/test/regress.ipp (original)
+++ branches/release/libs/xpressive/test/regress.ipp 2008-07-31 12:53:28 EDT (Thu, 31 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: branches/release/libs/xpressive/test/regress.txt
==============================================================================
--- branches/release/libs/xpressive/test/regress.txt (original)
+++ branches/release/libs/xpressive/test/regress.txt 2008-07-31 12:53:28 EDT (Thu, 31 Jul 2008)
@@ -3697,3 +3697,44 @@
 br10=
 br11=b
 [end]
+
+[track2157.1]
+str=abc\ndef\nghi
+pat=^.+$
+flg=m
+br0=abc
+[end]
+
+[track2157.2]
+str=abc\ndef\nghi
+pat=.$
+flg=m
+br0=c
+[end]
+
+[track2157.3]
+str=abc\ndef\nghi
+pat=^.+$
+flg=
+[end]
+
+[track2157.4]
+str=abc\ndef\nghi
+pat=.$
+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