Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
0920ed13
Commit
0920ed13
authored
Mar 05, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More unicode support
parent
3be62ae7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
7 deletions
+63
-7
src/runtime/float.cpp
src/runtime/float.cpp
+3
-0
src/runtime/str.cpp
src/runtime/str.cpp
+48
-7
test/tests/str_functions.py
test/tests/str_functions.py
+3
-0
test/tests/unicode_test.py
test/tests/unicode_test.py
+9
-0
No files found.
src/runtime/float.cpp
View file @
0920ed13
...
...
@@ -577,6 +577,9 @@ std::string floatFmt(double x, int precision, char code) {
}
BoxedFloat
*
_floatNew
(
Box
*
a
)
{
// FIXME CPython uses PyUnicode_EncodeDecimal:
a
=
coerceUnicodeToStr
(
a
);
if
(
a
->
cls
==
float_cls
)
{
return
static_cast
<
BoxedFloat
*>
(
a
);
}
else
if
(
isSubclass
(
a
->
cls
,
float_cls
))
{
...
...
src/runtime/str.cpp
View file @
0920ed13
...
...
@@ -1548,6 +1548,11 @@ Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) {
getTypeName
(
_self
));
BoxedString
*
self
=
static_cast
<
BoxedString
*>
(
_self
);
#ifdef Py_USING_UNICODE
if
(
PyUnicode_Check
(
_old
)
||
PyUnicode_Check
(
_new
))
return
PyUnicode_Replace
((
PyObject
*
)
self
,
_old
,
_new
,
-
1
/*count*/
);
#endif
if
(
_old
->
cls
!=
str_cls
)
raiseExcHelper
(
TypeError
,
"expected a character buffer object"
);
BoxedString
*
old
=
static_cast
<
BoxedString
*>
(
_old
);
...
...
@@ -1796,9 +1801,6 @@ Box* strStartswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
raiseExcHelper
(
TypeError
,
"descriptor 'startswith' requires a 'str' object but received a '%s'"
,
getTypeName
(
self
));
if
(
elt
->
cls
!=
str_cls
)
raiseExcHelper
(
TypeError
,
"expected a character buffer object"
);
Py_ssize_t
istart
=
0
,
iend
=
PY_SSIZE_T_MAX
;
if
(
start
)
{
int
r
=
_PyEval_SliceIndex
(
start
,
&
istart
);
...
...
@@ -1812,6 +1814,27 @@ Box* strStartswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
throwCAPIException
();
}
if
(
isSubclass
(
elt
->
cls
,
tuple_cls
))
{
for
(
auto
e
:
static_cast
<
BoxedTuple
*>
(
elt
)
->
elts
)
{
auto
b
=
strStartswith
(
self
,
e
,
start
,
_args
);
assert
(
b
->
cls
==
bool_cls
);
if
(
b
==
True
)
return
True
;
}
return
False
;
}
if
(
isSubclass
(
elt
->
cls
,
unicode_cls
))
{
int
r
=
PyUnicode_Tailmatch
(
self
,
elt
,
istart
,
iend
,
-
1
);
if
(
r
<
0
)
throwCAPIException
();
assert
(
r
==
0
||
r
==
1
);
return
boxBool
(
r
);
}
if
(
elt
->
cls
!=
str_cls
)
raiseExcHelper
(
TypeError
,
"expected a character buffer object"
);
BoxedString
*
sub
=
static_cast
<
BoxedString
*>
(
elt
);
Py_ssize_t
n
=
self
->
s
.
size
();
...
...
@@ -1841,9 +1864,6 @@ Box* strEndswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
raiseExcHelper
(
TypeError
,
"descriptor 'endswith' requires a 'str' object but received a '%s'"
,
getTypeName
(
self
));
if
(
elt
->
cls
!=
str_cls
)
raiseExcHelper
(
TypeError
,
"expected a character buffer object"
);
Py_ssize_t
istart
=
0
,
iend
=
PY_SSIZE_T_MAX
;
if
(
start
)
{
int
r
=
_PyEval_SliceIndex
(
start
,
&
istart
);
...
...
@@ -1857,6 +1877,27 @@ Box* strEndswith(BoxedString* self, Box* elt, Box* start, Box** _args) {
throwCAPIException
();
}
if
(
isSubclass
(
elt
->
cls
,
unicode_cls
))
{
int
r
=
PyUnicode_Tailmatch
(
self
,
elt
,
istart
,
iend
,
+
1
);
if
(
r
<
0
)
throwCAPIException
();
assert
(
r
==
0
||
r
==
1
);
return
boxBool
(
r
);
}
if
(
isSubclass
(
elt
->
cls
,
tuple_cls
))
{
for
(
auto
e
:
static_cast
<
BoxedTuple
*>
(
elt
)
->
elts
)
{
auto
b
=
strEndswith
(
self
,
e
,
start
,
_args
);
assert
(
b
->
cls
==
bool_cls
);
if
(
b
==
True
)
return
True
;
}
return
False
;
}
if
(
elt
->
cls
!=
str_cls
)
raiseExcHelper
(
TypeError
,
"expected a character buffer object"
);
BoxedString
*
sub
=
static_cast
<
BoxedString
*>
(
elt
);
Py_ssize_t
n
=
self
->
s
.
size
();
...
...
@@ -2358,7 +2399,7 @@ void setupStr() {
str_cls
->
giveAttr
(
"join"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strJoin
,
STR
,
2
)));
str_cls
->
giveAttr
(
"replace"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strReplace
,
STR
,
4
,
1
,
false
,
false
),
{
boxInt
(
-
1
)
}));
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strReplace
,
UNKNOWN
,
4
,
1
,
false
,
false
),
{
boxInt
(
-
1
)
}));
str_cls
->
giveAttr
(
"split"
,
new
BoxedFunction
(
boxRTFunction
((
void
*
)
strSplit
,
LIST
,
3
,
2
,
false
,
false
),
{
None
,
boxInt
(
-
1
)
}));
...
...
test/tests/str_functions.py
View file @
0920ed13
...
...
@@ -139,3 +139,6 @@ except:
print
repr
(
"hello
\
t
world
\
t
"
.
expandtabs
())
print
repr
(
"hello
\
t
world
\
t
"
.
expandtabs
(
12
))
print
"hello world"
.
startswith
((
"x"
,
"h"
))
print
"hello world"
.
endswith
((
"x"
,
"h"
))
test/tests/unicode_test.py
View file @
0920ed13
...
...
@@ -81,3 +81,12 @@ f(**{'a':2})
f
(
**
{
u'a'
:
3
})
print
repr
(
'%s'
%
u''
)
# this gives a unicode object!
print
repr
(
'hello world'
.
replace
(
u'hello'
,
u'hi'
))
print
"hello world"
.
endswith
(
u'hello'
)
print
"hello world"
.
endswith
(
u'world'
)
print
"hello world"
.
startswith
(
u'hello'
)
print
"hello world"
.
startswith
(
u'world'
)
print
float
(
u'1.0'
)
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