Skip to content

Instantly share code, notes, and snippets.

@alco
Created February 20, 2012 14:39
Show Gist options
  • Save alco/1869503 to your computer and use it in GitHub Desktop.
Save alco/1869503 to your computer and use it in GitHub Desktop.
A presumably simple abstraction over regex engines
#include "regex.h"
using namespace boost::xpressive;
struct regex_t {
sregex pattern;
};
regex_ref regex_compile(const char *pattern)
{
regex_ref re = new regex_t;
re->pattern = sregex::compile(pattern);
return re;
}
void regex_free(regex_ref pattern)
{
if (pattern)
delete pattern;
}
int regex_matches(regex_ref re, const char *string)
{
return regex_match(std::string(string), re->pattern);
}
typedef struct regex_t* regex_ref;
regex_ref regex_compile(const char *pattern);
void regex_free(regex_ref pattern);
int regex_matches(regex_ref pattern, const char *string);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment