'Requires:
the_string --string of toc, with new lines
Returns:
the_string -- string minus bookmarks
bookmark_string -- bookmarks
Logic:'

def __parse_bookmark_for_toc(self, my_string):

    in_bookmark = 0
    bracket_count = 0
    book_start_string = ''
    book_end_string = ''
    book_type = 0
    toc_string = ''
    lines = my_string.split('\n')
    end_bracket_count = sys.maxint
    for line in lines:
        token_info = line[:16]
        if (token_info == 'ob<nu<open-brack'):
            bracket_count += 1
        if (token_info == 'cb<nu<clos-brack'):
            bracket_count -= 1
        if in_bookmark:
            if ((bracket_count == end_bracket_count) and (token_info == 'cb<nu<clos-brack')):
                in_bookmark = 0
                toc_string += ('%s\n' % line)
            elif (token_info == 'tx<nu<__________'):
                if (book_type == 'start'):
                    book_start_string += line[17:]
                elif (book_type == 'end'):
                    book_end_string += line[17:]
            else:
                toc_string += ('%s\n' % line)
        else:
            if ((token_info == 'cw<an<book-mk-st') or (token_info == 'cw<an<book-mk-en')):
                if (token_info == 'cw<an<book-mk-st'):
                    book_type = 'start'
                if (token_info == 'cw<an<book-mk-en'):
                    book_type = 'end'
                end_bracket_count = (bracket_count - 1)
                in_bookmark = 1
            toc_string += ('%s\n' % line)
    return (toc_string, book_start_string, book_end_string)
