Skip to content

Parsing strings from binary data #377

Answered by mbrandonw
ZevEisenberg asked this question in Q&A
Discussion options

You must be logged in to vote

All of the parsers that come with the library are super generic and can work on almost any kind of collection (usually where C.SubSequence == C, e.g. Substring, UTF8View, etc.). And Data is such a collection, though ArraySlice<UInt8> would probably be a little more efficient to deal with.

And so when you form a parser like this:

PrefixThrough(Data("<<".utf8))

…that represents consuming all of the bytes up to and including the first occurrence of the subsequence of "<<" bytes in the input. And the PrefixUpTo parser does something similar, except it does not consume the delimiter bytes.

So, in your simplified example, you might want something like this:

import Testing
@Test func parser() th…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mbrandonw
Comment options

Answer selected by ZevEisenberg
@ZevEisenberg
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants