@staticmethod
def _do_encapsulated_split(text: str, sep_init='(', sep_end=')',
    include_separators=False):
    """
        Splits by text between tokens.
        :param text: text to split
        :param sep_init: token that specifies the start of the segment
        :param sep_end: token that specifies the end of the segment
        :param include_separators: boolean flag that specifies if the token separators should be included in the
        segment or not.
        :return: split segments
        """
    segment = ''
    open = False
    ESCAPE_CHAR = '\\'
    previous = ''
    for index, l in enumerate(text):
        if l == sep_init and not open and previous != ESCAPE_CHAR:
            open = True
        elif l == sep_end and previous != ESCAPE_CHAR:
            break
        elif open:
            segment += l
        previous = l
    return segment if not include_separators else sep_init + segment + sep_end
