zeek / spicy

C++ parser generator for dissecting protocols & files.
https://docs.zeek.org/projects/spicy
Other
246 stars 35 forks source link

Add some easy string helpers #1828

Closed evantypanski closed 1 month ago

evantypanski commented 1 month ago

This may or may not be enough for #1807 - but I'll let others decide that

This just adds a few easy methods for string that already had implementations for bytes (or, even, within the string namespace). Those are:

There are a couple of points worth noting:

1) The implementation for split1 is a little inconsistent (and split, but there are notes for that in code). I didn't want to change behavior for already defined functions here, so I just updated the docs to be more clear in my opinion. The main point is calling split1 with an empty string "" will immediately split, then put the whole string in the second value of the tuple. That may be entirely expected, but it's a little unintuitive at first 2) This doesn't implement find which was called out in the issue. That's just because it relies on the Bytes iterator and I wanted something in with the easy ones first. It may be just as easy, but this is enough for an initial bit :)

So from here we could just go down the list of bytes operators and try to bring them all into string - but would that be worthwhile? Is this enough? I have no idea because I don't know the relative utility

evantypanski commented 1 month ago

I went through everything, but I kept the default param stuff unresolved since I'm not completely convinced I took the right path there, let me know what you think. Enough should be in the commit message and initial comment, tl;dr is that I made the empty string default to the no-separator-provided behavior, I think that fixes the edge case of an empty string and simplifies

note: default param for split was dropped in favor of the optional one for merge