summaryrefslogtreecommitdiff
path: root/docs/examples/tutorial/string/utf_eight.pyx
blob: 7113947f4007ac0773bcf3359b995136cf0b5d7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)