Home | History | Annotate | Download | only in string_find.last.not.of
      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_last_not_of(charT c, size_type pos = npos) 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, typename S::value_type c, typename S::size_type pos,
     22      typename S::size_type x)
     23 {
     24     assert(s.find_last_not_of(c, pos) == x);
     25     if (x != S::npos)
     26         assert(x <= pos && x < s.size());
     27 }
     28 
     29 template <class S>
     30 void
     31 test(const S& s, typename S::value_type c, typename S::size_type x)
     32 {
     33     assert(s.find_last_not_of(c) == x);
     34     if (x != S::npos)
     35         assert(x < s.size());
     36 }
     37 
     38 int main()
     39 {
     40     {
     41     typedef std::string S;
     42     test(S(""), 'i', 0, S::npos);
     43     test(S(""), 'i', 1, S::npos);
     44     test(S("kitcj"), 'i', 0, 0);
     45     test(S("qkamf"), 'i', 1, 1);
     46     test(S("nhmko"), 'i', 2, 2);
     47     test(S("tpsaf"), 'i', 4, 4);
     48     test(S("lahfb"), 'i', 5, 4);
     49     test(S("irkhs"), 'i', 6, 4);
     50     test(S("gmfhdaipsr"), 'i', 0, 0);
     51     test(S("kantesmpgj"), 'i', 1, 1);
     52     test(S("odaftiegpm"), 'i', 5, 4);
     53     test(S("oknlrstdpi"), 'i', 9, 8);
     54     test(S("eolhfgpjqk"), 'i', 10, 9);
     55     test(S("pcdrofikas"), 'i', 11, 9);
     56     test(S("nbatdlmekrgcfqsophij"), 'i', 0, 0);
     57     test(S("bnrpehidofmqtcksjgla"), 'i', 1, 1);
     58     test(S("jdmciepkaqgotsrfnhlb"), 'i', 10, 10);
     59     test(S("jtdaefblsokrmhpgcnqi"), 'i', 19, 18);
     60     test(S("hkbgspofltajcnedqmri"), 'i', 20, 18);
     61     test(S("oselktgbcapndfjihrmq"), 'i', 21, 19);
     62 
     63     test(S(""), 'i', S::npos);
     64     test(S("csope"), 'i', 4);
     65     test(S("gfsmthlkon"), 'i', 9);
     66     test(S("laenfsbridchgotmkqpj"), 'i', 19);
     67     }
     68 #if __cplusplus >= 201103L
     69     {
     70     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
     71     test(S(""), 'i', 0, S::npos);
     72     test(S(""), 'i', 1, S::npos);
     73     test(S("kitcj"), 'i', 0, 0);
     74     test(S("qkamf"), 'i', 1, 1);
     75     test(S("nhmko"), 'i', 2, 2);
     76     test(S("tpsaf"), 'i', 4, 4);
     77     test(S("lahfb"), 'i', 5, 4);
     78     test(S("irkhs"), 'i', 6, 4);
     79     test(S("gmfhdaipsr"), 'i', 0, 0);
     80     test(S("kantesmpgj"), 'i', 1, 1);
     81     test(S("odaftiegpm"), 'i', 5, 4);
     82     test(S("oknlrstdpi"), 'i', 9, 8);
     83     test(S("eolhfgpjqk"), 'i', 10, 9);
     84     test(S("pcdrofikas"), 'i', 11, 9);
     85     test(S("nbatdlmekrgcfqsophij"), 'i', 0, 0);
     86     test(S("bnrpehidofmqtcksjgla"), 'i', 1, 1);
     87     test(S("jdmciepkaqgotsrfnhlb"), 'i', 10, 10);
     88     test(S("jtdaefblsokrmhpgcnqi"), 'i', 19, 18);
     89     test(S("hkbgspofltajcnedqmri"), 'i', 20, 18);
     90     test(S("oselktgbcapndfjihrmq"), 'i', 21, 19);
     91 
     92     test(S(""), 'i', S::npos);
     93     test(S("csope"), 'i', 4);
     94     test(S("gfsmthlkon"), 'i', 9);
     95     test(S("laenfsbridchgotmkqpj"), 'i', 19);
     96     }
     97 #endif
     98 }
     99