Skip to content

Commit

Permalink
optimize regular expression component
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Oct 10, 2023
1 parent 1d58108 commit 1aa7d79
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 118 deletions.
15 changes: 11 additions & 4 deletions docs/Melon Developer Guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1541,10 +1541,10 @@ Their definitions can be found in melon/include/mln_types.h.
own component.
Providing this feature is trying to make the capability of parsing HTTP URI better.
There are only two functions here.
a) int mln_reg_match(mln_string_t *exp, mln_string_t *text, mln_reg_match_t **head, mln_reg_match_t **tail);
a) int mln_reg_match(mln_string_t *exp, mln_string_t *text, mln_reg_match_result_t *matches);
'exp' is the regular expression that user provided.
'text' is the string that will be matched by 'exp'.
'head' and 'tail' are the chain to store matched string. If you don't need matched result, just set them NULL.
'matches' is an array to store matched pieces.
Return value:
0 - no matched result
>0 - the number of matched result
Expand All @@ -1554,8 +1554,15 @@ Their definitions can be found in melon/include/mln_types.h.
This function will return a non-zero if 'text' is completely matched by 'exp'. Otherwise, zero will be
returned.

c) mln_reg_match_result_free(mln_reg_match_t *results);
Free the result chain generated by 'mln_reg_match'.
c) mln_reg_match_result_new(prealloc);
Create a new matched result object.
'prealloc' is the pre-allocated array elements.

d) mln_reg_match_result_free(res);
Free the matched results.

e) mln_reg_match_result_get(res);
Get the array pointer of matched results.

Melon support these symbols below,
a) *
Expand Down
26 changes: 18 additions & 8 deletions include/mln_regexp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#define __MLN_REGEXP_H

#include "mln_string.h"
#include "mln_array.h"

typedef mln_array_t mln_reg_match_result_t;

#define M_REGEXP_MASK_SQUARE ((unsigned int)0x00800000)
#define M_REGEXP_MASK_OR ((unsigned int)0x01000000)
Expand All @@ -33,15 +36,22 @@
#define M_REGEXP_SUB 173
#define M_REGEXP_OR 174

typedef struct mln_reg_match_s {
mln_string_t data;
struct mln_reg_match_s *prev;
struct mln_reg_match_s *next;
} mln_reg_match_t;

extern int mln_reg_match(mln_string_t *exp, mln_string_t *text, mln_reg_match_t **head, mln_reg_match_t **tail);
extern int mln_reg_equal(mln_string_t *exp, mln_string_t *text);
extern void mln_reg_match_result_free(mln_reg_match_t *results);
#define mln_reg_match_result_new(prealloc) ({\
struct mln_array_attr attr;\
attr.pool = NULL;\
attr.pool_alloc = NULL;\
attr.pool_free = NULL;\
attr.free = NULL;\
attr.size = sizeof(mln_string_t);\
attr.nalloc = (prealloc);\
mln_array_new(&attr);\
})
#define mln_reg_match_result_free(res) mln_array_free(res)
#define mln_reg_match_result_get(res) (mln_string_t *)mln_array_elts(res)

extern int mln_reg_match(mln_string_t *exp, mln_string_t *text, mln_reg_match_result_t *matches) __NONNULL3(1,2,3);
extern int mln_reg_equal(mln_string_t *exp, mln_string_t *text) __NONNULL2(1,2);

#endif

Loading

0 comments on commit 1aa7d79

Please sign in to comment.