def guarded_find(substring, excerpt, pos=0, endpos=None):
    """Searches for a substring in an excerpt.

    :Parameters:
      - `substring`: substring that should be looked for
      - `excerpt`: excerpt of text that should be searched
      - `pos`: starting position of the search
      - `endpos`: ending position for the search

    :type substring: unicode
    :type excerpt: preprocessor.Excerpt
    :type pos: int
    :type endpos: int

    :Return:
      The index of the first occurence of `substring` in `excerpt`.  `None` if
      the substring was not found.

    :rtype: int
    """
    if endpos == None:
        result = excerpt.escaped_text().find(substring, pos)
    else:
        result = excerpt.escaped_text().find(substring, pos, endpos)
    if result == -1:
        result = None
    return result