sl@0: // Copyright David Abrahams 2002. sl@0: // Distributed under the Boost Software License, Version 1.0. (See sl@0: // accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: #ifndef STR_20020703_HPP sl@0: #define STR_20020703_HPP sl@0: sl@0: # include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: // disable defines in provided by some system libraries sl@0: #undef isspace sl@0: #undef islower sl@0: #undef isalpha sl@0: #undef isdigit sl@0: #undef isalnum sl@0: #undef isupper sl@0: sl@0: namespace boost { namespace python { sl@0: sl@0: class str; sl@0: sl@0: namespace detail sl@0: { sl@0: struct BOOST_PYTHON_DECL str_base : object sl@0: { sl@0: str capitalize() const; sl@0: sl@0: str center(object_cref width) const; sl@0: sl@0: long count(object_cref sub) const; sl@0: sl@0: long count(object_cref sub, object_cref start) const; sl@0: sl@0: long count(object_cref sub, object_cref start, object_cref end) const; sl@0: sl@0: object decode() const; sl@0: object decode(object_cref encoding) const; sl@0: sl@0: object decode(object_cref encoding, object_cref errors) const; sl@0: sl@0: object encode() const; sl@0: object encode(object_cref encoding) const; sl@0: object encode(object_cref encoding, object_cref errors) const; sl@0: sl@0: bool endswith(object_cref suffix) const; sl@0: sl@0: bool endswith(object_cref suffix, object_cref start) const; sl@0: bool endswith(object_cref suffix, object_cref start, object_cref end) const; sl@0: sl@0: str expandtabs() const; sl@0: str expandtabs(object_cref tabsize) const; sl@0: sl@0: long find(object_cref sub) const; sl@0: long find(object_cref sub, object_cref start) const; sl@0: sl@0: long find(object_cref sub, object_cref start, object_cref end) const; sl@0: sl@0: long index(object_cref sub) const; sl@0: sl@0: long index(object_cref sub, object_cref start) const; sl@0: long index(object_cref sub, object_cref start, object_cref end) const; sl@0: sl@0: bool isalnum() const; sl@0: bool isalpha() const; sl@0: bool isdigit() const; sl@0: bool islower() const; sl@0: bool isspace() const; sl@0: bool istitle() const; sl@0: bool isupper() const; sl@0: sl@0: str join(object_cref sequence) const; sl@0: sl@0: str ljust(object_cref width) const; sl@0: str lower() const; sl@0: str lstrip() const; sl@0: sl@0: str replace(object_cref old, object_cref new_) const; sl@0: str replace(object_cref old, object_cref new_, object_cref maxsplit) const; sl@0: long rfind(object_cref sub) const; sl@0: sl@0: long rfind(object_cref sub, object_cref start) const; sl@0: sl@0: long rfind(object_cref sub, object_cref start, object_cref end) const; sl@0: long rindex(object_cref sub) const; sl@0: long rindex(object_cref sub, object_cref start) const; sl@0: sl@0: sl@0: long rindex(object_cref sub, object_cref start, object_cref end) const; sl@0: sl@0: str rjust(object_cref width) const; sl@0: sl@0: str rstrip() const; sl@0: sl@0: list split() const; sl@0: list split(object_cref sep) const; sl@0: sl@0: list split(object_cref sep, object_cref maxsplit) const; sl@0: sl@0: sl@0: list splitlines() const; sl@0: list splitlines(object_cref keepends) const; sl@0: sl@0: bool startswith(object_cref prefix) const; sl@0: sl@0: sl@0: bool startswith(object_cref prefix, object_cref start) const; sl@0: bool startswith(object_cref prefix, object_cref start, object_cref end) const; sl@0: sl@0: str strip() const; sl@0: str swapcase() const; sl@0: str title() const; sl@0: sl@0: str translate(object_cref table) const; sl@0: sl@0: str translate(object_cref table, object_cref deletechars) const; sl@0: sl@0: sl@0: str upper() const; sl@0: sl@0: protected: sl@0: str_base(); // new str sl@0: sl@0: str_base(const char* s); // new str sl@0: sl@0: str_base(char const* start, char const* finish); sl@0: sl@0: str_base(char const* start, std::size_t length); sl@0: sl@0: explicit str_base(object_cref other); sl@0: sl@0: BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str_base, object) sl@0: private: sl@0: static new_reference call(object const&); sl@0: }; sl@0: } sl@0: sl@0: sl@0: class str : public detail::str_base sl@0: { sl@0: typedef detail::str_base base; sl@0: public: sl@0: str() {} // new str sl@0: sl@0: str(const char* s) : base(s) {} // new str sl@0: sl@0: str(char const* start, char const* finish) // new str sl@0: : base(start, finish) sl@0: {} sl@0: sl@0: str(char const* start, std::size_t length) // new str sl@0: : base(start, length) sl@0: {} sl@0: sl@0: template sl@0: explicit str(T const& other) sl@0: : base(object(other)) sl@0: { sl@0: } sl@0: sl@0: template sl@0: str center(T const& width) const sl@0: { sl@0: return base::center(object(width)); sl@0: } sl@0: sl@0: template sl@0: long count(T const& sub) const sl@0: { sl@0: return base::count(object(sub)); sl@0: } sl@0: sl@0: template sl@0: long count(T1 const& sub,T2 const& start) const sl@0: { sl@0: return base::count(object(sub), object(start)); sl@0: } sl@0: sl@0: template sl@0: long count(T1 const& sub,T2 const& start, T3 const& end) const sl@0: { sl@0: return base::count(object(sub), object(start)); sl@0: } sl@0: sl@0: object decode() const { return base::decode(); } sl@0: sl@0: template sl@0: object decode(T const& encoding) const sl@0: { sl@0: return base::decode(object(encoding)); sl@0: } sl@0: sl@0: template sl@0: object decode(T1 const& encoding, T2 const& errors) const sl@0: { sl@0: return base::decode(object(encoding),object(errors)); sl@0: } sl@0: sl@0: object encode() const { return base::encode(); } sl@0: sl@0: template sl@0: object encode(T const& encoding) const sl@0: { sl@0: return base::encode(object(encoding)); sl@0: } sl@0: sl@0: template sl@0: object encode(T1 const& encoding, T2 const& errors) const sl@0: { sl@0: return base::encode(object(encoding),object(errors)); sl@0: } sl@0: sl@0: template sl@0: bool endswith(T const& suffix) const sl@0: { sl@0: return base::endswith(object(suffix)); sl@0: } sl@0: sl@0: template sl@0: bool endswith(T1 const& suffix, T2 const& start) const sl@0: { sl@0: return base::endswith(object(suffix), object(start)); sl@0: } sl@0: sl@0: template sl@0: bool endswith(T1 const& suffix, T2 const& start, T3 const& end) const sl@0: { sl@0: return base::endswith(object(suffix), object(start), object(end)); sl@0: } sl@0: sl@0: str expandtabs() const { return base::expandtabs(); } sl@0: sl@0: template sl@0: str expandtabs(T const& tabsize) const sl@0: { sl@0: return base::expandtabs(object(tabsize)); sl@0: } sl@0: sl@0: template sl@0: long find(T const& sub) const sl@0: { sl@0: return base::find(object(sub)); sl@0: } sl@0: sl@0: template sl@0: long find(T1 const& sub, T2 const& start) const sl@0: { sl@0: return base::find(object(sub), object(start)); sl@0: } sl@0: sl@0: template sl@0: long find(T1 const& sub, T2 const& start, T3 const& end) const sl@0: { sl@0: return base::find(object(sub), object(start), object(end)); sl@0: } sl@0: sl@0: template sl@0: long index(T const& sub) const sl@0: { sl@0: return base::index(object(sub)); sl@0: } sl@0: sl@0: template sl@0: long index(T1 const& sub, T2 const& start) const sl@0: { sl@0: return base::index(object(sub), object(start)); sl@0: } sl@0: sl@0: template sl@0: long index(T1 const& sub, T2 const& start, T3 const& end) const sl@0: { sl@0: return base::index(object(sub), object(start), object(end)); sl@0: } sl@0: sl@0: template sl@0: str join(T const& sequence) const sl@0: { sl@0: return base::join(object(sequence)); sl@0: } sl@0: sl@0: template sl@0: str ljust(T const& width) const sl@0: { sl@0: return base::ljust(object(width)); sl@0: } sl@0: sl@0: template sl@0: str replace(T1 const& old, T2 const& new_) const sl@0: { sl@0: return base::replace(object(old),object(new_)); sl@0: } sl@0: sl@0: template sl@0: str replace(T1 const& old, T2 const& new_, T3 const& maxsplit) const sl@0: { sl@0: return base::replace(object(old),object(new_), object(maxsplit)); sl@0: } sl@0: sl@0: template sl@0: long rfind(T const& sub) const sl@0: { sl@0: return base::rfind(object(sub)); sl@0: } sl@0: sl@0: template sl@0: long rfind(T1 const& sub, T2 const& start) const sl@0: { sl@0: return base::rfind(object(sub), object(start)); sl@0: } sl@0: sl@0: template sl@0: long rfind(T1 const& sub, T2 const& start, T3 const& end) const sl@0: { sl@0: return base::rfind(object(sub), object(start), object(end)); sl@0: } sl@0: sl@0: template sl@0: long rindex(T const& sub) const sl@0: { sl@0: return base::rindex(object(sub)); sl@0: } sl@0: sl@0: template sl@0: long rindex(T1 const& sub, T2 const& start) const sl@0: { sl@0: return base::rindex(object(sub), object(start)); sl@0: } sl@0: sl@0: template sl@0: long rindex(T1 const& sub, T2 const& start, T3 const& end) const sl@0: { sl@0: return base::rindex(object(sub), object(start), object(end)); sl@0: } sl@0: sl@0: template sl@0: str rjust(T const& width) const sl@0: { sl@0: return base::rjust(object(width)); sl@0: } sl@0: sl@0: list split() const { return base::split(); } sl@0: sl@0: template sl@0: list split(T const& sep) const sl@0: { sl@0: return base::split(object(sep)); sl@0: } sl@0: sl@0: template sl@0: list split(T1 const& sep, T2 const& maxsplit) const sl@0: { sl@0: return base::split(object(sep), object(maxsplit)); sl@0: } sl@0: sl@0: list splitlines() const { return base::splitlines(); } sl@0: sl@0: template sl@0: list splitlines(T const& keepends) const sl@0: { sl@0: return base::splitlines(object(keepends)); sl@0: } sl@0: sl@0: template sl@0: bool startswith(T const& prefix) const sl@0: { sl@0: return base::startswith(object(prefix)); sl@0: } sl@0: sl@0: template sl@0: bool startswith(T1 const& prefix, T2 const& start) const sl@0: { sl@0: return base::startswith(object(prefix), object(start)); sl@0: } sl@0: sl@0: template sl@0: bool startswith(T1 const& prefix, T2 const& start, T3 const& end) const sl@0: { sl@0: return base::startswith(object(prefix), object(start), object(end)); sl@0: } sl@0: sl@0: template sl@0: str translate(T const& table) const sl@0: { sl@0: return base::translate(object(table)); sl@0: } sl@0: sl@0: template sl@0: str translate(T1 const& table, T2 const& deletechars) const sl@0: { sl@0: return base::translate(object(table), object(deletechars)); sl@0: } sl@0: sl@0: public: // implementation detail -- for internal use only sl@0: BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str, base) sl@0: }; sl@0: sl@0: // sl@0: // Converter Specializations sl@0: // sl@0: namespace converter sl@0: { sl@0: template <> sl@0: struct object_manager_traits sl@0: : pytype_object_manager_traits<&PyString_Type,str> sl@0: { sl@0: }; sl@0: } sl@0: sl@0: }} // namespace boost::python sl@0: sl@0: #endif // STR_20020703_HPP