def find_nth(s, sub, n, start=0, end=float('inf')):
    """ Get the index of the nth occurrence of a substring within a string

    Args:
        s (:obj:`str`): string to search
        sub (:obj:`str`): substring to search for
        n (:obj:`int`): number of occurence to find the position of
        start (:obj:`int`, optional): starting position to search from
        end (:obj:`int`, optional): end position to search within

    Returns:
        :obj:`int`: index of nth occurence of the substring within the string
            or -1 if there are less than n occurrences of the substring within
            the string

    Raises:
        :obj:`ValueError`: if `sub` is empty or `n` is less than 1
    """
    if not sub:
        raise ValueError('sep cannot be empty')
    if n < 1:
        raise ValueError('n must be at least 1')

    L = len(s)
    l = len(sub)
    count = 0
    i = start
    while i < min(end, L) - l + 1:
        if s[i:i+l] == sub:
            count += 1
            if count == n:
                return i
            i += l
        else:
            i += 1

    return -1