00001 #include "ckregex.h"
00002 #include <regex>
00003 #include <cstring>
00004 #include <cstdlib>
00005
00006 extern "C" char ** findFirstCaptures(const char * pattern, const char * input_str) {
00007 std::regex re(pattern);
00008 std::smatch match;
00009 std::string s(input_str);
00010 if (std::regex_search(s, match, re)) {
00011 const size_t match_size = match.size();
00012
00013 char ** result = (char **)malloc(match_size * sizeof(char *));
00014 result[match_size - 1] = NULL;
00015
00016
00017 for (int i = 1; i < match_size; ++i) {
00018 result[i-1] = strdup(match.str(i).c_str());
00019 }
00020
00021 return result;
00022 } else {
00023 return NULL;
00024 }
00025 }