[PATCH][libcxx] regex_iterator needs to handle /^a/ anchor correctly

Howard Hinnant hhinnant at apple.com
Tue Jul 9 10:31:09 PDT 2013


Committed revision 185950.

Thanks Bill!

Howard

On Jul 8, 2013, at 11:13 PM, William Fisher <william.w.fisher at gmail.com> wrote:

> This patch fixes a bug where regex_iterator doesn't indicate when it's restarting in the middle of a string. This bug causes /^a/ to match in the middle of the string "aaaaaaa", during iteration.
> 
> My patch uses `__no_update_pos` to communicate when `__at_first` is false.
> 
> Here is the test case:
> 
> ```
> #include <regex>
> #include <cassert>
> 
> int main()
> {
>     // Iterating over /^a/ should yield one instance at the beginning
>     // of the text.
> 
>     const char *text = "aaa\naa";
>     std::regex re{"^a"};
>     std::cregex_iterator it{text, text+6, re};
>     std::cregex_iterator end{};
> 
>     assert(it->str() == "a");
>     assert(it->position(0) == 0);
>     assert(it->length(0) == 1);
> 
>     ++it;
>     assert(it == end);
> }
> ```
> <regex_iter.patch>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list