Commit 9e55199c authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Moved an example from string.rst into the examples directory for testing.

parent 5c04c1a8
def process_byte_data(unsigned char[:] data, bint return_all):
# ... process the data
if return_all:
return bytes(data)
else:
# example for returning a slice
return bytes(data[5:35])
...@@ -228,15 +228,9 @@ when only a small slice is returned. Since memoryviews do not copy the ...@@ -228,15 +228,9 @@ when only a small slice is returned. Since memoryviews do not copy the
data, they would otherwise keep the entire original buffer alive. The data, they would otherwise keep the entire original buffer alive. The
general idea here is to be liberal with input by accepting any kind of general idea here is to be liberal with input by accepting any kind of
byte buffer, but strict with output by returning a simple, well adapted byte buffer, but strict with output by returning a simple, well adapted
object. This can simply be done as follows:: object. This can simply be done as follows:
def process_byte_data(unsigned char[:] data): .. literalinclude:: ../../examples/tutorial/string/return_memview.pyx
# ... process the data
if return_all:
return bytes(data)
else:
# example for returning a slice
return bytes(data[5:35])
If the byte input is actually encoded text, and the further processing If the byte input is actually encoded text, and the further processing
should happen at the Unicode level, then the right thing to do is to should happen at the Unicode level, then the right thing to do is to
......
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