Commit c36e1d35 authored by gabrieldemarmiesse's avatar gabrieldemarmiesse

Moved an example from the string.rst to the examples directory.

parent 5c04c1a8
# 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
...@@ -275,16 +275,9 @@ And should then be used like this:: ...@@ -275,16 +275,9 @@ And should then be used like this::
Similarly, if the further processing happens at the byte level, but Unicode 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 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 .. literalinclude:: ../../examples/tutorial/string/to_char.pyx
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
In this case, you might want to additionally ensure that byte string 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 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