def within_surrogate(text, index, *, length=None):
    """
    `True` if ``index`` is within a surrogate (before and after it, not at!).
    """
    if length is None:
        length = len(text)
    return 1 < index < len(text) and '\ud800' <= text[index - 1
        ] <= '\udfff' and '\ud800' <= text[index] <= '\udfff'
