2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 16:32:16 +00:00

Added new str constructors which take a range of characters, allowing

strings containing nul ('\0') characters.


[SVN r20006]
This commit is contained in:
Dave Abrahams
2003-09-11 02:57:24 +00:00
parent 621b5fc2db
commit e78b4939b3
4 changed files with 53 additions and 5 deletions

View File

@@ -29,6 +29,20 @@
<hr>
<dl class="page-index">
<dt>9 Sept 2003</dt>
<dd>Added new <code><a
href="v2/str.html#str-spec">str</a></code></dd> constructors
which take a range of characters, allowing strings containing
nul (<code>'\0'</code>) characters.
<dt>8 Sept 2003</dt>
<dd>Added the ability to create methods from function
objects (with an <code>operator()</code>); see the <a
href="v2/make_function.html#make_function-spec">make_function</a>
docs for more info.</dd>
<dt>10 August 2003</dt>
<dd>Added the new <code>properties</code> unit tests contributed by <a

View File

@@ -67,8 +67,10 @@
<p>Exposes the <a href=
"http://www.python.org/dev/doc/devel/lib/string-methods.html">string
methods</a> of Python's built-in <code>str</code> type. The
semantics of the constructors and member functions defined below
can be fully understood by reading the <a href=
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 <a href=
"ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> concept
definition. Since <code>str</code> is publicly derived from
<code><a href="object.html#object-spec">object</a></code>, 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 &lt;class T&gt;
explicit str(T const&amp; other);

View File

@@ -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 <class T>
explicit str(T const& other)
: base(object(other))

View File

@@ -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)