• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1[section boost/python/str.hpp]
2[section Introduction]
3Exposes a [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] for the Python [@http://www.python.org/dev/doc/devel/lib/string-methods.html `str`] type.
4[endsect]
5[section Class `str`]
6Exposes the [@http://www.python.org/dev/doc/devel/lib/string-methods.html string methods] of Python's built-in `str` type. The semantics of the constructors and member functions defined below, except for the two-argument constructors which construct str objects from a range of characters, can be fully understood by reading the [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] concept definition. Since str is publicly derived from [link object_wrappers.boost_python_object_hpp.class_object `object`], the public `object` interface applies to `str` instances as well.
7``
8namespace boost { namespace python
9{
10  class str : public object
11  {
12   public:
13      str(); // new str
14
15      str(char const* s); // new str
16
17      str(char const* start, char const* finish); // new str
18      str(char const* start, std::size_t length); // new str
19
20      template <class T>
21      explicit str(T const& other);
22
23      str capitalize() const;
24
25      template <class T>
26      str center(T const& width) const;
27
28      template<class T>
29      long count(T const& sub) const;
30      template<class T1, class T2>
31      long count(T1 const& sub,T2 const& start) const;
32      template<class T1, class T2, class T3>
33      long count(T1 const& sub,T2 const& start, T3 const& end) const;
34
35      object decode() const;
36      template<class T>
37      object decode(T const& encoding) const;
38      template<class T1, class T2>
39      object decode(T1 const& encoding, T2 const& errors) const;
40
41      object encode() const;
42      template <class T>
43      object encode(T const& encoding) const;
44      template <class T1, class T2>
45      object encode(T1 const& encoding, T2 const& errors) const;
46
47      template <class T>
48      bool endswith(T const& suffix) const;
49      template <class T1, class T2>
50      bool endswith(T1 const& suffix, T2 const& start) const;
51      template <class T1, class T2, class T3>
52      bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const;
53
54      str expandtabs() const;
55      template <class T>
56      str expandtabs(T const& tabsize) const;
57
58      template <class T>
59      long find(T const& sub) const;
60      template <class T1, class T2>
61      long find(T1 const& sub, T2 const& start) const;
62      template <class T1, class T2, class T3>
63      long find(T1 const& sub, T2 const& start, T3 const& end) const;
64
65      template <class T>
66      long index(T const& sub) const;
67      template <class T1, class T2>
68      long index(T1 const& sub, T2 const& start) const;
69      template <class T1, class T2, class T3>
70      long index(T1 const& sub, T2 const& start, T3 const& end) const;
71
72      bool isalnum() const;
73      bool isalpha() const;
74      bool isdigit() const;
75      bool islower() const;
76      bool isspace() const;
77      bool istitle() const;
78      bool isupper() const;
79
80      template <class T>
81      str join(T const& sequence) const;
82
83      template <class T>
84      str ljust(T const& width) const;
85
86      str lower() const;
87      str lstrip() const;
88
89      template <class T1, class T2>
90      str replace(T1 const& old, T2 const& new_) const;
91      template <class T1, class T2, class T3>
92      str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const;
93
94      template <class T>
95      long rfind(T const& sub) const;
96      template <class T1, class T2>
97      long rfind(T1 const& sub, T2 const& start) const;
98      template <class T1, class T2, class T3>
99      long rfind(T1 const& sub, T2 const& start, T3 const& end) const;
100
101      template <class T>
102      long rindex(T const& sub) const;
103      template <class T1, class T2>
104      long rindex(T1 const& sub, T2 const& start) const;
105      template <class T1, class T2, class T3>
106      long rindex(T1 const& sub, T2 const& start, T3 const& end) const;
107
108      template <class T>
109      str rjust(T const& width) const;
110
111      str rstrip() const;
112
113      list split() const;
114      template <class T>
115      list split(T const& sep) const;
116      template <class T1, class T2>
117      list split(T1 const& sep, T2 const& maxsplit) const;
118
119      list splitlines() const;
120      template <class T>
121      list splitlines(T const& keepends) const;
122
123      template <class T>
124      bool startswith(T const& prefix) const;
125      template <class T1, class T2>
126      bool startswidth(T1 const& prefix, T2 const& start) const;
127      template <class T1, class T2, class T3>
128      bool startswidth(T1 const& prefix, T2 const& start, T3 const& end) const;
129
130      str strip() const;
131      str swapcase() const;
132      str title() const;
133
134      template <class T>
135      str translate(T const& table) const;
136      template <class T1, class T2>
137      str translate(T1 const& table, T2 const& deletechars) const;
138
139      str upper() const;
140  };
141}}
142``
143[endsect]
144[section Example]
145``
146using namespace boost::python;
147str remove_angle_brackets(str x)
148{
149  return x.strip('<').strip('>');
150}
151``
152[endsect]
153[endsect]
154