Created
February 20, 2012 14:39
-
-
Save alco/1869503 to your computer and use it in GitHub Desktop.
A presumably simple abstraction over regex engines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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