def split_refs(text):
    """Split text with embedded references into a sequence of text
    and references.

    Reference is returned as tuple (id, name).

    :returns: iterator over pieces of text and references.
    """
    while True:
        pos = text.find('\x01')
        if pos < 0:
            if text:
                yield text
            break
        else:
            if pos > 0:
                yield text[:pos]
            text = text[pos + 1:]
            pos = text.find('\x03')
            ref_text = text[:pos]
            text = text[pos + 1:]
            ref, _, name = ref_text.partition('\x02')
            yield ref, name
