inclusion of regular expression wrapper functions in glib.



One of the things which I have created for my own use are a number of
wrapper functions for the posix regular expression interface. One of the
reasons for this is that I find it very cumbersome to use the standard
interface when I want to quickly use a regular expression for string
matching or some other purpose. Therefore I wonder if there is work being
done on including a few functions such as g_regex_match_pred,
g_regex_match_whole, etc. (a few prototypes follow at end of message) in
upcoming versions of glib.

I would be happy to contribute my code for these functions, or possibly
create modified versions of them if someone has better suggestions as to
what the API should look like.

Nathan Bullock

Please note that I am NOT on the gtk-devel-list and therefore email me at
bullock cs ualberta ca 


PS. reasons for creating a regex API in glib:
 - can be cludgy to have to allocate and deallocate space for the match
      registers.
 - would create a standard regular expression syntax for glib applications
      (instead of everyone using a different syntax) I am currently using
      extended regular expression syntax.
 - reduce chance of memory leaks when it comes to allocating and
      deallocating match registers.


//#################################################################
// These function try to match the regular expression REGEX,
//   with the line LINE. They return 1 if successful, 0 if not,
//   and -1 if their was some sort of error.
//#################################################################

// This is just a predicate function.
s32bit
regex_match_pred   (const char* regex, const char* line);

// Besides telling us if REGEX matched LINE, it also tells us which
//   substring it matched, namely LINE[START] to LINE[END]. 
s32bit
regex_match_whole  (const char* regex, const char* line,
                    s32bit *start, s32bit *end);

// Besides telling us if REGEX matched LINE, it also tells us which
//   substring group 1 of REGEX matched, namely LINE[START] to LINE[END]. 
s32bit
regex_match_group1 (const char* regex, const char* line,
                    s32bit *start, s32bit *end);

// Besides telling us if REGEX matched LINE, it also tells us which
//   substring group x of REGEX matched, namely LINE[START] to LINE[END]. 
s32bit
regex_match_groupx (const char* regex, const char* line, s32bit group,
                    s32bit *start, s32bit *end);




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]