def _splitbycharset(txt, charset):
    """Splits a string at the first occurrence of a character in a set.

    Args:
        txt: Text to split.
        chars: Chars to look for.

    Returns:
        Tuple (char, before, after). Char is the character which had been found
        (or empty string if nothing was found). Before is the substring before
        the splitting character (or the entire string). After is the substring
        after the splitting character (or empty string).
    """
    for firstpos, char in enumerate(txt):
        if char in charset:
            return txt[firstpos], txt[:firstpos], txt[firstpos + 1:]
    return '', txt, ''