Skip to content

Commit e78b493

Browse files
committed
Added new str constructors which take a range of characters, allowing
strings containing nul ('\0') characters. [SVN r20006]
1 parent 621b5fc commit e78b493

4 files changed

Lines changed: 53 additions & 5 deletions

File tree

doc/news.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ <h2 align="center">News/Change Log</h2>
2929
<hr>
3030

3131
<dl class="page-index">
32+
<dt>9 Sept 2003</dt>
33+
34+
<dd>Added new <code><a
35+
href="v2/str.html#str-spec">str</a></code></dd> constructors
36+
which take a range of characters, allowing strings containing
37+
nul (<code>'\0'</code>) characters.
38+
39+
<dt>8 Sept 2003</dt>
40+
41+
<dd>Added the ability to create methods from function
42+
objects (with an <code>operator()</code>); see the <a
43+
href="v2/make_function.html#make_function-spec">make_function</a>
44+
docs for more info.</dd>
45+
3246
<dt>10 August 2003</dt>
3347

3448
<dd>Added the new <code>properties</code> unit tests contributed by <a

doc/v2/str.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ <h3><a name="str-spec"></a>Class <code>str</code></h3>
6767
<p>Exposes the <a href=
6868
"http://www.python.org/dev/doc/devel/lib/string-methods.html">string
6969
methods</a> of Python's built-in <code>str</code> type. The
70-
semantics of the constructors and member functions defined below
71-
can be fully understood by reading the <a href=
70+
semantics of the constructors and member functions defined below,
71+
except for the two-argument constructors which construct str
72+
objects from a range of characters, can be fully understood by
73+
reading the <a href=
7274
"ObjectWrapper.html#TypeWrapper-concept">TypeWrapper</a> concept
7375
definition. Since <code>str</code> is publicly derived from
7476
<code><a href="object.html#object-spec">object</a></code>, the
@@ -85,7 +87,10 @@ <h4><a name="str-spec-synopsis"></a>Class <code>str</code>
8587
public:
8688
str(); // new str
8789

88-
str(const char* s); // new str
90+
str(char const* s); // new str
91+
92+
str(char const* start, char const* finish); // new str
93+
str(char const* start, std::size_t length); // new str
8994

9095
template &lt;class T&gt;
9196
explicit str(T const&amp; other);

include/boost/python/str.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ namespace detail
126126
str_base(); // new str
127127

128128
str_base(const char* s); // new str
129+
130+
str_base(char const* start, char const* finish);
131+
132+
str_base(char const* start, std::size_t length);
133+
129134
explicit str_base(object_cref other);
130135

131136
BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(str_base, object)
@@ -143,6 +148,14 @@ class str : public detail::str_base
143148

144149
str(const char* s) : base(s) {} // new str
145150

151+
str(char const* start, char const* finish) // new str
152+
: base(start, finish)
153+
{}
154+
155+
str(char const* start, std::size_t length) // new str
156+
: base(start, length)
157+
{}
158+
146159
template <class T>
147160
explicit str(T const& other)
148161
: base(object(other))

src/str.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,27 @@ detail::new_reference str_base::call(object const& arg_)
1111
}
1212

1313
str_base::str_base()
14-
: object(detail::new_reference(PyString_FromString("")))
14+
: object(detail::new_reference(::PyString_FromString("")))
1515
{}
1616

1717
str_base::str_base(const char* s)
18-
: object(detail::new_reference(PyString_FromString(s)))
18+
: object(detail::new_reference(::PyString_FromString(s)))
19+
{}
20+
21+
str_base::str_base(char const* start, char const* finish)
22+
: object(
23+
detail::new_reference(
24+
::PyString_FromStringAndSize(start, finish - start)
25+
)
26+
)
27+
{}
28+
29+
str_base::str_base(char const* start, std::size_t length) // new str
30+
: object(
31+
detail::new_reference(
32+
::PyString_FromStringAndSize(start, length)
33+
)
34+
)
1935
{}
2036

2137
str_base::str_base(object_cref other)

0 commit comments

Comments
 (0)