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