>gnome-regex

gnome-regex

Name

gnome-regex -- Regular expression cache implementation

Synopsis


#include <gnome.h>


struct      GnomeRegexCache;
GnomeRegexCache* gnome_regex_cache_new      (void);
void        gnome_regex_cache_destroy       (GnomeRegexCache *rxc);
void        gnome_regex_cache_set_size      (GnomeRegexCache *rxc,
                                             int new_size);
regex_t*    gnome_regex_cache_compile       (GnomeRegexCache *rxc,
                                             const char *pattern,
                                             int flags);

Description

Provides a cache for regular expressions. Applications first allocate a cache with gnome_regex_cache_new() and access the regular expressions through the gnome_regex_cache_compile() function (this will fetch the compiled value from the cache or re-compile it if required).

Details

struct GnomeRegexCache

typedef struct {
	int size;		/* Total number of cache slots.  */
	int next;		/* Next available slot.  */
	char **regexs;		/* Regular expression strings.  */
	regex_t *patterns;	/* Compiled expressions.  */
	/* FIXME: probably should cache compilation flags along with
	   regex and use those to determine caching.  For now we
	   assume that the flags never change.  Another option would
	   be to put the flag info into this structure and just not
	   let the user ever change it.  */
} GnomeRegexCache;


gnome_regex_cache_new ()

GnomeRegexCache* gnome_regex_cache_new      (void);

Creates a new regular expression cache object.

Returns : the new cache object.


gnome_regex_cache_destroy ()

void        gnome_regex_cache_destroy       (GnomeRegexCache *rxc);

Destroys a regular expression cache object.

rxc : A regular expression cache object


gnome_regex_cache_set_size ()

void        gnome_regex_cache_set_size      (GnomeRegexCache *rxc,
                                             int new_size);

Sets the maxiumum number of regular expressions the cache can hold. If this is less than the number of currently cached expressions, then the oldest expressions are deleted.

rxc : A regular expression cache object
new_size : new size of cache


gnome_regex_cache_compile ()

regex_t*    gnome_regex_cache_compile       (GnomeRegexCache *rxc,
                                             const char *pattern,
                                             int flags);

This compiles a regular expression. If the expression is cached, the previously computed value is returned. Otherwise, the expression is compiled, cached, and then returned.

rxc : A regular expression cache object
pattern : A string representing a regular expression
flags : Flags to pass to regcomp()
Returns : a compiled regular expression, or NULL on error.