def _leadingTabs(text, tabSize, tabsAtMost=-1):
    """
    Returns the number of leading tabs.
    If there are 'tabSize' number of consecutive spaces, 
    then this will interpreted as a single tab.

    text (string):
    The text from which to count the leading tabs from.

    tabSize (integer):
    The number of spaces in a tab.

    tabsAtMost (integer):
    The number of leading tabs to count at most.
    If this is negative, then the number of tabs
    to count is not limited.

    returns (integer, integer):
    The first number of is the number of leading tabs,
    as defined above. The second number is the number
    of leading characters taking part to this count.
    """
    tabs = 0
    consecutiveSpaces = 0
    characters = 0
    for c in text:
        if c == '\t':
            tabs += 1
            characters += consecutiveSpaces + 1
            consecutiveSpaces = 0
        elif c == ' ':
            consecutiveSpaces += 1
            if consecutiveSpaces == tabSize:
                tabs += 1
                characters += consecutiveSpaces
                consecutiveSpaces = 0
        else:
            break
        if tabsAtMost >= 0 and tabs == tabsAtMost:
            break
    return tabs, characters
