Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
d385e3f3
Commit
d385e3f3
authored
Jun 22, 2018
by
scoder
Committed by
GitHub
Jun 22, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2378 from gabrieldemarmiesse/test_string_4
Adding tests for "Unicode and passing strings" part 4
parents
04780910
d17d4e96
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
docs/examples/tutorial/string/return_memview.pyx
docs/examples/tutorial/string/return_memview.pyx
+9
-0
docs/src/tutorial/strings.rst
docs/src/tutorial/strings.rst
+3
-9
No files found.
docs/examples/tutorial/string/return_memview.pyx
0 → 100644
View file @
d385e3f3
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
])
docs/src/tutorial/strings.rst
View file @
d385e3f3
...
...
@@ -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
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
object. This can simply be done as follows::
def process_byte_data(unsigned char[:] data):
# ... process the data
if return_all:
return bytes(data)
else:
# example for returning a slice
return bytes(data[5:35])
object. This can simply be done as follows:
.. literalinclude:: ../../examples/tutorial/string/return_memview.pyx
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment