fix doc example typo
[boost.git] / boost / python / str.hpp
blob86bc3ba6e8f9a8c4eec32261fb29e294614f7351
1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef STR_20020703_HPP
6 #define STR_20020703_HPP
8 # include <boost/python/detail/prefix.hpp>
10 #include <boost/python/object.hpp>
11 #include <boost/python/list.hpp>
12 #include <boost/python/converter/pytype_object_mgr_traits.hpp>
14 // disable defines in <cctype> provided by some system libraries
15 #undef isspace
16 #undef islower
17 #undef isalpha
18 #undef isdigit
19 #undef isalnum
20 #undef isupper
22 namespace boost { namespace python {
24 class str;
26 namespace detail
28 struct BOOST_PYTHON_DECL str_base : object
30 str capitalize() const;
32 str center(object_cref width) const;
34 long count(object_cref sub) const;
36 long count(object_cref sub, object_cref start) const;
38 long count(object_cref sub, object_cref start, object_cref end) const;
40 object decode() const;
41 object decode(object_cref encoding) const;
43 object decode(object_cref encoding, object_cref errors) const;
45 object encode() const;
46 object encode(object_cref encoding) const;
47 object encode(object_cref encoding, object_cref errors) const;
49 bool endswith(object_cref suffix) const;
51 bool endswith(object_cref suffix, object_cref start) const;
52 bool endswith(object_cref suffix, object_cref start, object_cref end) const;
54 str expandtabs() const;
55 str expandtabs(object_cref tabsize) const;
57 long find(object_cref sub) const;
58 long find(object_cref sub, object_cref start) const;
60 long find(object_cref sub, object_cref start, object_cref end) const;
62 long index(object_cref sub) const;
64 long index(object_cref sub, object_cref start) const;
65 long index(object_cref sub, object_cref start, object_cref end) const;
67 bool isalnum() const;
68 bool isalpha() const;
69 bool isdigit() const;
70 bool islower() const;
71 bool isspace() const;
72 bool istitle() const;
73 bool isupper() const;
75 str join(object_cref sequence) const;
77 str ljust(object_cref width) const;
78 str lower() const;
79 str lstrip() const;
81 str replace(object_cref old, object_cref new_) const;
82 str replace(object_cref old, object_cref new_, object_cref maxsplit) const;
83 long rfind(object_cref sub) const;
85 long rfind(object_cref sub, object_cref start) const;
87 long rfind(object_cref sub, object_cref start, object_cref end) const;
88 long rindex(object_cref sub) const;
89 long rindex(object_cref sub, object_cref start) const;
92 long rindex(object_cref sub, object_cref start, object_cref end) const;
94 str rjust(object_cref width) const;
96 str rstrip() const;
98 list split() const;
99 list split(object_cref sep) const;
101 list split(object_cref sep, object_cref maxsplit) const;
104 list splitlines() const;
105 list splitlines(object_cref keepends) const;
107 bool startswith(object_cref prefix) const;
110 bool startswith(object_cref prefix, object_cref start) const;
111 bool startswith(object_cref prefix, object_cref start, object_cref end) const;
113 str strip() const;
114 str swapcase() const;
115 str title() const;
117 str translate(object_cref table) const;
119 str translate(object_cref table, object_cref deletechars) const;
122 str upper() const;
124 protected:
125 str_base(); // new str
127 str_base(const char* s); // new str
129 str_base(char const* start, char const* finish);
131 str_base(char const* start, std::size_t length);
133 explicit str_base(object_cref other);
135 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str_base, object)
136 private:
137 static new_reference call(object const&);
142 class str : public detail::str_base
144 typedef detail::str_base base;
145 public:
146 str() {} // new str
148 str(const char* s) : base(s) {} // new str
150 str(char const* start, char const* finish) // new str
151 : base(start, finish)
154 str(char const* start, std::size_t length) // new str
155 : base(start, length)
158 template <class T>
159 explicit str(T const& other)
160 : base(object(other))
164 template <class T>
165 str center(T const& width) const
167 return base::center(object(width));
170 template<class T>
171 long count(T const& sub) const
173 return base::count(object(sub));
176 template<class T1, class T2>
177 long count(T1 const& sub,T2 const& start) const
179 return base::count(object(sub), object(start));
182 template<class T1, class T2, class T3>
183 long count(T1 const& sub,T2 const& start, T3 const& end) const
185 return base::count(object(sub), object(start));
188 object decode() const { return base::decode(); }
190 template<class T>
191 object decode(T const& encoding) const
193 return base::decode(object(encoding));
196 template<class T1, class T2>
197 object decode(T1 const& encoding, T2 const& errors) const
199 return base::decode(object(encoding),object(errors));
202 object encode() const { return base::encode(); }
204 template <class T>
205 object encode(T const& encoding) const
207 return base::encode(object(encoding));
210 template <class T1, class T2>
211 object encode(T1 const& encoding, T2 const& errors) const
213 return base::encode(object(encoding),object(errors));
216 template <class T>
217 bool endswith(T const& suffix) const
219 return base::endswith(object(suffix));
222 template <class T1, class T2>
223 bool endswith(T1 const& suffix, T2 const& start) const
225 return base::endswith(object(suffix), object(start));
228 template <class T1, class T2, class T3>
229 bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const
231 return base::endswith(object(suffix), object(start), object(end));
234 str expandtabs() const { return base::expandtabs(); }
236 template <class T>
237 str expandtabs(T const& tabsize) const
239 return base::expandtabs(object(tabsize));
242 template <class T>
243 long find(T const& sub) const
245 return base::find(object(sub));
248 template <class T1, class T2>
249 long find(T1 const& sub, T2 const& start) const
251 return base::find(object(sub), object(start));
254 template <class T1, class T2, class T3>
255 long find(T1 const& sub, T2 const& start, T3 const& end) const
257 return base::find(object(sub), object(start), object(end));
260 template <class T>
261 long index(T const& sub) const
263 return base::index(object(sub));
266 template <class T1, class T2>
267 long index(T1 const& sub, T2 const& start) const
269 return base::index(object(sub), object(start));
272 template <class T1, class T2, class T3>
273 long index(T1 const& sub, T2 const& start, T3 const& end) const
275 return base::index(object(sub), object(start), object(end));
278 template <class T>
279 str join(T const& sequence) const
281 return base::join(object(sequence));
284 template <class T>
285 str ljust(T const& width) const
287 return base::ljust(object(width));
290 template <class T1, class T2>
291 str replace(T1 const& old, T2 const& new_) const
293 return base::replace(object(old),object(new_));
296 template <class T1, class T2, class T3>
297 str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const
299 return base::replace(object(old),object(new_), object(maxsplit));
302 template <class T>
303 long rfind(T const& sub) const
305 return base::rfind(object(sub));
308 template <class T1, class T2>
309 long rfind(T1 const& sub, T2 const& start) const
311 return base::rfind(object(sub), object(start));
314 template <class T1, class T2, class T3>
315 long rfind(T1 const& sub, T2 const& start, T3 const& end) const
317 return base::rfind(object(sub), object(start), object(end));
320 template <class T>
321 long rindex(T const& sub) const
323 return base::rindex(object(sub));
326 template <class T1, class T2>
327 long rindex(T1 const& sub, T2 const& start) const
329 return base::rindex(object(sub), object(start));
332 template <class T1, class T2, class T3>
333 long rindex(T1 const& sub, T2 const& start, T3 const& end) const
335 return base::rindex(object(sub), object(start), object(end));
338 template <class T>
339 str rjust(T const& width) const
341 return base::rjust(object(width));
344 list split() const { return base::split(); }
346 template <class T>
347 list split(T const& sep) const
349 return base::split(object(sep));
352 template <class T1, class T2>
353 list split(T1 const& sep, T2 const& maxsplit) const
355 return base::split(object(sep), object(maxsplit));
358 list splitlines() const { return base::splitlines(); }
360 template <class T>
361 list splitlines(T const& keepends) const
363 return base::splitlines(object(keepends));
366 template <class T>
367 bool startswith(T const& prefix) const
369 return base::startswith(object(prefix));
372 template <class T1, class T2>
373 bool startswith(T1 const& prefix, T2 const& start) const
375 return base::startswith(object(prefix), object(start));
378 template <class T1, class T2, class T3>
379 bool startswith(T1 const& prefix, T2 const& start, T3 const& end) const
381 return base::startswith(object(prefix), object(start), object(end));
384 template <class T>
385 str translate(T const& table) const
387 return base::translate(object(table));
390 template <class T1, class T2>
391 str translate(T1 const& table, T2 const& deletechars) const
393 return base::translate(object(table), object(deletechars));
396 public: // implementation detail -- for internal use only
397 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str, base)
401 // Converter Specializations
403 namespace converter
405 template <>
406 struct object_manager_traits<str>
407 : pytype_object_manager_traits<&PyString_Type,str>
412 }} // namespace boost::python
414 #endif // STR_20020703_HPP