Commit 226f53c8 authored by scoder's avatar scoder Committed by GitHub

Merge pull request #2380 from gabrieldemarmiesse/test_string_6

Adding tests for "Unicode and passing strings" part 6
parents c9f7bce2 c36e1d35
# define a global name for whatever char type is used in the module
ctypedef unsigned char char_type
cdef char_type[:] _chars(s):
if isinstance(s, unicode):
# encode to the specific encoding used inside of the module
s = (<unicode>s).encode('utf8')
return s
......@@ -246,16 +246,9 @@ And should then be used like this:
Similarly, if the further processing happens at the byte level, but Unicode
string input should be accepted, then the following might work, if you are
using memory views::
using memory views:
# define a global name for whatever char type is used in the module
ctypedef unsigned char char_type
cdef char_type[:] _chars(s):
if isinstance(s, unicode):
# encode to the specific encoding used inside of the module
s = (<unicode>s).encode('utf8')
return s
.. literalinclude:: ../../examples/tutorial/string/to_char.pyx
In this case, you might want to additionally ensure that byte string
input really uses the correct encoding, e.g. if you require pure ASCII
......
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