tiny-regex-c icon indicating copy to clipboard operation
tiny-regex-c copied to clipboard

Support for multiple patterns

Open skyformat99 opened this issue 5 years ago • 8 comments

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);

skyformat99 avatar Aug 14 '20 03:08 skyformat99

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?

Nable80 avatar Aug 14 '20 03:08 Nable80

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

skyformat99 avatar Aug 14 '20 05:08 skyformat99

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.

Nable80 avatar Aug 14 '20 06:08 Nable80

thanks, All fixed, ^_^

skyformat99 avatar Aug 14 '20 07:08 skyformat99

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 avatar Aug 14 '20 14:08 Nable80

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

Nable80 avatar Aug 21 '20 13:08 Nable80

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

marler8997 avatar Mar 05 '21 20:03 marler8997

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

good

skyformat99 avatar Mar 06 '21 15:03 skyformat99