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
Boxiang Sun
cython
Commits
7224f33a
Commit
7224f33a
authored
Feb 20, 2013
by
zaur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for negative indices in unicode_slicing and PyUnicode_READY in __Pyx_PyUnicode_Substring
parent
b12402fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
44 deletions
+82
-44
Cython/Utility/StringTools.c
Cython/Utility/StringTools.c
+5
-0
tests/run/bytesmethods.pyx
tests/run/bytesmethods.pyx
+6
-6
tests/run/unicode_slicing.pyx
tests/run/unicode_slicing.pyx
+71
-38
No files found.
Cython/Utility/StringTools.c
View file @
7224f33a
...
...
@@ -394,6 +394,11 @@ PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(text)+start, stop-start)
static
CYTHON_INLINE
PyObject
*
__Pyx_PyUnicode_Substring
(
PyObject
*
text
,
Py_ssize_t
start
,
Py_ssize_t
stop
)
{
Py_ssize_t
length
;
#if CYTHON_PEP393_ENABLED
if
(
PyUnicode_READY
(
self
)
==
-
1
)
return
NULL
;
#endif
#if CYTHON_PEP393_ENABLED
length
=
PyUnicode_GET_LENGTH
(
text
);
#else
...
...
tests/run/bytesmethods.pyx
View file @
7224f33a
...
...
@@ -133,13 +133,13 @@ def bytes_decode(bytes s, start=None, stop=None):
AttributeError: 'NoneType' object has no attribute 'decode'
>>> print(bytes_decode(None, 1))
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'decode'
TypeError: 'NoneType' object is not subscriptable
>>> print(bytes_decode(None, None, 1))
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'decode'
TypeError: 'NoneType' object is not subscriptable
>>> print(bytes_decode(None, 0, 1))
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'decode'
TypeError: 'NoneType' object is not subscriptable
"""
if
start
is
None
:
if
stop
is
None
:
...
...
@@ -173,13 +173,13 @@ def bytes_decode_unbound_method(bytes s, start=None, stop=None):
TypeError: descriptor 'decode' requires a 'bytes' object but received a 'NoneType'
>>> print(bytes_decode_unbound_method(None, 1))
Traceback (most recent call last):
TypeError:
descriptor 'decode' requires a 'bytes' object but received a 'NoneType'
TypeError:
'NoneType' object is not subscriptable
>>> print(bytes_decode_unbound_method(None, None, 1))
Traceback (most recent call last):
TypeError:
descriptor 'decode' requires a 'bytes' object but received a 'NoneType'
TypeError:
'NoneType' object is not subscriptable
>>> print(bytes_decode_unbound_method(None, 0, 1))
Traceback (most recent call last):
TypeError:
descriptor 'decode' requires a 'bytes' object but received a 'NoneType'
TypeError:
'NoneType' object is not subscriptable
"""
if
start
is
None
:
if
stop
is
None
:
...
...
tests/run/unicode_slicing.pyx
View file @
7224f33a
...
...
@@ -2,61 +2,97 @@
__doc__
=
u"""
>>> do_slice1(u'abcdef', 2, 3)
u'c'
c
>>> do_slice2(u'abcdef', 2, 3)
u'cdef'
cdef
>>> do_slice3(u'abcdef', 2, 3)
u'ab'
ab
>>> do_slice4(u'abcdef', 2, 3)
u'abcdef'
abcdef
>>> do_slice5(u'abcdef', 2, 3)
u'cdef'
cdef
>>> do_slice6(u'abcdef', 2, 3)
u'ab'
ab
>>> do_slice7(u'abcdef', 2, 3)
u'abcdef'
abcdef
>>> do_slice1(u'abcdef', 2, 10)
cdef
>>> do_slice2(u'abcdef', 2, 10)
cdef
>>> do_slice3(u'abcdef', 2, 10)
ab
>>> do_slice4(u'abcdef', 2, 10)
abcdef
>>> do_slice1(u'abcdef', 0, 5)
u'abcde'
abcde
>>> do_slice2(u'abcdef', 0, 5)
u'abcdef'
abcdef
>>> do_slice3(u'abcdef', 0, 5)
u''
<BLANKLINE>
>>> do_slice4(u'abcdef', 0, 5)
u'abcdef'
abcdef
>>> do_slice5(u'abcdef', 0, 5)
u'abcdef'
abcdef
>>> do_slice6(u'abcdef', 0, 5)
u''
<BLANKLINE>
>>> do_slice7(u'abcdef', 0, 5)
u'abcdef'
abcdef
>>> do_slice1(u'abcdef', -6, -1)
abcde
>>> do_slice2(u'abcdef', -6, -1)
abcdef
>>> do_slice3(u'abcdef', -6, -1)
<BLANKLINE>
>>> do_slice4(u'abcdef', -6, -1)
abcdef
>>> do_slice5(u'abcdef', -6, -1)
abcdef
>>> do_slice6(u'abcdef', -6, -1)
<BLANKLINE>
>>> do_slice7(u'abcdef', -6, -1)
abcdef
>>> do_slice1(u'aАbБcСdДeЕfФ', 2, 8)
u'bБcСdД'
bБcСdД
>>> do_slice2(u'aАbБcСdДeЕfФ', 2, 8)
u'bБcСdДeЕfФ'
bБcСdДeЕfФ
>>> do_slice3(u'aАbБcСdДeЕfФ', 2, 8)
u'aА'
aА
>>> do_slice4(u'aАbБcСdДeЕfФ', 2, 8)
u'aАbБcСdДeЕfФ'
aАbБcСdДeЕfФ
>>> do_slice5(u'aАbБcСdДeЕfФ', 2, 8)
u'bБcСdДeЕfФ'
bБcСdДeЕfФ
>>> do_slice6(u'aАbБcСdДeЕfФ', 2, 8)
u'aА'
aА
>>> do_slice7(u'aАbБcСdДeЕfФ', 2, 8)
u'aАbБcСdДeЕfФ'
aАbБcСdДeЕfФ
>>> do_slice1(u'АБСДЕФ', 2, 4)
u'СД'
СД
>>> do_slice2(u'АБСДЕФ', 2, 4)
u'СДЕФ'
СДЕФ
>>> do_slice3(u'АБСДЕФ', 2, 4)
u'АБ'
АБ
>>> do_slice4(u'АБСДЕФ', 2, 4)
u'АБСДЕФ'
АБСДЕФ
>>> do_slice5(u'АБСДЕФ', 2, 4)
u'СДЕФ'
СДЕФ
>>> do_slice6(u'АБСДЕФ', 2, 4)
u'АБ'
АБ
>>> do_slice7(u'АБСДЕФ', 2, 4)
u'АБСДЕФ'
АБСДЕФ
>>> do_slice1(u'АБСДЕФ', -4, -2)
СД
>>> do_slice2(u'АБСДЕФ', -4, -2)
СДЕФ
>>> do_slice3(u'АБСДЕФ', -4, -2)
АБ
>>> do_slice4(u'АБСДЕФ', -4, -2)
АБСДЕФ
>>> do_slice5(u'АБСДЕФ', -4, -2)
СДЕФ
>>> do_slice6(u'АБСДЕФ', -4, -2)
АБ
>>> do_slice7(u'АБСДЕФ', -4, -2)
АБСДЕФ
>>> do_slice1(None, 2, 4)
Traceback (most recent call last):
TypeError: 'NoneType' object is not subscriptable
...
...
@@ -84,27 +120,24 @@ import sys
if
sys
.
version_info
[
0
]
>=
3
:
__doc__
=
__doc__
.
replace
(
u"(u'"
,
u"('"
).
replace
(
u" u'"
,
u" '"
)
ss
=
"'"
else
:
ss
=
"u'"
def
do_slice1
(
unicode
s
,
int
i
,
int
j
):
print
(
s
s
+
s
[
i
:
j
]
+
"'"
)
print
(
s
[
i
:
j
]
)
def
do_slice2
(
unicode
s
,
int
i
,
int
j
):
print
(
s
s
+
s
[
i
:]
+
"'"
)
print
(
s
[
i
:]
)
def
do_slice3
(
unicode
s
,
int
i
,
int
j
):
print
(
s
s
+
s
[:
i
]
+
"'"
)
print
(
s
[:
i
]
)
def
do_slice4
(
unicode
s
,
int
i
,
int
j
):
print
(
s
s
+
s
[:]
+
"'"
)
print
(
s
[:]
)
def
do_slice5
(
unicode
s
,
int
i
,
int
j
):
print
(
s
s
+
s
[
i
:
None
]
+
"'"
)
print
(
s
[
i
:
None
]
)
def
do_slice6
(
unicode
s
,
int
i
,
int
j
):
print
(
s
s
+
s
[
None
:
i
]
+
"'"
)
print
(
s
[
None
:
i
]
)
def
do_slice7
(
unicode
s
,
int
i
,
int
j
):
print
(
s
s
+
s
[
None
:
None
]
+
"'"
)
print
(
s
[
None
:
None
]
)
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