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