1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <string>
10
11// size_type find_first_not_of(basic_string_view sv, size_type pos = 0) const; // constexpr since C++20
12
13#include <string>
14#include <cassert>
15
16#include "test_macros.h"
17#include "min_allocator.h"
18
19template <class S, class SV>
20TEST_CONSTEXPR_CXX20 void test(const S& s, SV sv, typename S::size_type pos, typename S::size_type x) {
21 LIBCPP_ASSERT_NOEXCEPT(s.find_first_not_of(sv, pos));
22 assert(s.find_first_not_of(sv, pos) == x);
23 if (x != S::npos)
24 assert(pos <= x && x < s.size());
25}
26
27template <class S, class SV>
28TEST_CONSTEXPR_CXX20 void test(const S& s, SV sv, typename S::size_type x) {
29 LIBCPP_ASSERT_NOEXCEPT(s.find_first_not_of(sv));
30 assert(s.find_first_not_of(sv) == x);
31 if (x != S::npos)
32 assert(x < s.size());
33}
34
35template <class S, class SV>
36TEST_CONSTEXPR_CXX20 void test0() {
37 test(S(""), SV(""), 0, S::npos);
38 test(S(""), SV("laenf"), 0, S::npos);
39 test(S(""), SV("pqlnkmbdjo"), 0, S::npos);
40 test(S(""), SV("qkamfogpnljdcshbreti"), 0, S::npos);
41 test(S(""), SV(""), 1, S::npos);
42 test(S(""), SV("bjaht"), 1, S::npos);
43 test(S(""), SV("hjlcmgpket"), 1, S::npos);
44 test(S(""), SV("htaobedqikfplcgjsmrn"), 1, S::npos);
45 test(S("fodgq"), SV(""), 0, 0);
46 test(S("qanej"), SV("dfkap"), 0, 0);
47 test(S("clbao"), SV("ihqrfebgad"), 0, 0);
48 test(S("mekdn"), SV("ngtjfcalbseiqrphmkdo"), 0, S::npos);
49 test(S("srdfq"), SV(""), 1, 1);
50 test(S("oemth"), SV("ikcrq"), 1, 1);
51 test(S("cdaih"), SV("dmajblfhsg"), 1, 3);
52 test(S("qohtk"), SV("oqftjhdmkgsblacenirp"), 1, S::npos);
53 test(S("cshmd"), SV(""), 2, 2);
54 test(S("lhcdo"), SV("oebqi"), 2, 2);
55 test(S("qnsoh"), SV("kojhpmbsfe"), 2, S::npos);
56 test(S("pkrof"), SV("acbsjqogpltdkhinfrem"), 2, S::npos);
57 test(S("fmtsp"), SV(""), 4, 4);
58 test(S("khbpm"), SV("aobjd"), 4, 4);
59 test(S("pbsji"), SV("pcbahntsje"), 4, 4);
60 test(S("mprdj"), SV("fhepcrntkoagbmldqijs"), 4, S::npos);
61 test(S("eqmpa"), SV(""), 5, S::npos);
62 test(S("omigs"), SV("kocgb"), 5, S::npos);
63 test(S("onmje"), SV("fbslrjiqkm"), 5, S::npos);
64 test(S("oqmrj"), SV("jeidpcmalhfnqbgtrsko"), 5, S::npos);
65 test(S("schfa"), SV(""), 6, S::npos);
66 test(S("igdsc"), SV("qngpd"), 6, S::npos);
67 test(S("brqgo"), SV("rodhqklgmb"), 6, S::npos);
68 test(S("tnrph"), SV("thdjgafrlbkoiqcspmne"), 6, S::npos);
69 test(S("hcjitbfapl"), SV(""), 0, 0);
70 test(S("daiprenocl"), SV("ashjd"), 0, 2);
71 test(S("litpcfdghe"), SV("mgojkldsqh"), 0, 1);
72 test(S("aidjksrolc"), SV("imqnaghkfrdtlopbjesc"), 0, S::npos);
73 test(S("qpghtfbaji"), SV(""), 1, 1);
74 test(S("gfshlcmdjr"), SV("nadkh"), 1, 1);
75 test(S("nkodajteqp"), SV("ofdrqmkebl"), 1, 4);
76 test(S("gbmetiprqd"), SV("bdfjqgatlksriohemnpc"), 1, S::npos);
77 test(S("crnklpmegd"), SV(""), 5, 5);
78 test(S("jsbtafedoc"), SV("prqgn"), 5, 5);
79 test(S("qnmodrtkeb"), SV("pejafmnokr"), 5, 6);
80 test(S("cpebqsfmnj"), SV("odnqkgijrhabfmcestlp"), 5, S::npos);
81 test(S("lmofqdhpki"), SV(""), 9, 9);
82 test(S("hnefkqimca"), SV("rtjpa"), 9, S::npos);
83 test(S("drtasbgmfp"), SV("ktsrmnqagd"), 9, 9);
84 test(S("lsaijeqhtr"), SV("rtdhgcisbnmoaqkfpjle"), 9, S::npos);
85 test(S("elgofjmbrq"), SV(""), 10, S::npos);
86 test(S("mjqdgalkpc"), SV("dplqa"), 10, S::npos);
87 test(S("kthqnfcerm"), SV("dkacjoptns"), 10, S::npos);
88 test(S("dfsjhanorc"), SV("hqfimtrgnbekpdcsjalo"), 10, S::npos);
89 test(S("eqsgalomhb"), SV(""), 11, S::npos);
90 test(S("akiteljmoh"), SV("lofbc"), 11, S::npos);
91 test(S("hlbdfreqjo"), SV("astoegbfpn"), 11, S::npos);
92 test(S("taqobhlerg"), SV("pdgreqomsncafklhtibj"), 11, S::npos);
93 test(S("snafbdlghrjkpqtoceim"), SV(""), 0, 0);
94 test(S("aemtbrgcklhndjisfpoq"), SV("lbtqd"), 0, 0);
95 test(S("pnracgfkjdiholtbqsem"), SV("tboimldpjh"), 0, 1);
96 test(S("dicfltehbsgrmojnpkaq"), SV("slcerthdaiqjfnobgkpm"), 0, S::npos);
97 test(S("jlnkraeodhcspfgbqitm"), SV(""), 1, 1);
98 test(S("lhosrngtmfjikbqpcade"), SV("aqibs"), 1, 1);
99 test(S("rbtaqjhgkneisldpmfoc"), SV("gtfblmqinc"), 1, 3);
100 test(S("gpifsqlrdkbonjtmheca"), SV("mkqpbtdalgniorhfescj"), 1, S::npos);
101 test(S("hdpkobnsalmcfijregtq"), SV(""), 10, 10);
102 test(S("jtlshdgqaiprkbcoenfm"), SV("pblas"), 10, 11);
103 test(S("fkdrbqltsgmcoiphneaj"), SV("arosdhcfme"), 10, 13);
104 test(S("crsplifgtqedjohnabmk"), SV("blkhjeogicatqfnpdmsr"), 10, S::npos);
105 test(S("niptglfbosehkamrdqcj"), SV(""), 19, 19);
106 test(S("copqdhstbingamjfkler"), SV("djkqc"), 19, 19);
107 test(S("mrtaefilpdsgocnhqbjk"), SV("lgokshjtpb"), 19, S::npos);
108 test(S("kojatdhlcmigpbfrqnes"), SV("bqjhtkfepimcnsgrlado"), 19, S::npos);
109 test(S("eaintpchlqsbdgrkjofm"), SV(""), 20, S::npos);
110 test(S("gjnhidfsepkrtaqbmclo"), SV("nocfa"), 20, S::npos);
111 test(S("spocfaktqdbiejlhngmr"), SV("bgtajmiedc"), 20, S::npos);
112 test(S("rphmlekgfscndtaobiqj"), SV("lsckfnqgdahejiopbtmr"), 20, S::npos);
113 test(S("liatsqdoegkmfcnbhrpj"), SV(""), 21, S::npos);
114 test(S("binjagtfldkrspcomqeh"), SV("gfsrt"), 21, S::npos);
115 test(S("latkmisecnorjbfhqpdg"), SV("pfsocbhjtm"), 21, S::npos);
116 test(S("lecfratdjkhnsmqpoigb"), SV("tpflmdnoicjgkberhqsa"), 21, S::npos);
117}
118
119template <class S, class SV>
120TEST_CONSTEXPR_CXX20 void test1() {
121 test(S(""), SV(""), S::npos);
122 test(S(""), SV("laenf"), S::npos);
123 test(S(""), SV("pqlnkmbdjo"), S::npos);
124 test(S(""), SV("qkamfogpnljdcshbreti"), S::npos);
125 test(S("nhmko"), SV(""), 0);
126 test(S("lahfb"), SV("irkhs"), 0);
127 test(S("gmfhd"), SV("kantesmpgj"), 2);
128 test(S("odaft"), SV("oknlrstdpiqmjbaghcfe"), S::npos);
129 test(S("eolhfgpjqk"), SV(""), 0);
130 test(S("nbatdlmekr"), SV("bnrpe"), 2);
131 test(S("jdmciepkaq"), SV("jtdaefblso"), 2);
132 test(S("hkbgspoflt"), SV("oselktgbcapndfjihrmq"), S::npos);
133 test(S("gprdcokbnjhlsfmtieqa"), SV(""), 0);
134 test(S("qjghlnftcaismkropdeb"), SV("bjaht"), 0);
135 test(S("pnalfrdtkqcmojiesbhg"), SV("hjlcmgpket"), 1);
136 test(S("pniotcfrhqsmgdkjbael"), SV("htaobedqikfplcgjsmrn"), S::npos);
137}
138
139template <class CharT, template <class> class Alloc>
140TEST_CONSTEXPR_CXX20 void test_string() {
141 using S = std::basic_string<CharT, std::char_traits<CharT>, Alloc<CharT> >;
142 using SV = std::basic_string_view<CharT, std::char_traits<CharT> >;
143
144 test0<S, SV>();
145 test1<S, SV>();
146}
147
148TEST_CONSTEXPR_CXX20 bool test() {
149 test_string<char, std::allocator>();
150#if TEST_STD_VER >= 11
151 test_string<char, min_allocator>();
152#endif
153
154 return true;
155}
156
157int main(int, char**) {
158 test();
159#if TEST_STD_VER > 17
160 static_assert(test());
161#endif
162
163 return 0;
164}
165

source code of libcxx/test/std/strings/basic.string/string.ops/string_find.first.not.of/string_view_size.pass.cpp