[pypy-svn] r10711 - pypy/dist/pypy/objspace/std
pedronis at codespeak.net
pedronis at codespeak.net
Fri Apr 15 21:27:48 CEST 2005
Author: pedronis
Date: Fri Apr 15 21:27:48 2005
New Revision: 10711
Modified:
pypy/dist/pypy/objspace/std/stringobject.py
Log:
reworked to depend less on string methods
Modified: pypy/dist/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/dist/pypy/objspace/std/stringobject.py (original)
+++ pypy/dist/pypy/objspace/std/stringobject.py Fri Apr 15 21:27:48 2005
@@ -147,6 +147,20 @@
return space.w_False
return space.w_True
+def _upper(ch):
+ if _islower(ch):
+ o = ord(ch) - 32
+ return chr(o)
+ else:
+ return ch
+
+def _lower(ch):
+ if _isupper(ch):
+ o = ord(ch) + 32
+ return chr(o)
+ else:
+ return ch
+
def str_isspace__String(space, w_self):
return _is_generic(w_self, _isspace)
@@ -171,9 +185,9 @@
for pos in range(0, len(input)):
ch = input[pos]
- if ch.isalpha():
- if (prev_letter.isalpha() and ch.isupper()) or \
- (not prev_letter.isalpha() and ch.islower()):
+ if _isalpha(ch):
+ if (_isalpha(prev_letter) and _isupper(ch)) or \
+ (not _isalpha(prev_letter) and _islower(ch)):
return space.w_False
prev_letter = ch
@@ -184,11 +198,7 @@
res = [' '] * len(self)
for i in range(len(self)):
ch = self[i]
- if _islower(ch):
- o = ord(ch) - 32
- res[i] = chr(o)
- else:
- res[i] = ch
+ res[i] = _upper(ch)
return space.wrap("".join(res))
@@ -197,11 +207,7 @@
res = [' '] * len(self)
for i in range(len(self)):
ch = self[i]
- if _isupper(ch):
- o = ord(ch) + 32
- res[i] = chr(o)
- else:
- res[i] = ch
+ res[i] = _lower(ch)
return space.wrap("".join(res))
@@ -250,10 +256,10 @@
for pos in range(0, len(input)):
ch = input[pos]
- if not prev_letter.isalpha():
- buffer[pos] = ch.upper()
+ if not _isalpha(prev_letter):
+ buffer[pos] = _upper(ch)
else:
- buffer[pos] = ch.lower()
+ buffer[pos] = _lower(ch)
prev_letter = buffer[pos]
@@ -267,7 +273,7 @@
pos = 0
for ch in value:
- if ch.isspace():
+ if _isspace(ch):
if inword:
inword = 0
else:
@@ -566,11 +572,11 @@
if left:
#print "while %d < %d and -%s- in -%s-:"%(lpos, rpos, u_self[lpos],w_chars)
- while lpos < rpos and u_self[lpos].isspace():
+ while lpos < rpos and _isspace(u_self[lpos]):
lpos += 1
if right:
- while rpos > lpos and u_self[rpos - 1].isspace():
+ while rpos > lpos and _isspace(u_self[rpos - 1]):
rpos -= 1
return space.wrap(u_self[lpos:rpos])
More information about the Pypy-commit
mailing list