Commit d385e3f3 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2378 from gabrieldemarmiesse/test_string_4

Adding tests for "Unicode and passing strings" part 4
parents 04780910 d17d4e96
def process_byte_data(unsigned char[:] data):
# ... process the data, here, dummy processing.
cdef bint return_all = (data[0] == 108)
if return_all:
return bytes(data)
else:
# example for returning a slice
return bytes(data[5:7])
...@@ -216,15 +216,9 @@ when only a small slice is returned. Since memoryviews do not copy the ...@@ -216,15 +216,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