1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // const size_type find_last_not_of(charT c, size_type pos = npos) const;
14 #include <string_view>
17 #include "test_macros.h"
18 #include "constexpr_char_traits.hpp"
22 test(const S& s, typename S::value_type c, typename S::size_type pos,
23 typename S::size_type x)
25 assert(s.find_last_not_of(c, pos) == x);
27 assert(x <= pos && x < s.size());
32 test(const S& s, typename S::value_type c, typename S::size_type x)
34 assert(s.find_last_not_of(c) == x);
42 typedef std::string_view S;
43 test(S(""), 'i', 0, S::npos);
44 test(S(""), 'i', 1, S::npos);
45 test(S("kitcj"), 'i', 0, 0);
46 test(S("qkamf"), 'i', 1, 1);
47 test(S("nhmko"), 'i', 2, 2);
48 test(S("tpsaf"), 'i', 4, 4);
49 test(S("lahfb"), 'i', 5, 4);
50 test(S("irkhs"), 'i', 6, 4);
51 test(S("gmfhdaipsr"), 'i', 0, 0);
52 test(S("kantesmpgj"), 'i', 1, 1);
53 test(S("odaftiegpm"), 'i', 5, 4);
54 test(S("oknlrstdpi"), 'i', 9, 8);
55 test(S("eolhfgpjqk"), 'i', 10, 9);
56 test(S("pcdrofikas"), 'i', 11, 9);
57 test(S("nbatdlmekrgcfqsophij"), 'i', 0, 0);
58 test(S("bnrpehidofmqtcksjgla"), 'i', 1, 1);
59 test(S("jdmciepkaqgotsrfnhlb"), 'i', 10, 10);
60 test(S("jtdaefblsokrmhpgcnqi"), 'i', 19, 18);
61 test(S("hkbgspofltajcnedqmri"), 'i', 20, 18);
62 test(S("oselktgbcapndfjihrmq"), 'i', 21, 19);
64 test(S(""), 'i', S::npos);
65 test(S("csope"), 'i', 4);
66 test(S("gfsmthlkon"), 'i', 9);
67 test(S("laenfsbridchgotmkqpj"), 'i', 19);
72 typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
74 constexpr SV sv2 { "abcde", 5 };
76 static_assert (sv1.find_last_not_of( 'i', 0 ) == SV::npos, "" );
77 static_assert (sv1.find_last_not_of( 'i', 1 ) == SV::npos, "" );
78 static_assert (sv2.find_last_not_of( 'a', 0 ) == SV::npos, "" );
79 static_assert (sv2.find_last_not_of( 'a', 1 ) == 1, "" );
80 static_assert (sv2.find_last_not_of( 'e', 5 ) == 3, "" );