| 1 |
// 1999-06-10 bkoz |
| 2 |
|
| 3 |
// Copyright (C) 1994-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 |
// 21.3.5.6 basic_string::replace |
| 21 |
|
| 22 |
#include <string> |
| 23 |
#include <testsuite_hooks.h> |
| 24 |
|
| 25 |
// Some more miscellaneous tests |
| 26 |
void |
| 27 |
test03() |
| 28 |
{ |
| 29 |
const char* title01 = "nine types of ambiguity"; |
| 30 |
const char* title02 = "ultra"; |
| 31 |
std::string str01 = title01; |
| 32 |
std::string str02 = title02; |
| 33 |
|
| 34 |
str01.replace(0, 4, str02); |
| 35 |
VERIFY(str01 == "ultra types of ambiguity"); |
| 36 |
|
| 37 |
str01.replace(15, 9, str02, 2, 2); |
| 38 |
VERIFY(str01 == "ultra types of tr"); |
| 39 |
|
| 40 |
str01 = title01; |
| 41 |
str02.replace(0, 0, str01, 0, std::string::npos); |
| 42 |
VERIFY(str02 == "nine types of ambiguityultra"); |
| 43 |
|
| 44 |
str02.replace(11, 2, title02, 5); |
| 45 |
VERIFY(str02 == "nine types ultra ambiguityultra"); |
| 46 |
|
| 47 |
str02.replace(11, 5, title01, 2); |
| 48 |
VERIFY(str02 == "nine types ni ambiguityultra"); |
| 49 |
|
| 50 |
str01.replace(str01.size(), 0, title02); |
| 51 |
VERIFY(str01 == "nine types of ambiguityultra"); |
| 52 |
|
| 53 |
str01 = title01; |
| 54 |
str02 = title02; |
| 55 |
str01.replace(str01.begin(), str01.end(), str02); |
| 56 |
VERIFY(str01 == "ultra"); |
| 57 |
|
| 58 |
str01.replace(str01.begin(), str01.begin(), title01, 4); |
| 59 |
VERIFY(str01 == "nineultra"); |
| 60 |
|
| 61 |
str01.replace(str01.end(), str01.end(), title01 + 5, 5); |
| 62 |
VERIFY(str01 == "nineultratypes"); |
| 63 |
|
| 64 |
str01.replace(str01.begin(), str01.end(), title02); |
| 65 |
VERIFY(str01 == "ultra"); |
| 66 |
} |
| 67 |
|
| 68 |
int main() |
| 69 |
{ |
| 70 |
test03(); |
| 71 |
return 0; |
| 72 |
} |