]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/replace.cc
acinclude.m4 (GLIBCPP_CONFIGURE_TESTSUITE): New macro, calls...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / replace.cc
1 // 1999-06-10 bkoz
2
3 // Copyright (C) 1994, 1999 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 2, 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 COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 // 21.3.5.6 basic_string::replace
22
23 #include <string>
24 #include <stdexcept>
25 #include <testsuite_hooks.h>
26
27 bool test01(void)
28 {
29 bool test = true;
30 typedef std::string::size_type csize_type;
31 typedef std::string::const_reference cref;
32 typedef std::string::reference ref;
33 csize_type npos = std::string::npos;
34 csize_type csz01, csz02;
35
36 const char str_lit01[] = "ventura, california";
37 const std::string str01(str_lit01);
38 std::string str02("del mar, california");
39 std::string str03(" and ");
40 std::string str05;
41
42 // string& replace(size_type pos, size_type n, const string& string)
43 // string& replace(size_type pos1, size_type n1, const string& string,
44 // size_type pos2, size_type n2)
45 // string& replace(size_type pos, size_type n1, const char* s, size_type n2)
46 // string& replace(size_type pos, size_type n1, const char* s)
47 // string& replace(size_type pos, size_type n1, size_type n2, char c)
48 // string& replace(iterator it1, iterator it2, const string& str)
49 // string& replace(iterator it1, iterator it2, const chat* s, size_type n)
50 // string& replace(iterator it1, iterator it2, const chat* s)
51 // string& replace(iterator it1, iterator it2, size_type n, char c)
52 // template<typename InputIter>
53 // string& replace(iterator it1, iterator it2, InputIter j1, InputIter j2)
54
55 #if 1
56 // with mods, from tstring.cc, from jason merrill, et. al.
57 std::string X = "Hello";
58 std::string x = X;
59
60 char ch = x[0];
61 VERIFY( ch == 'H' );
62
63 std::string z = x.substr(2, 3);
64 VERIFY( z == "llo" );
65
66 x.replace(2, 2, "r");
67 VERIFY( x == "Hero" );
68
69 x = X;
70 x.replace(0, 1, "j");
71 VERIFY( x == "jello" );
72
73 int ar[] = { 'H', 'e', 'l', 'l', 'o' };
74 x.replace(std::find(x.begin(), x.end(), 'l'),
75 std::find(x.rbegin(), x.rend(), 'l').base(), ar,
76 ar + sizeof(ar) / sizeof(ar[0]));
77 VERIFY( x == "jeHelloo" );
78 #endif
79
80 #ifdef DEBUG_ASSERT
81 assert(test);
82 #endif
83 return test;
84 }
85
86 int main()
87 {
88 test01();
89 return 0;
90 }