Show More
@@ -1,34 +1,36 | |||
|
1 | 1 | # strutil.py - string utilities for Mercurial |
|
2 | 2 | # |
|
3 | 3 | # Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com> |
|
4 | 4 | # |
|
5 | 5 | # This software may be used and distributed according to the terms of the |
|
6 | 6 | # GNU General Public License version 2 or any later version. |
|
7 | 7 | |
|
8 | from __future__ import absolute_import | |
|
9 | ||
|
8 | 10 | def findall(haystack, needle, start=0, end=None): |
|
9 | 11 | if end is None: |
|
10 | 12 | end = len(haystack) |
|
11 | 13 | if end < 0: |
|
12 | 14 | end += len(haystack) |
|
13 | 15 | if start < 0: |
|
14 | 16 | start += len(haystack) |
|
15 | 17 | while start < end: |
|
16 | 18 | c = haystack.find(needle, start, end) |
|
17 | 19 | if c == -1: |
|
18 | 20 | break |
|
19 | 21 | yield c |
|
20 | 22 | start = c + 1 |
|
21 | 23 | |
|
22 | 24 | def rfindall(haystack, needle, start=0, end=None): |
|
23 | 25 | if end is None: |
|
24 | 26 | end = len(haystack) |
|
25 | 27 | if end < 0: |
|
26 | 28 | end += len(haystack) |
|
27 | 29 | if start < 0: |
|
28 | 30 | start += len(haystack) |
|
29 | 31 | while end >= 0: |
|
30 | 32 | c = haystack.rfind(needle, start, end) |
|
31 | 33 | if c == -1: |
|
32 | 34 | break |
|
33 | 35 | yield c |
|
34 | 36 | end = c - 1 |
General Comments 0
You need to be logged in to leave comments.
Login now