Commit 159e5589 authored by Stefan Behnel's avatar Stefan Behnel

support iteration over std::string in C++

parent 2bac445c
...@@ -15,6 +15,40 @@ cdef extern from "<string>" namespace "std" nogil: ...@@ -15,6 +15,40 @@ cdef extern from "<string>" namespace "std" nogil:
# as a string formed by a repetition of character c, n times. # as a string formed by a repetition of character c, n times.
string(size_t, char) except + string(size_t, char) except +
cppclass iterator:
iterator()
char& operator*()
iterator(iterator &)
iterator operator++()
iterator operator--()
bint operator==(iterator)
bint operator!=(iterator)
cppclass reverse_iterator:
char& operator*()
iterator operator++()
iterator operator--()
iterator operator+(size_t)
iterator operator-(size_t)
bint operator==(reverse_iterator)
bint operator!=(reverse_iterator)
bint operator<(reverse_iterator)
bint operator>(reverse_iterator)
bint operator<=(reverse_iterator)
bint operator>=(reverse_iterator)
cppclass const_iterator(iterator):
pass
cppclass const_reverse_iterator(reverse_iterator):
pass
iterator begin()
const_iterator const_begin "begin"()
iterator end()
const_iterator const_end "end"()
reverse_iterator rbegin()
const_reverse_iterator const_rbegin "rbegin"()
reverse_iterator rend()
const_reverse_iterator const_rend "rend"()
const char* c_str() const char* c_str()
const char* data() const char* data()
size_t size() size_t size()
......
...@@ -300,3 +300,13 @@ def test_greater_than(char *a, char *b): ...@@ -300,3 +300,13 @@ def test_greater_than(char *a, char *b):
cdef string s = string(a) cdef string s = string(a)
cdef string t = string(b) cdef string t = string(b)
return (s > t, s > b, s >= b) return (s > t, s > b, s >= b)
def test_iteration(string s):
"""
>>> test_iteration(b'xyz')
[120, 121, 122]
>>> test_iteration(b'')
[]
"""
return [c for c in s]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment