3 // Copyright (C) 1994, 1999, 2000, 2003 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21 // 21.3.6.1 basic_string find
24 #include <testsuite_hooks.h>
28 bool test
__attribute__((unused
)) = true;
29 typedef std::string::size_type csize_type
;
30 typedef std::string::const_reference cref
;
31 typedef std::string::reference ref
;
32 csize_type npos
= std::string::npos
;
33 csize_type csz01
, csz02
;
35 const char str_lit01
[] = "mave";
36 const std::string
str01("mavericks, santa cruz");
37 std::string
str02(str_lit01
);
38 std::string
str03("s, s");
41 // size_type find(const string&, size_type pos = 0) const;
42 csz01
= str01
.find(str01
);
44 csz01
= str01
.find(str01
, 4);
45 VERIFY( csz01
== npos
);
46 csz01
= str01
.find(str02
, 0);
48 csz01
= str01
.find(str02
, 3);
49 VERIFY( csz01
== npos
);
50 csz01
= str01
.find(str03
, 0);
52 csz01
= str01
.find(str03
, 3);
54 csz01
= str01
.find(str03
, 12);
55 VERIFY( csz01
== npos
);
57 // An empty string consists of no characters
58 // therefore it should be found at every point in a string,
59 // except beyond the end
60 csz01
= str01
.find(str04
, 0);
62 csz01
= str01
.find(str04
, 5);
64 csz01
= str01
.find(str04
, str01
.size());
65 VERIFY( csz01
== str01
.size() );
66 csz01
= str01
.find(str04
, str01
.size()+1);
67 VERIFY( csz01
== npos
);
69 // size_type find(const char* s, size_type pos, size_type n) const;
70 csz01
= str01
.find(str_lit01
, 0, 3);
72 csz01
= str01
.find(str_lit01
, 3, 0);
75 // size_type find(const char* s, size_type pos = 0) const;
76 csz01
= str01
.find(str_lit01
);
78 csz01
= str01
.find(str_lit01
, 3);
79 VERIFY( csz01
== npos
);
81 // size_type find(char c, size_type pos = 0) const;
82 csz01
= str01
.find('z');
83 csz02
= str01
.size() - 1;
84 VERIFY( csz01
== csz02
);
85 csz01
= str01
.find('/');
86 VERIFY( csz01
== npos
);