view mercurial/strutil.py @ 11148:a912f26777d3

merge: introduce tool.check parameter tool.check is a list of check options, and can be used in place of tool.checkchanged and tool.checkconflicts: Equivalences: tool.checkchanged = yes tool.checkconflicts = no tool.check = changed tool.checkchanged = no tool.checkconflicts = yes tool.check = conflicts tool.checkchanged = yes tool.checkconflicts = yes tool.check = changed, conflicts Add _toollist() wrapper for ui.configlist() to implement this consistently. checkchanged and checkconflicts are still supported, but check is preferred for implementing new check options.
author David Champion <dgc@uchicago.edu>
date Mon, 10 May 2010 11:04:56 -0500
parents 25e572394f5c
children b723f05ec49b
line wrap: on
line source

# strutil.py - string utilities for Mercurial
#
# Copyright 2006 Vadim Gelfer <vadim.gelfer@gmail.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.

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