Looking for advice on this: I am ingesting a seque...
# announcements
s
Looking for advice on this: I am ingesting a sequence of chars, I want to buffer them until I receive a particular xml end tag then flush the buffer. Is there a more efficient (while also easy) way to check for the existence of this tag at the end of the buffer? I think the trivial method is
endswith("</endtag>")
but this seems inefficient to run over the length of the buffer, especially if we get a char that can’t contribute to the terminal tag.
A state machine or something seems overkill but under the hood I think that’s the best way?
n
check if the char equals index n of the endtag, if yes, n++, else n=0 when n reaches length of end tag, you have a endtag
n
i think that you can write a
sequence
pretty easily that does this, no?
just keep yielding till you find the tag
that said, if its xml, you probably want to use a proper xml parser, unless this xml is so huge it has to be lazy
j
If you want more efficiency you can try algorithms like KMP or Boyer Moore
With XML in general, you are better off just using a pull parser.. There are plenty already out there.
☝️ 1