[libcxx] r232733 - Add code to honor the match_not_bol and match_not_eol regex flats. Fixes PR#22651. Thanks to Jim Porter for the report and suggested fix.

Marshall Clow mclow.lists at gmail.com
Thu Mar 19 10:05:59 PDT 2015


Author: marshall
Date: Thu Mar 19 12:05:59 2015
New Revision: 232733

URL: http://llvm.org/viewvc/llvm-project?rev=232733&view=rev
Log:
Add code to honor the match_not_bol and match_not_eol regex flats. Fixes PR#22651. Thanks to Jim Porter for the report and suggested fix.

Added:
    libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_bol.pass.cpp
    libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp
Modified:
    libcxx/trunk/include/regex

Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=232733&r1=232732&r2=232733&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Thu Mar 19 12:05:59 2015
@@ -1947,7 +1947,8 @@ template <class _CharT>
 void
 __l_anchor<_CharT>::__exec(__state& __s) const
 {
-    if (__s.__at_first_ && __s.__current_ == __s.__first_)
+    if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
+        !(__s.__flags_ & regex_constants::match_not_bol))
     {
         __s.__do_ = __state::__accept_but_not_consume;
         __s.__node_ = this->first();
@@ -1981,7 +1982,8 @@ template <class _CharT>
 void
 __r_anchor<_CharT>::__exec(__state& __s) const
 {
-    if (__s.__current_ == __s.__last_)
+    if (__s.__current_ == __s.__last_ &&
+        !(__s.__flags_ & regex_constants::match_not_eol))
     {
         __s.__do_ = __state::__accept_but_not_consume;
         __s.__node_ = this->first();

Added: libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_bol.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_bol.pass.cpp?rev=232733&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_bol.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_bol.pass.cpp Thu Mar 19 12:05:59 2015
@@ -0,0 +1,50 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// match_not_bol:
+//     The first character in the sequence [first,last) shall be treated as 
+//     though it is not at the beginning of a line, so the character ^ in the 
+//     regular expression shall not match [first,first).
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+    std::string target = "foo";
+    std::regex re("^foo");
+    assert( std::regex_match(target, re));
+    assert(!std::regex_match(target, re, std::regex_constants::match_not_bol));
+    }
+
+    {
+    std::string target = "foo";
+    std::regex re("foo");
+    assert( std::regex_match(target, re));
+    assert( std::regex_match(target, re, std::regex_constants::match_not_bol));
+    }
+
+    {
+    std::string target = "fooby";
+    std::regex re("^foo");
+    assert( std::regex_search(target, re));
+    assert(!std::regex_search(target, re, std::regex_constants::match_not_bol));
+    }
+
+    {
+    std::string target = "fooby";
+    std::regex re("foo");
+    assert( std::regex_search(target, re));
+    assert( std::regex_search(target, re, std::regex_constants::match_not_bol));
+    }
+}

Added: libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp?rev=232733&view=auto
==============================================================================
--- libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp (added)
+++ libcxx/trunk/test/std/re/re.const/re.matchflag/match_not_eol.pass.cpp Thu Mar 19 12:05:59 2015
@@ -0,0 +1,50 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <regex>
+
+// match_not_eol:
+//     The last character in the sequence [first,last) shall be treated as 
+//     though it is not at the end of a line, so the character "$" in 
+//     the regular expression shall not match [last,last).
+
+#include <regex>
+#include <cassert>
+
+int main()
+{
+    {
+    std::string target = "foo";
+    std::regex re("foo$");
+    assert( std::regex_match(target, re));
+    assert(!std::regex_match(target, re, std::regex_constants::match_not_eol));
+    }
+
+    {
+    std::string target = "foo";
+    std::regex re("foo");
+    assert( std::regex_match(target, re));
+    assert( std::regex_match(target, re, std::regex_constants::match_not_eol));
+    }
+
+    {
+    std::string target = "refoo";
+    std::regex re("foo$");
+    assert( std::regex_search(target, re));
+    assert(!std::regex_search(target, re, std::regex_constants::match_not_eol));
+    }
+
+    {
+    std::string target = "refoo";
+    std::regex re("foo");
+    assert( std::regex_search(target, re));
+    assert( std::regex_search(target, re, std::regex_constants::match_not_eol));
+    }
+}





More information about the cfe-commits mailing list