2006-08-19 08:03:29 +04:00
|
|
|
# strutil.py - string utilities for Mercurial
|
|
|
|
#
|
|
|
|
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
|
|
|
|
#
|
2009-04-26 03:08:54 +04:00
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2006-08-19 08:03:29 +04:00
|
|
|
|
2015-08-09 06:01:40 +03:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2006-08-19 08:03:29 +04:00
|
|
|
def findall(haystack, needle, start=0, end=None):
|
|
|
|
if end is None:
|
|
|
|
end = len(haystack)
|
|
|
|
if end < 0:
|
|
|
|
end += len(haystack)
|
|
|
|
if start < 0:
|
|
|
|
start += len(haystack)
|
|
|
|
while start < end:
|
|
|
|
c = haystack.find(needle, start, end)
|
|
|
|
if c == -1:
|
|
|
|
break
|
|
|
|
yield c
|
|
|
|
start = c + 1
|
|
|
|
|
|
|
|
def rfindall(haystack, needle, start=0, end=None):
|
|
|
|
if end is None:
|
|
|
|
end = len(haystack)
|
|
|
|
if end < 0:
|
|
|
|
end += len(haystack)
|
|
|
|
if start < 0:
|
|
|
|
start += len(haystack)
|
|
|
|
while end >= 0:
|
|
|
|
c = haystack.rfind(needle, start, end)
|
|
|
|
if c == -1:
|
|
|
|
break
|
|
|
|
yield c
|
|
|
|
end = c - 1
|