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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
715d093b
Commit
715d093b
authored
Jun 21, 2018
by
gabrieldemarmiesse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put an example of a decoding to utf-8 to the examples directory for testing.
parent
04780910
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
16 deletions
+17
-16
docs/examples/tutorial/string/utf_eight.pyx
docs/examples/tutorial/string/utf_eight.pyx
+15
-0
docs/src/tutorial/strings.rst
docs/src/tutorial/strings.rst
+2
-16
No files found.
docs/examples/tutorial/string/utf_eight.pyx
0 → 100644
View file @
715d093b
from
libc.stdlib
cimport
free
cdef
unicode
tounicode
(
char
*
s
):
return
s
.
decode
(
'UTF-8'
,
'strict'
)
cdef
unicode
tounicode_with_length
(
char
*
s
,
size_t
length
):
return
s
[:
length
].
decode
(
'UTF-8'
,
'strict'
)
cdef
unicode
tounicode_with_length_and_free
(
char
*
s
,
size_t
length
):
try
:
return
s
[:
length
].
decode
(
'UTF-8'
,
'strict'
)
finally
:
free
(
s
)
\ No newline at end of file
docs/src/tutorial/strings.rst
View file @
715d093b
...
...
@@ -312,23 +312,9 @@ that are 'obviously' correct than to rely on the data to be as expected.
It is common practice to wrap string conversions (and non-trivial type
conversions in general) in dedicated functions, as this needs to be
done in exactly the same way whenever receiving text from C. This
could look as follows:
:
could look as follows:
from libc.stdlib cimport free
cdef unicode tounicode(char* s):
return s.decode('UTF-8', 'strict')
cdef unicode tounicode_with_length(
char* s, size_t length):
return s[:length].decode('UTF-8', 'strict')
cdef unicode tounicode_with_length_and_free(
char* s, size_t length):
try:
return s[:length].decode('UTF-8', 'strict')
finally:
free(s)
.. literalinclude:: ../../examples/tutorial/string/utf_eight.pyx
Most likely, you will prefer shorter function names in your code based
on the kind of string being handled. Different types of content often
...
...
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