Closed ryanb closed 11 months ago
I think chompUntil will work, it just returns a List U8 instead of a string, because it is operating on raw utf-8 bytes and chomping in a very primitive way.
In Roc a Str is guaranteed to always be valid utf-8, and we know that utf-8 is a variable width encoding.
So, if you map the returned value with Str.fromUtf8 and then maybe also Result.withDefault if you are sure you are working with ASCII which is encoded as a single utf-8 byte, this will get you back to a Str.
In future once roc-lang/unicode gets a bit more mature we should be ok to write a parser that operates on unicode CodePoints which are U32 and then it should be possible to implement anyString I think, but it will probably do strange things with emoji and flags.
@lukewilliamboswell thanks for the detailed answer. Sounds like chompUntil
will work for this. Would you consider adding anyStringUntil
which does the conversion back to string for convenience? Alternatively maybe add a string conversion example to the docs of chompUntil
?
I think an example and some explanation for the documentation would be best. Do you have a working example I can use?
Would you be interested in contributing a PR with this addition to the docs?
Thank you for raising this issue. 😀
@lukewilliamboswell sounds good, I'll try to submit a PR when I get some time.
Is it possible to match an arbitrary string in a non greedy way? I tried
anyString
however it appears to be greedy. Here's some code.It results in the error "expected string
:
but found ``." so I assume it's greedy.I also tried
apply (chompUntil ':')
but I don't think it generates what I want.Thanks for this awesome library by the way. Let me know if there's a better place to put questions like this.