| 1 | // { dg-do run { target c++17 } } |
| 2 | |
| 3 | // Copyright (C) 2016-2025 Free Software Foundation, Inc. |
| 4 | // |
| 5 | // This file is part of the GNU ISO C++ Library. This library is free |
| 6 | // software; you can redistribute it and/or modify it under the |
| 7 | // terms of the GNU General Public License as published by the |
| 8 | // Free Software Foundation; either version 3, or (at your option) |
| 9 | // any later version. |
| 10 | |
| 11 | // This library is distributed in the hope that it will be useful, |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | // GNU General Public License for more details. |
| 15 | |
| 16 | // You should have received a copy of the GNU General Public License along |
| 17 | // with this library; see the file COPYING3. If not see |
| 18 | // <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | // [string::find] |
| 21 | // [string::rfind] |
| 22 | // [string::find.first.of] |
| 23 | // [string::find.last.of] |
| 24 | // [string::find.first.not.of] |
| 25 | // [string::find.last.not.of] |
| 26 | |
| 27 | #include <testsuite_string.h> |
| 28 | #include <testsuite_hooks.h> |
| 29 | |
| 30 | void |
| 31 | test03() |
| 32 | { |
| 33 | std::string_view str1("bar"); |
| 34 | __gnu_test::string str2("foobar"); |
| 35 | |
| 36 | auto x = str2.find(str1); |
| 37 | VERIFY (x == 3); |
| 38 | |
| 39 | x = str2.find(str1, 1); |
| 40 | VERIFY (x == 3); |
| 41 | |
| 42 | str2 = "barbar"; |
| 43 | x = str2.rfind(str1); |
| 44 | VERIFY (x == 3); |
| 45 | |
| 46 | x = str2.rfind(str1, 0); |
| 47 | VERIFY (x == 0); |
| 48 | |
| 49 | x = str2.rfind(str1, 3); |
| 50 | VERIFY (x == 3); |
| 51 | |
| 52 | str2 = "foobarxyz"; |
| 53 | str1 = "zyx"; |
| 54 | x = str2.find_first_of(str1); |
| 55 | VERIFY (x == 6); |
| 56 | |
| 57 | str2 = "foobarxyzfooxyz"; |
| 58 | x = str2.find_first_of(str1); |
| 59 | VERIFY (x == 6); |
| 60 | x = str2.find_first_of(str1, 9); |
| 61 | VERIFY (x == 12); |
| 62 | x = str2.find_last_of(str1); |
| 63 | VERIFY (x == 14); |
| 64 | x = str2.find_last_of(str1, 10); |
| 65 | VERIFY (x == 8); |
| 66 | |
| 67 | str2 = "abcabcabcxxx"; |
| 68 | str1 = "cba"; |
| 69 | x = str2.find_first_not_of(str1); |
| 70 | VERIFY (x == 9); |
| 71 | |
| 72 | str2 = "abcabcabcxxxabcabcxxx"; |
| 73 | x = str2.find_first_not_of(str1, 12); |
| 74 | VERIFY (x == 18); |
| 75 | |
| 76 | str1 = "x"; |
| 77 | x = str2.find_last_not_of(str1); |
| 78 | VERIFY (x == 17); |
| 79 | x = str2.find_last_not_of(str1, 11); |
| 80 | VERIFY (x == 8); |
| 81 | } |
| 82 | |
| 83 | int main() |
| 84 | { |
| 85 | test03(); |
| 86 | return 0; |
| 87 | } |