[pypy-svn] r48715 - pypy/branch/ropes-unicode/pypy/objspace/std
cfbolz at codespeak.net
cfbolz at codespeak.net
Thu Nov 15 18:39:04 CET 2007
Author: cfbolz
Date: Thu Nov 15 18:39:02 2007
New Revision: 48715
Modified:
pypy/branch/ropes-unicode/pypy/objspace/std/rope.py
pypy/branch/ropes-unicode/pypy/objspace/std/ropeobject.py
Log:
move start/endswith helpers to rope.py
Modified: pypy/branch/ropes-unicode/pypy/objspace/std/rope.py
==============================================================================
--- pypy/branch/ropes-unicode/pypy/objspace/std/rope.py (original)
+++ pypy/branch/ropes-unicode/pypy/objspace/std/rope.py Thu Nov 15 18:39:02 2007
@@ -1120,6 +1120,39 @@
return len1 - len2
+def startswith(self, prefix, start, end):
+ if prefix.length() == 0:
+ return True
+ if self.length() == 0:
+ return False
+ stop = start + prefix.length()
+ if stop > end:
+ return False
+ iter1 = SeekableItemIterator(self)
+ iter1.seekforward(start)
+ iter2 = ItemIterator(prefix)
+ for i in range(prefix.length()):
+ if iter1.nextint() != iter2.nextint():
+ return False
+ return True
+
+def endswith(self, suffix, start, end):
+ if suffix.length() == 0:
+ return True
+ if self.length() == 0:
+ return False
+ begin = end - suffix.length()
+ if begin < start:
+ return False
+ iter1 = SeekableItemIterator(self)
+ iter1.seekforward(begin)
+ iter2 = ItemIterator(suffix)
+ for i in range(suffix.length()):
+ if iter1.nextint() != iter2.nextint():
+ return False
+ return True
+
+
# __________________________________________________________________________
# misc
Modified: pypy/branch/ropes-unicode/pypy/objspace/std/ropeobject.py
==============================================================================
--- pypy/branch/ropes-unicode/pypy/objspace/std/ropeobject.py (original)
+++ pypy/branch/ropes-unicode/pypy/objspace/std/ropeobject.py Thu Nov 15 18:39:02 2007
@@ -663,65 +663,34 @@
i += 1
return wrapint(space, i)
-def ropeendswith(self, suffix, start, end):
- if suffix.length() == 0:
- return True
- if self.length() == 0:
- return False
- begin = end - suffix.length()
- if begin < start:
- return False
- iter1 = rope.SeekableItemIterator(self)
- iter1.seekforward(begin)
- iter2 = rope.ItemIterator(suffix)
- for i in range(suffix.length()):
- if iter1.nextchar() != iter2.nextchar():
- return False
- return True
-
def str_endswith__Rope_Rope_ANY_ANY(space, w_self, w_suffix, w_start, w_end):
(self, suffix, start, end) = _convert_idx_params(space, w_self,
w_suffix, w_start, w_end)
- return space.newbool(ropeendswith(self, suffix, start, end))
+ return space.newbool(rope.endswith(self, suffix, start, end))
def str_endswith__Rope_Tuple_ANY_ANY(space, w_self, w_suffixes, w_start, w_end):
(self, _, start, end) = _convert_idx_params(space, w_self,
space.wrap(''), w_start, w_end)
for w_suffix in space.unpacktuple(w_suffixes):
suffix = rope_w(space, w_suffix)
- if ropeendswith(self, suffix, start, end):
+ if rope.endswith(self, suffix, start, end):
return space.w_True
return space.w_False
-def ropestartswith(self, prefix, start, end):
- if prefix.length() == 0:
- return True
- if self.length() == 0:
- return False
- stop = start + prefix.length()
- if stop > end:
- return False
- iter1 = rope.SeekableItemIterator(self)
- iter1.seekforward(start)
- iter2 = rope.ItemIterator(prefix)
- for i in range(prefix.length()):
- if iter1.nextchar() != iter2.nextchar():
- return False
- return True
def str_startswith__Rope_Rope_ANY_ANY(space, w_self, w_prefix, w_start, w_end):
(self, prefix, start, end) = _convert_idx_params(space, w_self,
w_prefix, w_start, w_end)
- return space.newbool(ropestartswith(self, prefix, start, end))
+ return space.newbool(rope.startswith(self, prefix, start, end))
def str_startswith__Rope_Tuple_ANY_ANY(space, w_self, w_prefixes, w_start, w_end):
(self, _, start, end) = _convert_idx_params(space, w_self, space.wrap(''),
w_start, w_end)
for w_prefix in space.unpacktuple(w_prefixes):
prefix = rope_w(space, w_prefix)
- if ropestartswith(self, prefix, start, end):
+ if rope.startswith(self, prefix, start, end):
return space.w_True
return space.w_False
More information about the Pypy-commit
mailing list