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