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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
226f53c8
Commit
226f53c8
authored
Jun 20, 2018
by
scoder
Committed by
GitHub
Jun 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2380 from gabrieldemarmiesse/test_string_6
Adding tests for "Unicode and passing strings" part 6
parents
c9f7bce2
c36e1d35
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
9 deletions
+10
-9
docs/examples/tutorial/string/to_char.pyx
docs/examples/tutorial/string/to_char.pyx
+8
-0
docs/src/tutorial/strings.rst
docs/src/tutorial/strings.rst
+2
-9
No files found.
docs/examples/tutorial/string/to_char.pyx
0 → 100644
View file @
226f53c8
# 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
docs/src/tutorial/strings.rst
View file @
226f53c8
...
...
@@ -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
...
...
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