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