kokke / tiny-regex-c

Small portable regex in C
The Unlicense
1.23k stars 175 forks source link

Support for multiple patterns #45

Open skyformat99 opened 4 years ago

skyformat99 commented 4 years ago

Support for multiple patterns

When multiple patterns are used simultaneously, the existing code will fail, the PR fix it. example:

int match_length; const char* string_to_search = "ahem.. 'hello world !' ..";

re_t p1 = re_compile("[Hh]ello [Ww]orld\s[!]?"); re_t p2 = re_compile("hello[0-9]"); re_t p3 = re_compile("fadsf");

int match_idx; match_idx = re_matchp(p1, string_to_search, &match_length); match_idx = re_matchp(p2, string_to_search, &match_length); match_idx = re_matchp(p3, string_to_search, &match_length);

re_freecompile(p1); re_freecompile(p2); re_freecompile(p3);

Nable80 commented 4 years ago

Hi! Thank you for your interest in this library! I have to say that your patch uses dynamic memory allocation (calloc/free), while this library is mostly targeted at embedded usage where it's important to avoid anything that isn't predictable at compilation time. It's explicitly mentioned in README: "No use of dynamic memory allocation (i.e. no calls to malloc / free)".

I think it's still possible to add optional support for dynamic allocation that is configured by preprocessor definitions (#if/#ifdef...#endif) but it definitely shouldn't break existing use-cases and default behavior. Do you agree with this idea?

skyformat99 commented 4 years ago

thanks, you are right. Added preprocessor definition (# if / # IFDEF...# endif).

Nable80 commented 4 years ago

Let's wait for some reply from the repo owner, I'm just a regular user here after all.

I'll try to add a code review for your changes anyway, just in hope anyone finds it useful.

skyformat99 commented 4 years ago

thanks, All fixed, ^_^

Nable80 commented 4 years ago

Btw, you can also squash commits and re-push to avoid unnecessary intermediate changes. Probably it's even possible to do it via Github UI, I'm not sure (command-line tools are good enough for me).

I should also say that it's better to wait for repo owner's reply, his opinion about some questionable parts may be different. I.e. you don't have to change things immediately after getting the first reply, sometimes it's better to wait for more comments and only then decide what to do next.

Nable80 commented 4 years ago

@kokke What do you think about merging this feature as an optional extension?

marler8997 commented 3 years ago

I think my PR might be an alternative to this: https://github.com/kokke/tiny-regex-c/pull/58

skyformat99 commented 3 years ago

I think my PR might be an alternative to this: #58

good