2333cc3dd8755f2efcd1b9326b3db4d42e1d137b
3 // Copyright (C) 1999 Free Software Foundation, Inc.
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)
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.
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,
21 // 21.3.5.3 basic_string::assign
25 #include <debug_assert.h>
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
;
36 const char str_lit01
[] = "point bolivar, texas";
37 const std::string
str01(str_lit01
);
38 const std::string
str02("corpus, ");
39 const std::string str03
;
43 // string& append(const string&)
46 VERIFY( str05
== "corpus, corpus, " );
48 VERIFY( str05
== "corpus, corpus, point bolivar, texas" );
50 VERIFY( str05
== "corpus, corpus, point bolivar, texas" );
53 VERIFY( str06
== str05
);
56 // string& append(const string&, size_type pos, size_type n)
61 str06
.append(str03
, csz01
+ 1, 0);
64 catch(std::out_of_range
& fail
) {
73 str06
.append(str01
, csz01
+ 1, 0);
76 catch(std::out_of_range
& fail
) {
84 str05
.append(str01
, 0, std::string::npos
);
85 VERIFY( str05
== "corpus, point bolivar, texas" );
86 VERIFY( str05
!= str02
);
89 str06
.append(str01
, 15, std::string::npos
);
90 VERIFY( str06
== "corpus, texas" );
91 VERIFY( str02
!= str06
);
94 // string& append(const char* s)
98 VERIFY( str05
== str03
);
100 str05
.append(str_lit01
);
101 VERIFY( str05
== str01
);
104 str06
.append("corpus, ");
105 VERIFY( str06
== "corpus, corpus, " );
108 // string& append(const char* s, size_type n)
112 VERIFY( str05
.size() == 0 );
113 VERIFY( str05
== str03
);
115 str05
.append(str_lit01
, sizeof(str_lit01
) - 1);
116 VERIFY( str05
== str01
);
119 str06
.append("corpus, ", 6);
120 VERIFY( str06
== "corpus, corpus" );
123 str06
.append("corpus, ", 12);
124 VERIFY( str06
!= "corpus, corpus, " );
127 // string& append(size_type n, char c)
130 str05
.append(0, 'a');
131 VERIFY( str05
== str03
);
132 str06
.append(8, '.');
133 VERIFY( str06
== "........" );
136 // template<typename InputIter>
137 // string& append(InputIter first, InputIter last)
140 str05
.append(str03
.begin(), str03
.end());
141 VERIFY( str05
== str03
);
144 str06
.append(str01
.begin(), str01
.begin() + str01
.find('r'));
145 VERIFY( str06
== "corpus, point boliva" );
146 VERIFY( str06
!= str01
);
147 VERIFY( str06
!= str02
);
150 str05
.append(str05
.begin(), str05
.begin() + str05
.find('r'));
151 VERIFY( str05
== "point bolivar, texaspoint boliva" );
152 VERIFY( str05
!= str01
);