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
c0516913
Commit
c0516913
authored
Jul 29, 2014
by
Krzysztof Klinikowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup, fixes after CR
parent
488c1139
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
133 additions
and
246 deletions
+133
-246
src/runtime/str.cpp
src/runtime/str.cpp
+43
-36
test/tests/str_isalnum_test.py
test/tests/str_isalnum_test.py
+0
-31
test/tests/str_isalpha_test.py
test/tests/str_isalpha_test.py
+0
-27
test/tests/str_isdigit_test.py
test/tests/str_isdigit_test.py
+0
-21
test/tests/str_islower_test.py
test/tests/str_islower_test.py
+0
-28
test/tests/str_isspace_test.py
test/tests/str_isspace_test.py
+0
-30
test/tests/str_istitle_test.py
test/tests/str_istitle_test.py
+0
-39
test/tests/str_isupper_test.py
test/tests/str_isupper_test.py
+0
-28
test/tests/str_manipulation.py
test/tests/str_manipulation.py
+90
-6
No files found.
src/runtime/str.cpp
View file @
c0516913
...
...
@@ -381,13 +381,13 @@ Box* strIsAlpha(BoxedString* self) {
assert
(
self
->
cls
==
str_cls
);
std
::
string
str
(
self
->
s
);
std
::
string
::
size_type
i
;
if
(
str
.
empty
())
return
False
;
for
(
const
auto
&
i
:
str
)
if
(
!
std
::
isalpha
(
str
[
i
]
))
for
(
const
auto
&
i
:
str
)
{
if
(
!
std
::
isalpha
(
i
))
return
False
;
}
return
True
;
}
...
...
@@ -396,13 +396,13 @@ Box* strIsDigit(BoxedString* self) {
assert
(
self
->
cls
==
str_cls
);
std
::
string
str
(
self
->
s
);
std
::
string
::
size_type
i
;
if
(
str
.
empty
())
return
False
;
for
(
const
auto
&
i
:
str
)
if
(
!
std
::
isdigit
(
str
[
i
]
))
for
(
const
auto
&
i
:
str
)
{
if
(
!
std
::
isdigit
(
i
))
return
False
;
}
return
True
;
}
...
...
@@ -411,13 +411,13 @@ Box* strIsAlnum(BoxedString* self) {
assert
(
self
->
cls
==
str_cls
);
std
::
string
str
(
self
->
s
);
std
::
string
::
size_type
i
;
if
(
str
.
empty
())
return
False
;
for
(
const
auto
&
i
:
str
)
if
(
!
std
::
isalnum
(
str
[
i
]
))
for
(
const
auto
&
i
:
str
)
{
if
(
!
std
::
isalnum
(
i
))
return
False
;
}
return
True
;
}
...
...
@@ -427,28 +427,44 @@ Box* strIsLower(BoxedString* self) {
assert
(
self
->
cls
==
str_cls
);
std
::
string
str
(
self
->
s
);
std
::
string
::
size_type
i
;
bool
lowered
=
false
;
if
(
str
.
empty
())
return
False
;
for
(
const
auto
&
i
:
str
)
if
(
!
std
::
islower
(
i
))
for
(
const
auto
&
i
:
str
)
{
if
(
std
::
isspace
(
i
)
||
std
::
isdigit
(
i
))
{
continue
;
}
else
if
(
!
std
::
islower
(
i
))
{
return
False
;
}
else
{
lowered
=
true
;
}
}
return
True
;
return
boxBool
(
lowered
)
;
}
Box
*
strIsUpper
(
BoxedString
*
self
)
{
assert
(
self
->
cls
==
str_cls
);
std
::
string
str
(
self
->
s
);
std
::
string
::
size_type
i
;
bool
uppered
=
false
;
if
(
str
.
empty
())
return
False
;
for
(
const
auto
&
i
:
str
)
if
(
!
std
::
isupper
(
str
[
i
]))
for
(
const
auto
&
i
:
str
)
{
if
(
std
::
isspace
(
i
)
||
std
::
isdigit
(
i
))
{
continue
;
}
else
if
(
!
std
::
isupper
(
i
))
{
return
False
;
}
else
{
uppered
=
true
;
}
}
return
boxBool
(
uppered
);
return
True
;
}
...
...
@@ -457,13 +473,13 @@ Box* strIsSpace(BoxedString* self) {
assert
(
self
->
cls
==
str_cls
);
std
::
string
str
(
self
->
s
);
std
::
string
::
size_type
i
;
if
(
str
.
empty
())
return
False
;
for
(
const
auto
&
i
:
str
)
if
(
!
std
::
isspace
(
str
[
i
]
))
for
(
const
auto
&
i
:
str
)
{
if
(
!
std
::
isspace
(
i
))
return
False
;
}
return
True
;
}
...
...
@@ -472,47 +488,38 @@ Box* strIsTitle(BoxedString* self) {
assert
(
self
->
cls
==
str_cls
);
std
::
string
str
(
self
->
s
);
std
::
string
::
size_type
i
;
if
(
str
.
empty
())
return
False
;
if
(
str
.
size
()
==
1
)
return
boxBool
(
std
::
isupper
(
str
[
0
]));
bool
cased
=
false
,
previous_is_case
d
=
false
;
bool
cased
=
false
,
start_of_wor
d
=
false
;
for
(
const
auto
&
i
:
str
)
{
if
(
std
::
isupper
(
str
[
i
]
))
{
if
(
previous_is_case
d
)
{
if
(
std
::
isupper
(
i
))
{
if
(
start_of_wor
d
)
{
return
False
;
}
previous_is_case
d
=
true
;
start_of_wor
d
=
true
;
cased
=
true
;
}
else
if
(
std
::
islower
(
str
[
i
]
))
{
if
(
!
previous_is_case
d
)
{
}
else
if
(
std
::
islower
(
i
))
{
if
(
!
start_of_wor
d
)
{
return
False
;
}
previous_is_case
d
=
true
;
start_of_wor
d
=
true
;
cased
=
true
;
}
else
{
previous_is_case
d
=
false
;
start_of_wor
d
=
false
;
}
}
return
boxBool
(
cased
);
}
Box
*
strLower
(
BoxedString
*
self
)
{
assert
(
self
->
cls
==
str_cls
);
std
::
string
lowered
(
self
->
s
);
std
::
transform
(
lowered
.
begin
(),
lowered
.
end
(),
lowered
.
begin
(),
tolower
);
return
boxString
(
std
::
move
(
lowered
));
}
Box
*
strJoin
(
BoxedString
*
self
,
Box
*
rhs
)
{
assert
(
self
->
cls
==
str_cls
);
...
...
test/tests/str_isalnum_test.py
deleted
100644 → 0
View file @
488c1139
var
=
''
assert
var
.
isalnum
()
==
False
var
=
'a'
assert
var
.
isalnum
()
==
True
var
=
'A'
assert
var
.
isalnum
()
==
True
var
=
'
\
n
'
assert
var
.
isalnum
()
==
False
var
=
'123abc456'
assert
var
.
isalnum
()
==
True
var
=
'a1b3c'
assert
var
.
isalnum
()
==
True
var
=
'aBc000 '
assert
var
.
isalnum
()
==
False
var
=
'abc
\
n
'
assert
var
.
isalnum
()
==
False
try
:
var
=
'abc'
var
.
isalnum
(
42
)
assert
False
except
TypeError
:
assert
True
test/tests/str_isalpha_test.py
deleted
100644 → 0
View file @
488c1139
var
=
''
assert
var
.
isalpha
()
==
False
var
=
'a'
assert
var
.
isalpha
()
==
True
var
=
'A'
assert
var
.
isalpha
()
==
True
var
=
'
\
n
'
assert
var
.
isalpha
()
==
False
var
=
'abc'
assert
var
.
isalpha
()
==
True
var
=
'aBc123'
assert
var
.
isalpha
()
==
False
var
=
'abc
\
n
'
assert
var
.
isalpha
()
==
False
try
:
var
=
'abc'
var
.
isalpha
(
42
)
assert
False
except
TypeError
:
assert
True
test/tests/str_isdigit_test.py
deleted
100644 → 0
View file @
488c1139
var
=
''
assert
var
.
isdigit
()
==
False
var
=
'a'
assert
var
.
isdigit
()
==
False
var
=
'0'
assert
var
.
isdigit
()
==
True
var
=
'0123456789'
assert
var
.
isdigit
()
==
True
var
=
'0123456789a'
assert
var
.
isdigit
()
==
False
try
:
var
=
'abc'
var
.
isdigit
(
42
)
assert
False
except
TypeError
:
assert
True
test/tests/str_islower_test.py
deleted
100644 → 0
View file @
488c1139
var
=
''
assert
var
.
islower
()
==
False
var
=
'a'
assert
var
.
islower
()
==
True
var
=
'A'
assert
var
.
islower
()
==
False
var
=
'
\
n
'
assert
var
.
islower
()
==
False
var
=
'abc'
assert
var
.
islower
()
==
True
var
=
'aBc'
assert
var
.
islower
()
==
False
# TODO: not supported yet
#var = 'abc\n'
#assert var.islower() == True
try
:
var
=
'abc'
var
.
islower
(
42
)
assert
False
except
TypeError
:
assert
True
test/tests/str_isspace_test.py
deleted
100644 → 0
View file @
488c1139
var
=
''
assert
var
.
isspace
()
==
False
var
=
'a'
assert
var
.
isspace
()
==
False
var
=
' '
assert
var
.
isspace
()
==
True
var
=
'
\
t
'
assert
var
.
isspace
()
==
True
var
=
'
\
r
'
assert
var
.
isspace
()
==
True
var
=
'
\
n
'
assert
var
.
isspace
()
==
True
var
=
'
\
t
\
r
\
n
'
assert
var
.
isspace
()
==
True
var
=
'
\
t
\
r
\
n
a'
assert
var
.
isspace
()
==
False
try
:
var
=
'abc'
var
.
isspace
(
42
)
assert
False
except
TypeError
:
assert
True
test/tests/str_istitle_test.py
deleted
100644 → 0
View file @
488c1139
var
=
''
assert
var
.
istitle
()
==
False
var
=
'a'
assert
var
.
istitle
()
==
False
var
=
'A'
assert
var
.
istitle
()
==
True
var
=
'
\
n
'
assert
var
.
istitle
()
==
False
var
=
'A Titlecased Line'
assert
var
.
istitle
()
==
True
var
=
'A
\
n
Titlecased Line'
assert
var
.
istitle
()
==
True
var
=
'A Titlecased, Line'
assert
var
.
istitle
()
==
True
var
=
'Not a capitalized String'
assert
var
.
istitle
()
==
False
var
=
'Not
\
t
a Titlecase String'
assert
var
.
istitle
()
==
False
var
=
'Not--a Titlecase String'
assert
var
.
istitle
()
==
False
var
=
'NOT'
assert
var
.
istitle
()
==
False
try
:
var
=
'abc'
var
.
istitle
(
42
)
assert
False
except
TypeError
:
assert
True
test/tests/str_isupper_test.py
deleted
100644 → 0
View file @
488c1139
var
=
''
assert
var
.
isupper
()
==
False
var
=
'a'
assert
var
.
isupper
()
==
False
var
=
'A'
assert
var
.
isupper
()
==
True
var
=
'
\
n
'
assert
var
.
isupper
()
==
False
var
=
'ABC'
assert
var
.
isupper
()
==
True
var
=
'AbC'
assert
var
.
isupper
()
==
False
# TODO: not supported yet
#var = 'ABC\n'
#assert var.isupper() == True
try
:
var
=
'abc'
var
.
isupper
(
42
)
assert
False
except
TypeError
:
assert
True
test/tests/str_manipulation.py
View file @
c0516913
# Testing capitalize/title methods.
def
test
(
s
):
...
...
@@ -32,12 +33,6 @@ try:
except
TypeError
:
print
'TypeError raised'
for
i
in
xrange
(
256
):
c
=
chr
(
i
)
s
=
"a%sb"
%
c
if
s
.
title
()[
2
]
==
'b'
:
print
repr
(
c
)
try
:
var
=
'hello'
var
.
lower
(
42
)
...
...
@@ -58,3 +53,92 @@ try:
print
'TypeError not raised'
except
TypeError
:
print
'TypeError raised'
for
i
in
xrange
(
256
):
c
=
chr
(
i
)
s
=
"a%sb"
%
c
if
s
.
title
()[
2
]
==
'b'
:
print
repr
(
c
)
# Testing isalnum, isalpha, isdigit, islower, isspace, istitle and isupper methods
def
test_is
(
s
):
print
'string:'
,
repr
(
s
),
'isalnum:'
,
s
.
isalnum
(),
'isalpha:'
,
s
.
isalpha
(),
'isdigit:'
,
s
.
isdigit
(),
'islower:'
,
s
.
islower
(),
'isspace:'
,
s
.
isspace
(),
'istitle:'
,
s
.
istitle
(),
'isupper:'
,
s
.
isupper
()
test_is
(
''
)
test_is
(
'a'
)
test_is
(
'A'
)
test_is
(
'123abc456'
)
test_is
(
'a1b3c'
)
test_is
(
'aBc000 '
)
test_is
(
'abc
\
n
'
)
test_is
(
'aBc123'
)
test_is
(
'abc'
)
test_is
(
'0'
)
test_is
(
'0123456789'
)
test_is
(
'0123456789a'
)
test_is
(
' '
)
test_is
(
'
\
t
'
)
test_is
(
'
\
r
'
)
test_is
(
'
\
n
'
)
test_is
(
'
\
t
\
r
\
n
'
)
test_is
(
'
\
t
\
r
\
n
a'
)
test_is
(
'A Titlecased Line'
)
test_is
(
'A
\
n
Titlecased Line'
)
test_is
(
'A Titlecased, Line'
)
test_is
(
'Not a capitalized String'
)
test_is
(
'Not
\
t
a Titlecase String'
)
test_is
(
'Not--a Titlecase String'
)
test_is
(
'NOT'
)
try
:
var
=
'abc'
var
.
isalnum
(
42
)
print
'TypeError not raised'
except
TypeError
:
print
'TypeError raised'
try
:
var
=
'abc'
var
.
isalpha
(
42
)
print
'TypeError not raised'
except
TypeError
:
print
'TypeError raised'
try
:
var
=
'abc'
var
.
isdigit
(
42
)
print
'TypeError not raised'
except
TypeError
:
print
'TypeError raised'
try
:
var
=
'abc'
var
.
islower
(
42
)
print
'TypeError not raised'
except
TypeError
:
print
'TypeError raised'
try
:
var
=
'abc'
var
.
isspace
(
42
)
print
'TypeError not raised'
except
TypeError
:
print
'TypeError raised'
try
:
var
=
'abc'
var
.
istitle
(
42
)
print
'TypeError not raised'
except
TypeError
:
print
'TypeError raised'
try
:
var
=
'abc'
var
.
isupper
(
42
)
print
'TypeError not raised'
except
TypeError
:
print
'TypeError raised'
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