Commit | Line | Data |
---|---|---|
fdc11678 SM |
1 | // { dg-options "-std=gnu++17" } |
2 | ||
3666a048 | 3 | // Copyright (C) 2013-2021 Free Software Foundation, Inc. |
fdc11678 SM |
4 | // |
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) | |
9 | // any later version. | |
10 | ||
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. | |
15 | ||
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/>. | |
19 | ||
20 | // basic_string_view find_first_not_of | |
21 | ||
c9638d26 | 22 | namespace operations_find_3 { |
fdc11678 | 23 | |
dd694d77 SM |
24 | static void |
25 | test03 () | |
fdc11678 | 26 | { |
c9638d26 SM |
27 | typedef gdb::string_view::size_type csize_type; |
28 | csize_type npos = gdb::string_view::npos; | |
fdc11678 SM |
29 | csize_type csz01; |
30 | ||
c9638d26 | 31 | const gdb::string_view str01("Bob Rock, per me"); |
fdc11678 | 32 | const char str_lit01[] = "Bob Rock"; |
c9638d26 SM |
33 | gdb::string_view str02("ovvero Trivi"); |
34 | gdb::string_view str03(str_lit01); | |
35 | gdb::string_view str04; | |
fdc11678 SM |
36 | |
37 | // size_type find_first_not_of(const string_view&, size_type pos = 0) const; | |
38 | csz01 = str01.find_first_not_of(str01); | |
39 | VERIFY( csz01 == npos ); | |
40 | csz01 = str01.find_first_not_of(str02, 0); | |
41 | VERIFY( csz01 == 0 ); | |
42 | csz01 = str01.find_first_not_of(str02, 10); | |
43 | VERIFY( csz01 == 10 ); | |
44 | csz01 = str01.find_first_not_of(str02, 12); | |
45 | VERIFY( csz01 == 14 ); | |
46 | csz01 = str01.find_first_not_of(str03, 0); | |
47 | VERIFY( csz01 == 8 ); | |
48 | csz01 = str01.find_first_not_of(str03, 15); | |
49 | VERIFY( csz01 == 15 ); | |
50 | csz01 = str01.find_first_not_of(str03, 16); | |
51 | VERIFY( csz01 == npos ); | |
52 | csz01 = str01.find_first_not_of(str04, 0); | |
53 | VERIFY( csz01 == 0 ); | |
54 | csz01 = str01.find_first_not_of(str04, 12); | |
55 | VERIFY( csz01 == 12 ); | |
56 | csz01 = str03.find_first_not_of(str01, 0); | |
57 | VERIFY( csz01 == npos ); | |
58 | csz01 = str04.find_first_not_of(str02, 0); | |
59 | VERIFY( csz01 == npos ); | |
60 | ||
61 | // size_type find_first_not_of(const char* s, size_type pos, size_type n) const; | |
62 | csz01 = str01.find_first_not_of(str_lit01, 0, 0); | |
63 | VERIFY( csz01 == 0 ); | |
64 | csz01 = str01.find_first_not_of(str_lit01, 0, 8); | |
65 | VERIFY( csz01 == 8 ); | |
66 | csz01 = str01.find_first_not_of(str_lit01, 10, 0); | |
67 | VERIFY( csz01 == 10 ); | |
68 | ||
69 | // size_type find_first_not_of(const char* s, size_type pos = 0) const; | |
70 | csz01 = str01.find_first_not_of(str_lit01); | |
71 | VERIFY( csz01 == 8 ); | |
72 | csz01 = str02.find_first_not_of(str_lit01, 2); | |
73 | VERIFY( csz01 == 2 ); | |
74 | ||
75 | // size_type find_first_not_of(char c, size_type pos = 0) const; | |
76 | csz01 = str01.find_first_not_of('B'); | |
77 | VERIFY( csz01 == 1 ); | |
78 | csz01 = str01.find_first_not_of('o', 1); | |
79 | VERIFY( csz01 == 2 ); | |
80 | csz01 = str02.find_first_not_of('z'); | |
81 | VERIFY( csz01 == 0 ); | |
82 | csz01 = str04.find_first_not_of('S'); | |
83 | VERIFY( csz01 == npos ); | |
84 | } | |
85 | ||
c9638d26 | 86 | #ifndef GDB_STRING_VIEW |
fdc11678 SM |
87 | constexpr bool |
88 | test04() | |
89 | { | |
90 | typedef std::string_view::size_type csize_type; | |
91 | csize_type npos = std::string_view::npos; | |
92 | csize_type csz01 = 0; | |
93 | ||
94 | const std::string_view str01("Bob Rock, per me"); | |
95 | const char str_lit01[] = "Bob Rock"; | |
96 | std::string_view str02("ovvero Trivi"); | |
97 | std::string_view str03(str_lit01); | |
98 | std::string_view str04; | |
99 | ||
100 | #undef VERIFY | |
101 | #define VERIFY(x) if(!(x)) return false | |
102 | ||
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 ); | |
126 | ||
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 ); | |
134 | ||
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 ); | |
140 | ||
141 | // size_type find_first_not_of(char c, size_type pos = 0) const; | |
142 | csz01 = str01.find_first_not_of('B'); | |
143 | VERIFY( csz01 == 1 ); | |
144 | csz01 = str01.find_first_not_of('o', 1); | |
145 | VERIFY( csz01 == 2 ); | |
146 | csz01 = str02.find_first_not_of('z'); | |
147 | VERIFY( csz01 == 0 ); | |
148 | csz01 = str04.find_first_not_of('S'); | |
149 | VERIFY( csz01 == npos ); | |
150 | ||
151 | return true; | |
152 | } | |
c9638d26 | 153 | #endif |
fdc11678 | 154 | |
dd694d77 SM |
155 | static int |
156 | main () | |
fdc11678 SM |
157 | { |
158 | test03(); | |
c9638d26 | 159 | #ifndef GDB_STRING_VIEW |
fdc11678 | 160 | static_assert( test04() ); |
c9638d26 | 161 | #endif |
fdc11678 SM |
162 | |
163 | return 0; | |
164 | } | |
c9638d26 SM |
165 | |
166 | } // namespace operations_find_3 |