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
22 namespace boost
{ namespace python
{
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;
75 str
join(object_cref sequence
) const;
77 str
ljust(object_cref width
) 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;
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;
114 str
swapcase() const;
117 str
translate(object_cref table
) const;
119 str
translate(object_cref table
, object_cref deletechars
) const;
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
)
137 static new_reference
call(object
const&);
142 class str
: public detail::str_base
144 typedef detail::str_base base
;
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
)
159 explicit str(T
const& other
)
160 : base(object(other
))
165 str
center(T
const& width
) const
167 return base::center(object(width
));
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(); }
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(); }
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
));
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(); }
237 str
expandtabs(T
const& tabsize
) const
239 return base::expandtabs(object(tabsize
));
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
));
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
));
279 str
join(T
const& sequence
) const
281 return base::join(object(sequence
));
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
));
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
));
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
));
339 str
rjust(T
const& width
) const
341 return base::rjust(object(width
));
344 list
split() const { return base::split(); }
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(); }
361 list
splitlines(T
const& keepends
) const
363 return base::splitlines(object(keepends
));
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
));
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
406 struct object_manager_traits
<str
>
407 : pytype_object_manager_traits
<&PyString_Type
,str
>
412 }} // namespace boost::python
414 #endif // STR_20020703_HPP