def _strip_unbalanced_punctuation(text, is_open_char, is_close_char):
    """Remove unbalanced punctuation (e.g parentheses or quotes) from text.

    Removes each opening punctuation character for which it can't find
    corresponding closing character, and vice versa.
    It can only handle one type of punctuation
    (e.g. it could strip quotes or parentheses but not both).
    It takes functions (is_open_char, is_close_char),
    instead of the characters themselves,
    so that we can determine from nearby characters whether a straight quote is
    an opening or closing quote.

    Args:
        text (string): the text to fix
        is_open_char: a function that accepts the text and an index,
            and returns true if the character at that index is
            an opening punctuation mark.
        is_close_char: same as is_open_char for closing punctuation mark.

    Returns:
        The text with unmatched punctuation removed.
    """
    # lists of unmatched opening and closing chararacters
    opening_chars = []
    unmatched_closing_chars = []
    for idx, c in enumerate(text):
        if is_open_char(text, idx):
            opening_chars.append(idx)
        elif is_close_char(text, idx):
            if opening_chars:
                # this matches a character we found earlier
                opening_chars.pop()
            else:
                # this doesn't match any opening character
                unmatched_closing_chars.append(idx)
    char_indices = [i for (i, _) in enumerate(text)
                    if not(i in opening_chars or i in unmatched_closing_chars)]
    stripped_text = "".join([text[i] for i in char_indices])
    return stripped_text