]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc
1 // { dg-do run { target c++11 } }
2 // { dg-timeout-factor 2 }
5 // 2013-07-25 Tim Shen <timshen91@gmail.com>
7 // Copyright (C) 2013-2021 Free Software Foundation, Inc.
9 // This file is part of the GNU ISO C++ Library. This library is free
10 // software; you can redistribute it and/or modify it under the
11 // terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 3, or (at your option)
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
24 // 28.12.1 regex_iterator
25 // Tests iter->position() behavior
29 #include <testsuite_hooks.h>
34 std::regex
re("asdf");
35 std::string
s("asdfasdfasdf");
37 for (std::sregex_iterator
it(s
.begin(), s
.end(), re
);
38 it
!= std::sregex_iterator();
40 VERIFY( it
->position() == 4 * i
);
48 std::regex
re("\\w+");
49 std::string
s("-a-b-c-");
51 std::tuple
<int, int, const char*> expected
[] =
53 std::make_tuple(1, 1, "a"),
54 std::make_tuple(3, 1, "b"),
55 std::make_tuple(5, 1, "c"),
59 for (auto it1
= std::sregex_iterator(s
.begin(), s
.end(), re
),
60 end
= std::sregex_iterator(); it1
!= end
; ++it1
, i
++)
63 VERIFY(it1
->position() == std::get
<0>(expected
[i
]));
64 VERIFY(it1
->length() == std::get
<1>(expected
[i
]));
65 VERIFY(it1
->str() == std::get
<2>(expected
[i
]));
66 VERIFY(it2
->position() == std::get
<0>(expected
[i
]));
67 VERIFY(it2
->length() == std::get
<1>(expected
[i
]));
68 VERIFY(it2
->str() == std::get
<2>(expected
[i
]));
76 std::string s
= "abcde";
77 std::regex_search(s
, m
, std::regex("bcd"));
78 VERIFY(m
.position() == 1);
79 VERIFY(m
.position() == m
.prefix().length());