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