1 // { dg-options "-std=gnu++17" }
3 // Copyright (C) 2013-2022 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // basic_string_view find_first_not_of
22 #include <string_view>
23 #include <testsuite_hooks.h>
28 typedef std::wstring_view::size_type csize_type
;
29 csize_type npos
= std::wstring_view::npos
;
32 const std::wstring_view
str01(L
"Bob Rock, per me");
33 const wchar_t str_lit01
[] = L
"Bob Rock";
34 std::wstring_view
str02(L
"ovvero Trivi");
35 std::wstring_view
str03(str_lit01
);
36 std::wstring_view str04
;
38 // size_type find_first_not_of(const string_view&, size_type pos = 0) const;
39 csz01
= str01
.find_first_not_of(str01
);
40 VERIFY( csz01
== npos
);
41 csz01
= str01
.find_first_not_of(str02
, 0);
43 csz01
= str01
.find_first_not_of(str02
, 10);
44 VERIFY( csz01
== 10 );
45 csz01
= str01
.find_first_not_of(str02
, 12);
46 VERIFY( csz01
== 14 );
47 csz01
= str01
.find_first_not_of(str03
, 0);
49 csz01
= str01
.find_first_not_of(str03
, 15);
50 VERIFY( csz01
== 15 );
51 csz01
= str01
.find_first_not_of(str03
, 16);
52 VERIFY( csz01
== npos
);
53 csz01
= str01
.find_first_not_of(str04
, 0);
55 csz01
= str01
.find_first_not_of(str04
, 12);
56 VERIFY( csz01
== 12 );
57 csz01
= str03
.find_first_not_of(str01
, 0);
58 VERIFY( csz01
== npos
);
59 csz01
= str04
.find_first_not_of(str02
, 0);
60 VERIFY( csz01
== npos
);
62 // size_type find_first_not_of(const char* s, size_type pos, size_type n) const;
63 csz01
= str01
.find_first_not_of(str_lit01
, 0, 0);
65 csz01
= str01
.find_first_not_of(str_lit01
, 0, 8);
67 csz01
= str01
.find_first_not_of(str_lit01
, 10, 0);
68 VERIFY( csz01
== 10 );
70 // size_type find_first_not_of(const char* s, size_type pos = 0) const;
71 csz01
= str01
.find_first_not_of(str_lit01
);
73 csz01
= str02
.find_first_not_of(str_lit01
, 2);
76 // size_type find_first_not_of(char c, size_type pos = 0) const;
77 csz01
= str01
.find_first_not_of(L
'B');
79 csz01
= str01
.find_first_not_of(L
'o', 1);
81 csz01
= str02
.find_first_not_of(L
'z');
83 csz01
= str04
.find_first_not_of(L
'S');
84 VERIFY( csz01
== npos
);
90 typedef std::wstring_view::size_type csize_type
;
91 csize_type npos
= std::wstring_view::npos
;
94 const std::wstring_view
str01(L
"Bob Rock, per me");
95 const wchar_t str_lit01
[] = L
"Bob Rock";
96 std::wstring_view
str02(L
"ovvero Trivi");
97 std::wstring_view
str03(str_lit01
);
98 std::wstring_view str04
;
101 #define VERIFY(x) if(!(x)) return false
103 // size_type find_first_not_of(const string_view&, size_type pos = 0) const;
104 csz01
= str01
.find_first_not_of(str01
);
105 VERIFY( csz01
== npos
);
106 csz01
= str01
.find_first_not_of(str02
, 0);
107 VERIFY( csz01
== 0 );
108 csz01
= str01
.find_first_not_of(str02
, 10);
109 VERIFY( csz01
== 10 );
110 csz01
= str01
.find_first_not_of(str02
, 12);
111 VERIFY( csz01
== 14 );
112 csz01
= str01
.find_first_not_of(str03
, 0);
113 VERIFY( csz01
== 8 );
114 csz01
= str01
.find_first_not_of(str03
, 15);
115 VERIFY( csz01
== 15 );
116 csz01
= str01
.find_first_not_of(str03
, 16);
117 VERIFY( csz01
== npos
);
118 csz01
= str01
.find_first_not_of(str04
, 0);
119 VERIFY( csz01
== 0 );
120 csz01
= str01
.find_first_not_of(str04
, 12);
121 VERIFY( csz01
== 12 );
122 csz01
= str03
.find_first_not_of(str01
, 0);
123 VERIFY( csz01
== npos
);
124 csz01
= str04
.find_first_not_of(str02
, 0);
125 VERIFY( csz01
== npos
);
127 // size_type find_first_not_of(const char* s, size_type pos, size_type n) const;
128 csz01
= str01
.find_first_not_of(str_lit01
, 0, 0);
129 VERIFY( csz01
== 0 );
130 csz01
= str01
.find_first_not_of(str_lit01
, 0, 8);
131 VERIFY( csz01
== 8 );
132 csz01
= str01
.find_first_not_of(str_lit01
, 10, 0);
133 VERIFY( csz01
== 10 );
135 // size_type find_first_not_of(const char* s, size_type pos = 0) const;
136 csz01
= str01
.find_first_not_of(str_lit01
);
137 VERIFY( csz01
== 8 );
138 csz01
= str02
.find_first_not_of(str_lit01
, 2);
139 VERIFY( csz01
== 2 );
141 // size_type find_first_not_of(char c, size_type pos = 0) const;
142 csz01
= str01
.find_first_not_of(L
'B');
143 VERIFY( csz01
== 1 );
144 csz01
= str01
.find_first_not_of(L
'o', 1);
145 VERIFY( csz01
== 2 );
146 csz01
= str02
.find_first_not_of(L
'z');
147 VERIFY( csz01
== 0 );
148 csz01
= str04
.find_first_not_of(L
'S');
149 VERIFY( csz01
== npos
);
158 static_assert( test04() );