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 rfind(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.rfind(c, pos) == x);
25    if (x != S::npos)
26        assert(x <= pos && x + 1 <= 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.rfind(c) == x);
34    if (x != S::npos)
35        assert(x + 1 <= s.size());
36}
37
38int main()
39{
40    {
41    typedef std::string S;
42    test(S(""), 'b', 0, S::npos);
43    test(S(""), 'b', 1, S::npos);
44    test(S("abcde"), 'b', 0, S::npos);
45    test(S("abcde"), 'b', 1, 1);
46    test(S("abcde"), 'b', 2, 1);
47    test(S("abcde"), 'b', 4, 1);
48    test(S("abcde"), 'b', 5, 1);
49    test(S("abcde"), 'b', 6, 1);
50    test(S("abcdeabcde"), 'b', 0, S::npos);
51    test(S("abcdeabcde"), 'b', 1, 1);
52    test(S("abcdeabcde"), 'b', 5, 1);
53    test(S("abcdeabcde"), 'b', 9, 6);
54    test(S("abcdeabcde"), 'b', 10, 6);
55    test(S("abcdeabcde"), 'b', 11, 6);
56    test(S("abcdeabcdeabcdeabcde"), 'b', 0, S::npos);
57    test(S("abcdeabcdeabcdeabcde"), 'b', 1, 1);
58    test(S("abcdeabcdeabcdeabcde"), 'b', 10, 6);
59    test(S("abcdeabcdeabcdeabcde"), 'b', 19, 16);
60    test(S("abcdeabcdeabcdeabcde"), 'b', 20, 16);
61    test(S("abcdeabcdeabcdeabcde"), 'b', 21, 16);
62
63    test(S(""), 'b', S::npos);
64    test(S("abcde"), 'b', 1);
65    test(S("abcdeabcde"), 'b', 6);
66    test(S("abcdeabcdeabcdeabcde"), 'b', 16);
67    }
68#if __cplusplus >= 201103L
69    {
70    typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
71    test(S(""), 'b', 0, S::npos);
72    test(S(""), 'b', 1, S::npos);
73    test(S("abcde"), 'b', 0, S::npos);
74    test(S("abcde"), 'b', 1, 1);
75    test(S("abcde"), 'b', 2, 1);
76    test(S("abcde"), 'b', 4, 1);
77    test(S("abcde"), 'b', 5, 1);
78    test(S("abcde"), 'b', 6, 1);
79    test(S("abcdeabcde"), 'b', 0, S::npos);
80    test(S("abcdeabcde"), 'b', 1, 1);
81    test(S("abcdeabcde"), 'b', 5, 1);
82    test(S("abcdeabcde"), 'b', 9, 6);
83    test(S("abcdeabcde"), 'b', 10, 6);
84    test(S("abcdeabcde"), 'b', 11, 6);
85    test(S("abcdeabcdeabcdeabcde"), 'b', 0, S::npos);
86    test(S("abcdeabcdeabcdeabcde"), 'b', 1, 1);
87    test(S("abcdeabcdeabcdeabcde"), 'b', 10, 6);
88    test(S("abcdeabcdeabcdeabcde"), 'b', 19, 16);
89    test(S("abcdeabcdeabcdeabcde"), 'b', 20, 16);
90    test(S("abcdeabcdeabcdeabcde"), 'b', 21, 16);
91
92    test(S(""), 'b', S::npos);
93    test(S("abcde"), 'b', 1);
94    test(S("abcdeabcde"), 'b', 6);
95    test(S("abcdeabcdeabcdeabcde"), 'b', 16);
96    }
97#endif
98}
99