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
b1667e9e
Commit
b1667e9e
authored
Jun 22, 2018
by
scoder
Committed by
GitHub
Jun 22, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2384 from gabrieldemarmiesse/test_string_9
Adding tests for "Unicode and passing strings" part 9
parents
d385e3f3
715d093b
Changes
2
Show 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 @
b1667e9e
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 @
b1667e9e
...
@@ -306,23 +306,9 @@ that are 'obviously' correct than to rely on the data to be as expected.
...
@@ -306,23 +306,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
It is common practice to wrap string conversions (and non-trivial type
conversions in general) in dedicated functions, as this needs to be
conversions in general) in dedicated functions, as this needs to be
done in exactly the same way whenever receiving text from C. This
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
.. literalinclude:: ../../examples/tutorial/string/utf_eight.pyx
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)
Most likely, you will prefer shorter function names in your code based
Most likely, you will prefer shorter function names in your code based
on the kind of string being handled. Different types of content often
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