summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/string
diff options
context:
space:
mode:
authorgabrieldemarmiesse <gabriel.demarmiesse@teraki.com>2018-06-19 11:35:35 +0200
committergabrieldemarmiesse <gabriel.demarmiesse@teraki.com>2018-06-19 11:35:35 +0200
commitc36e1d358554c6802939a2012ebe152b207eac1a (patch)
treeeb06b4e26a838c1fafba0a9f722bc44bd36d5435 /docs/examples/tutorial/string
parent5c04c1a8ffd3a09c00cad41604bb648b786b8dda (diff)
downloadcython-c36e1d358554c6802939a2012ebe152b207eac1a.tar.gz
Moved an example from the string.rst to the examples directory.
Diffstat (limited to 'docs/examples/tutorial/string')
-rw-r--r--docs/examples/tutorial/string/to_char.pyx8
1 files changed, 8 insertions, 0 deletions
diff --git a/docs/examples/tutorial/string/to_char.pyx b/docs/examples/tutorial/string/to_char.pyx
new file mode 100644
index 000000000..5e4a16161
--- /dev/null
+++ b/docs/examples/tutorial/string/to_char.pyx
@@ -0,0 +1,8 @@
+# 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