[pypy-commit] lang-io default: fix sequence asCapitalized to only capitalize first char and leave the rest unchanged
bivab
noreply at buildbot.pypy.org
Fri Sep 23 09:48:39 CEST 2011
Author: David Schneider <david.schneider at picle.org>
Branch:
Changeset: r46:495612e30422
Date: 2011-09-23 09:28 +0200
http://bitbucket.org/pypy/lang-io/changeset/495612e30422/
Log: fix sequence asCapitalized to only capitalize first char and leave
the rest unchanged
diff --git a/io/sequence.py b/io/sequence.py
--- a/io/sequence.py
+++ b/io/sequence.py
@@ -9,7 +9,7 @@
@register_method('Sequence', 'asCapitalized')
def sequence_as_capitalized(space, w_target, w_message, w_context):
- # c/p from pypy/objspace/std/stringobject.py
+ # based on pypy/objspace/std/stringobject.py
input = w_target.value
buffer = [' '] * len(input)
if len(input) > 0:
@@ -22,11 +22,7 @@
for i in range(1, len(input)):
ch = input[i]
- if ch.isupper():
- o = ord(ch) + 32
- buffer[i] = chr(o)
- else:
- buffer[i] = ch
+ buffer[i] = ch
s = space.w_sequence.clone()
s.value = "".join(buffer)
diff --git a/io/test/test_sequence.py b/io/test/test_sequence.py
--- a/io/test/test_sequence.py
+++ b/io/test/test_sequence.py
@@ -16,3 +16,9 @@
def test_sequence_as_capitalized():
inp = '"asdf qerttz" asCapitalized'
+ res, space = interpret(inp)
+ assert res.value == "Asdf qerttz"
+
+ inp = '"fooBar" asCapitalized'
+ res, space = interpret(inp)
+ assert res.value == "FooBar"
More information about the pypy-commit
mailing list