File indexing completed on 2025-01-18 09:50:42
0001
0002
0003
0004
0005 #ifndef STR_20020703_HPP
0006 #define STR_20020703_HPP
0007
0008 # include <boost/python/detail/prefix.hpp>
0009
0010 #include <boost/python/object.hpp>
0011 #include <boost/python/list.hpp>
0012 #include <boost/python/converter/pytype_object_mgr_traits.hpp>
0013
0014
0015 #undef isspace
0016 #undef islower
0017 #undef isalpha
0018 #undef isdigit
0019 #undef isalnum
0020 #undef isupper
0021
0022 namespace boost { namespace python {
0023
0024 class str;
0025
0026 namespace detail
0027 {
0028 struct BOOST_PYTHON_DECL str_base : object
0029 {
0030 str capitalize() const;
0031
0032 str center(object_cref width) const;
0033
0034 long count(object_cref sub) const;
0035
0036 long count(object_cref sub, object_cref start) const;
0037
0038 long count(object_cref sub, object_cref start, object_cref end) const;
0039
0040 #if PY_VERSION_HEX < 0x03000000
0041 object decode() const;
0042 object decode(object_cref encoding) const;
0043
0044 object decode(object_cref encoding, object_cref errors) const;
0045 #endif
0046
0047 object encode() const;
0048 object encode(object_cref encoding) const;
0049 object encode(object_cref encoding, object_cref errors) const;
0050
0051 bool endswith(object_cref suffix) const;
0052
0053 bool endswith(object_cref suffix, object_cref start) const;
0054 bool endswith(object_cref suffix, object_cref start, object_cref end) const;
0055
0056 str expandtabs() const;
0057 str expandtabs(object_cref tabsize) const;
0058
0059 long find(object_cref sub) const;
0060 long find(object_cref sub, object_cref start) const;
0061
0062 long find(object_cref sub, object_cref start, object_cref end) const;
0063
0064 long index(object_cref sub) const;
0065
0066 long index(object_cref sub, object_cref start) const;
0067 long index(object_cref sub, object_cref start, object_cref end) const;
0068
0069 bool isalnum() const;
0070 bool isalpha() const;
0071 bool isdigit() const;
0072 bool islower() const;
0073 bool isspace() const;
0074 bool istitle() const;
0075 bool isupper() const;
0076
0077 str join(object_cref sequence) const;
0078
0079 str ljust(object_cref width) const;
0080 str lower() const;
0081 str lstrip() const;
0082
0083 str replace(object_cref old, object_cref new_) const;
0084 str replace(object_cref old, object_cref new_, object_cref maxsplit) const;
0085 long rfind(object_cref sub) const;
0086
0087 long rfind(object_cref sub, object_cref start) const;
0088
0089 long rfind(object_cref sub, object_cref start, object_cref end) const;
0090 long rindex(object_cref sub) const;
0091 long rindex(object_cref sub, object_cref start) const;
0092
0093
0094 long rindex(object_cref sub, object_cref start, object_cref end) const;
0095
0096 str rjust(object_cref width) const;
0097
0098 str rstrip() const;
0099
0100 list split() const;
0101 list split(object_cref sep) const;
0102
0103 list split(object_cref sep, object_cref maxsplit) const;
0104
0105
0106 list splitlines() const;
0107 list splitlines(object_cref keepends) const;
0108
0109 bool startswith(object_cref prefix) const;
0110
0111
0112 bool startswith(object_cref prefix, object_cref start) const;
0113 bool startswith(object_cref prefix, object_cref start, object_cref end) const;
0114
0115 str strip() const;
0116 str swapcase() const;
0117 str title() const;
0118
0119 str translate(object_cref table) const;
0120
0121 str translate(object_cref table, object_cref deletechars) const;
0122
0123
0124 str upper() const;
0125
0126 protected:
0127 str_base();
0128
0129 str_base(const char* s);
0130
0131 str_base(char const* start, char const* finish);
0132
0133 str_base(char const* start, std::size_t length);
0134
0135 explicit str_base(object_cref other);
0136
0137 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str_base, object)
0138 private:
0139 static new_reference call(object const&);
0140 };
0141 }
0142
0143
0144 class str : public detail::str_base
0145 {
0146 typedef detail::str_base base;
0147 public:
0148 str() {}
0149
0150 str(const char* s) : base(s) {}
0151
0152 str(char const* start, char const* finish)
0153 : base(start, finish)
0154 {}
0155
0156 str(char const* start, std::size_t length)
0157 : base(start, length)
0158 {}
0159
0160 template <class T>
0161 explicit str(T const& other)
0162 : base(object(other))
0163 {
0164 }
0165
0166 template <class T>
0167 str center(T const& width) const
0168 {
0169 return base::center(object(width));
0170 }
0171
0172 template<class T>
0173 long count(T const& sub) const
0174 {
0175 return base::count(object(sub));
0176 }
0177
0178 template<class T1, class T2>
0179 long count(T1 const& sub,T2 const& start) const
0180 {
0181 return base::count(object(sub), object(start));
0182 }
0183
0184 template<class T1, class T2, class T3>
0185 long count(T1 const& sub,T2 const& start, T3 const& end) const
0186 {
0187 return base::count(object(sub), object(start), object(end));
0188 }
0189
0190 #if PY_VERSION_HEX < 0x03000000
0191 object decode() const { return base::decode(); }
0192
0193 template<class T>
0194 object decode(T const& encoding) const
0195 {
0196 return base::decode(object(encoding));
0197 }
0198
0199 template<class T1, class T2>
0200 object decode(T1 const& encoding, T2 const& errors) const
0201 {
0202 return base::decode(object(encoding),object(errors));
0203 }
0204 #endif
0205
0206 object encode() const { return base::encode(); }
0207
0208 template <class T>
0209 object encode(T const& encoding) const
0210 {
0211 return base::encode(object(encoding));
0212 }
0213
0214 template <class T1, class T2>
0215 object encode(T1 const& encoding, T2 const& errors) const
0216 {
0217 return base::encode(object(encoding),object(errors));
0218 }
0219
0220 template <class T>
0221 bool endswith(T const& suffix) const
0222 {
0223 return base::endswith(object(suffix));
0224 }
0225
0226 template <class T1, class T2>
0227 bool endswith(T1 const& suffix, T2 const& start) const
0228 {
0229 return base::endswith(object(suffix), object(start));
0230 }
0231
0232 template <class T1, class T2, class T3>
0233 bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const
0234 {
0235 return base::endswith(object(suffix), object(start), object(end));
0236 }
0237
0238 str expandtabs() const { return base::expandtabs(); }
0239
0240 template <class T>
0241 str expandtabs(T const& tabsize) const
0242 {
0243 return base::expandtabs(object(tabsize));
0244 }
0245
0246 template <class T>
0247 long find(T const& sub) const
0248 {
0249 return base::find(object(sub));
0250 }
0251
0252 template <class T1, class T2>
0253 long find(T1 const& sub, T2 const& start) const
0254 {
0255 return base::find(object(sub), object(start));
0256 }
0257
0258 template <class T1, class T2, class T3>
0259 long find(T1 const& sub, T2 const& start, T3 const& end) const
0260 {
0261 return base::find(object(sub), object(start), object(end));
0262 }
0263
0264 template <class T>
0265 long index(T const& sub) const
0266 {
0267 return base::index(object(sub));
0268 }
0269
0270 template <class T1, class T2>
0271 long index(T1 const& sub, T2 const& start) const
0272 {
0273 return base::index(object(sub), object(start));
0274 }
0275
0276 template <class T1, class T2, class T3>
0277 long index(T1 const& sub, T2 const& start, T3 const& end) const
0278 {
0279 return base::index(object(sub), object(start), object(end));
0280 }
0281
0282 template <class T>
0283 str join(T const& sequence) const
0284 {
0285 return base::join(object(sequence));
0286 }
0287
0288 template <class T>
0289 str ljust(T const& width) const
0290 {
0291 return base::ljust(object(width));
0292 }
0293
0294 template <class T1, class T2>
0295 str replace(T1 const& old, T2 const& new_) const
0296 {
0297 return base::replace(object(old),object(new_));
0298 }
0299
0300 template <class T1, class T2, class T3>
0301 str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const
0302 {
0303 return base::replace(object(old),object(new_), object(maxsplit));
0304 }
0305
0306 template <class T>
0307 long rfind(T const& sub) const
0308 {
0309 return base::rfind(object(sub));
0310 }
0311
0312 template <class T1, class T2>
0313 long rfind(T1 const& sub, T2 const& start) const
0314 {
0315 return base::rfind(object(sub), object(start));
0316 }
0317
0318 template <class T1, class T2, class T3>
0319 long rfind(T1 const& sub, T2 const& start, T3 const& end) const
0320 {
0321 return base::rfind(object(sub), object(start), object(end));
0322 }
0323
0324 template <class T>
0325 long rindex(T const& sub) const
0326 {
0327 return base::rindex(object(sub));
0328 }
0329
0330 template <class T1, class T2>
0331 long rindex(T1 const& sub, T2 const& start) const
0332 {
0333 return base::rindex(object(sub), object(start));
0334 }
0335
0336 template <class T1, class T2, class T3>
0337 long rindex(T1 const& sub, T2 const& start, T3 const& end) const
0338 {
0339 return base::rindex(object(sub), object(start), object(end));
0340 }
0341
0342 template <class T>
0343 str rjust(T const& width) const
0344 {
0345 return base::rjust(object(width));
0346 }
0347
0348 list split() const { return base::split(); }
0349
0350 template <class T>
0351 list split(T const& sep) const
0352 {
0353 return base::split(object(sep));
0354 }
0355
0356 template <class T1, class T2>
0357 list split(T1 const& sep, T2 const& maxsplit) const
0358 {
0359 return base::split(object(sep), object(maxsplit));
0360 }
0361
0362 list splitlines() const { return base::splitlines(); }
0363
0364 template <class T>
0365 list splitlines(T const& keepends) const
0366 {
0367 return base::splitlines(object(keepends));
0368 }
0369
0370 template <class T>
0371 bool startswith(T const& prefix) const
0372 {
0373 return base::startswith(object(prefix));
0374 }
0375
0376 template <class T1, class T2>
0377 bool startswith(T1 const& prefix, T2 const& start) const
0378 {
0379 return base::startswith(object(prefix), object(start));
0380 }
0381
0382 template <class T1, class T2, class T3>
0383 bool startswith(T1 const& prefix, T2 const& start, T3 const& end) const
0384 {
0385 return base::startswith(object(prefix), object(start), object(end));
0386 }
0387
0388 template <class T>
0389 str translate(T const& table) const
0390 {
0391 return base::translate(object(table));
0392 }
0393
0394 template <class T1, class T2>
0395 str translate(T1 const& table, T2 const& deletechars) const
0396 {
0397 return base::translate(object(table), object(deletechars));
0398 }
0399
0400 public:
0401 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str, base)
0402 };
0403
0404
0405
0406
0407 namespace converter
0408 {
0409 template <>
0410 struct object_manager_traits<str>
0411 #if PY_VERSION_HEX >= 0x03000000
0412 : pytype_object_manager_traits<&PyUnicode_Type,str>
0413 #else
0414 : pytype_object_manager_traits<&PyString_Type,str>
0415 #endif
0416 {
0417 };
0418 }
0419
0420 }}
0421
0422 #endif