Mercurial > cpython-lru_cache-weakref
diff Lib/string.py @ 2541:b72ccf5b7dbc legacy-trunk
add dummy base to atoi/atol; careful about negative start indices in find/count
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Tue, 14 Mar 1995 17:43:02 +0000 |
| parents | 56a986e49f56 |
| children | 17fdec2fb309 |
line wrap: on
line diff
--- a/Lib/string.py Tue Mar 14 17:41:36 1995 +0000 +++ b/Lib/string.py Tue Mar 14 17:43:02 1995 +0000 @@ -115,7 +115,7 @@ # Count non-overlapping occurrences of substring def count(s, sub, i = 0): - if i < 0: i = i + len(s) + if i < 0: i = max(0, i + len(s)) n = len(sub) m = len(s) + 1 - n if n == 0: return m-i @@ -130,7 +130,7 @@ # Find substring, return -1 if not found def find(s, sub, i = 0): - if i < 0: i = i + len(s) + if i < 0: i = max(0, i + len(s)) n = len(sub) m = len(s) + 1 - n while i < m: @@ -140,7 +140,7 @@ # Find last substring, return -1 if not found def rfind(s, sub, i = 0): - if i < 0: i = i + len(s) + if i < 0: i = max(0, i + len(s)) n = len(sub) m = len(s) + 1 - n r = -1 @@ -168,7 +168,10 @@ raise ValueError, 'non-float argument to string.atof' # Convert string to integer -def atoi(str): +def atoi(str, base=10): + if base != 10: + # We only get here if strop doesn't define atoi() + raise ValueError, "this string.atoi doesn't support base != 10" sign = '' s = str if s and s[0] in '+-': @@ -183,7 +186,10 @@ return eval(sign + s) # Convert string to long integer -def atol(str): +def atol(str, base=10): + if base != 10: + # We only get here if strop doesn't define atol() + raise ValueError, "this string.atol doesn't support base != 10" sign = '' s = str if s and s[0] in '+-':
