From e78b4939b391c61c8e14901dd6aea686f49073ad Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 11 Sep 2003 02:57:24 +0000 Subject: [PATCH] Added new str constructors which take a range of characters, allowing strings containing nul ('\0') characters. [SVN r20006] --- doc/news.html | 14 ++++++++++++++ doc/v2/str.html | 11 ++++++++--- include/boost/python/str.hpp | 13 +++++++++++++ src/str.cpp | 20 ++++++++++++++++++-- 4 files changed, 53 insertions(+), 5 deletions(-) diff --git a/doc/news.html b/doc/news.html index a3344e34..3b38951a 100644 --- a/doc/news.html +++ b/doc/news.html @@ -29,6 +29,20 @@
+
9 Sept 2003
+ +
Added new str
constructors + which take a range of characters, allowing strings containing + nul ('\0') characters. + +
8 Sept 2003
+ +
Added the ability to create methods from function + objects (with an operator()); see the make_function + docs for more info.
+
10 August 2003
Added the new properties unit tests contributed by Exposes the string methods of Python's built-in str type. The - semantics of the constructors and member functions defined below - can be fully understood by reading the TypeWrapper concept definition. Since str is publicly derived from object, the @@ -85,7 +87,10 @@ namespace boost { namespace python public: str(); // new str - str(const char* s); // new str + str(char const* s); // new str + + str(char const* start, char const* finish); // new str + str(char const* start, std::size_t length); // new str template <class T> explicit str(T const& other); diff --git a/include/boost/python/str.hpp b/include/boost/python/str.hpp index 6fc20f9d..024712f1 100644 --- a/include/boost/python/str.hpp +++ b/include/boost/python/str.hpp @@ -126,6 +126,11 @@ namespace detail str_base(); // new str str_base(const char* s); // new str + + str_base(char const* start, char const* finish); + + str_base(char const* start, std::size_t length); + explicit str_base(object_cref other); BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str_base, object) @@ -143,6 +148,14 @@ class str : public detail::str_base str(const char* s) : base(s) {} // new str + str(char const* start, char const* finish) // new str + : base(start, finish) + {} + + str(char const* start, std::size_t length) // new str + : base(start, length) + {} + template explicit str(T const& other) : base(object(other)) diff --git a/src/str.cpp b/src/str.cpp index fc29aa03..c2d41a8e 100644 --- a/src/str.cpp +++ b/src/str.cpp @@ -11,11 +11,27 @@ detail::new_reference str_base::call(object const& arg_) } str_base::str_base() - : object(detail::new_reference(PyString_FromString(""))) + : object(detail::new_reference(::PyString_FromString(""))) {} str_base::str_base(const char* s) - : object(detail::new_reference(PyString_FromString(s))) + : object(detail::new_reference(::PyString_FromString(s))) +{} + +str_base::str_base(char const* start, char const* finish) + : object( + detail::new_reference( + ::PyString_FromStringAndSize(start, finish - start) + ) + ) +{} + +str_base::str_base(char const* start, std::size_t length) // new str + : object( + detail::new_reference( + ::PyString_FromStringAndSize(start, length) + ) + ) {} str_base::str_base(object_cref other)