def capitalize(text):
    """
    Capitalize first non-whitespace character folling each period in string

    :param str text: text to capitalize
    :return: capitalized text
    :rtype: str
    """
    ret = list(text)
    i = 0
    while i < len(text) - 1 and text[i].isspace():
        i += 1
    if text[i].isalpha() and text[i].islower():
        ret[i] = ret[i].upper()
    p = 0
    while p < len(text) - 1:
        p = text.find('.', p)
        if p < 0:
            break
        p += 1
        w = p
        while w < len(text) - 1 and text[w].isspace():
            w += 1
        if text[w].isalpha() and text[w].islower():
            ret[w] = ret[w].upper()
    return ''.join(ret)
