]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string_view/operations/rfind/char/1.cc
1 // { dg-options "-std=gnu++17" }
2 // { dg-do run { target c++17 } }
4 // Copyright (C) 2013-2021 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 #include <string_view>
22 #include <testsuite_hooks.h>
24 // basic_string_view rfind
29 typedef std::string_view::size_type csize_type
;
30 typedef std::string_view::const_reference cref
;
31 typedef std::string_view::reference ref
;
32 csize_type npos
= std::string_view::npos
;
33 csize_type csz01
, csz02
;
35 const char str_lit01
[] = "mave";
36 const std::string_view
str01("mavericks, santa cruz");
37 std::string_view
str02(str_lit01
);
38 std::string_view
str03("s, s");
39 std::string_view str04
;
41 // size_type rfind(const string_view&, size_type pos = 0) const;
42 csz01
= str01
.rfind(str01
);
44 csz01
= str01
.rfind(str01
, 4);
46 csz01
= str01
.rfind(str02
,3);
48 csz01
= str01
.rfind(str02
);
50 csz01
= str01
.rfind(str03
);
52 csz01
= str01
.rfind(str03
, 3);
53 VERIFY( csz01
== npos
);
54 csz01
= str01
.rfind(str03
, 12);
57 // An empty string_view consists of no characters
58 // therefore it should be found at every point in a string_view,
59 // except beyond the end
60 csz01
= str01
.rfind(str04
, 0);
62 csz01
= str01
.rfind(str04
, 5);
64 csz01
= str01
.rfind(str04
, str01
.size());
65 VERIFY( csz01
== str01
.size() );
66 csz01
= str01
.rfind(str04
, str01
.size()+1);
67 VERIFY( csz01
== str01
.size() );
69 // size_type rfind(const char* s, size_type pos, size_type n) const;
70 csz01
= str01
.rfind(str_lit01
, 0, 3);
72 csz01
= str01
.rfind(str_lit01
, 3, 0);
75 // size_type rfind(const char* s, size_type pos = 0) const;
76 csz01
= str01
.rfind(str_lit01
);
78 csz01
= str01
.rfind(str_lit01
, 3);
81 // size_type rfind(char c, size_type pos = 0) const;
82 csz01
= str01
.rfind('z');
83 csz02
= str01
.size() - 1;
84 VERIFY( csz01
== csz02
);
85 csz01
= str01
.rfind('/');
86 VERIFY( csz01
== npos
);