[Python-checkins] CVS: python/dist/src/Lib string.py,1.49,1.50
Fred L. Drake
python-dev@python.org
Mon, 3 Jul 2000 00:23:16 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory slayer.i.sourceforge.net:/tmp/cvs-serv31657
Modified Files:
string.py
Log Message:
Martin von Löwis <martin@loewis.home.cs.tu-berlin.de>:
This patch delegates more string functions to string object methods,
uses the varargs delegation syntax, and stops using stringold.
Closes SourceForge patch #100712.
Index: string.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/string.py,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -r1.49 -r1.50
*** string.py 2000/04/05 20:11:18 1.49
--- string.py 2000/07/03 07:23:13 1.50
***************
*** 126,132 ****
joinfields = join
- # for a little bit of speed
- _apply = apply
-
# Find substring, raise exception if not found
def index(s, *args):
--- 126,129 ----
***************
*** 136,140 ****
"""
! return _apply(s.index, args)
# Find last substring, raise exception if not found
--- 133,137 ----
"""
! return s.index(*args)
# Find last substring, raise exception if not found
***************
*** 145,149 ****
"""
! return _apply(s.rindex, args)
# Count non-overlapping occurrences of substring
--- 142,146 ----
"""
! return s.rindex(*args)
# Count non-overlapping occurrences of substring
***************
*** 156,160 ****
"""
! return _apply(s.count, args)
# Find substring, return -1 if not found
--- 153,157 ----
"""
! return s.count(*args)
# Find substring, return -1 if not found
***************
*** 169,173 ****
"""
! return _apply(s.find, args)
# Find last substring, return -1 if not found
--- 166,170 ----
"""
! return s.find(*args)
# Find last substring, return -1 if not found
***************
*** 182,186 ****
"""
! return _apply(s.rfind, args)
# for a bit of speed
--- 179,183 ----
"""
! return s.rfind(*args)
# for a bit of speed
***************
*** 240,246 ****
"""
! n = width - len(s)
! if n <= 0: return s
! return s + ' '*n
# Right-justify a string
--- 237,241 ----
"""
! return s.ljust(width)
# Right-justify a string
***************
*** 253,259 ****
"""
! n = width - len(s)
! if n <= 0: return s
! return ' '*n + s
# Center a string
--- 248,252 ----
"""
! return s.rjust(width)
# Center a string
***************
*** 266,276 ****
"""
! n = width - len(s)
! if n <= 0: return s
! half = n/2
! if n%2 and width%2:
! # This ensures that center(center(s, i), j) = center(s, j)
! half = half+1
! return ' '*half + s + ' '*(n-half)
# Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03'
--- 259,263 ----
"""
! return s.center(width)
# Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03'
***************
*** 303,315 ****
"""
! res = line = ''
! for c in s:
! if c == '\t':
! c = ' '*(tabsize - len(line) % tabsize)
! line = line + c
! if c == '\n':
! res = res + line
! line = ''
! return res + line
# Character translation through look-up table.
--- 290,294 ----
"""
! return s.expandtabs(tabsize)
# Character translation through look-up table.
***************
*** 380,393 ****
return s.replace(old, new, maxsplit)
-
- # XXX: transitional
- #
- # If string objects do not have methods, then we need to use the old string.py
- # library, which uses strop for many more things than just the few outlined
- # below.
- try:
- ''.upper
- except AttributeError:
- from stringold import *
# Try importing optional built-in module "strop" -- if it exists,
--- 359,362 ----