Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F126909
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/util/regex.cpp b/util/regex.cpp
index 33aa6706..5fc903d0 100644
--- a/util/regex.cpp
+++ b/util/regex.cpp
@@ -1,17 +1,36 @@
#include <string>
/* gnu/posix's regex header */
#include <regex.h>
/* our regex header */
#include "regex.h"
using namespace std;
/* http://www.gnu.org/s/libc/manual/html_node/Regular-Expressions.html */
bool Util::matchRegex(const string & str, const string & pattern){
regex_t regex;
if (regcomp(®ex, pattern.c_str(), 0) != 0){
return false;
}
bool matched = regexec(®ex, str.c_str(), 0, NULL, 0) == 0;
+ regfree(®ex);
return matched;
}
+
+string Util::captureRegex(const string & str, const string & pattern, int capture){
+ regex_t regex;
+ regmatch_t matches[20];
+ if (regcomp(®ex, pattern.c_str(), 0) != 0){
+ return false;
+ }
+ bool matched = regexec(®ex, str.c_str(), 20, matches, 0) == 0;
+ regfree(®ex);
+ if (matched){
+ if (matches[capture+1].rm_so != -1){
+ int start = matches[capture+1].rm_so;
+ int end = matches[capture+1].rm_eo;
+ return str.substr(start, end);
+ }
+ }
+ return "";
+}
diff --git a/util/regex.h b/util/regex.h
index ee01e950..5e8801fc 100644
--- a/util/regex.h
+++ b/util/regex.h
@@ -1,10 +1,11 @@
#ifndef _paintown_regex_h
#define _paintown_regex_h
#include <string>
namespace Util{
bool matchRegex(const std::string & str, const std::string & regex);
+ std::string captureRegex(const std::string & str, const std::string & regex, int capture);
}
#endif
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Jun 11, 1:32 PM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69265
Default Alt Text
(1 KB)
Attached To
Mode
R75 R-Tech1
Attached
Detach File
Event Timeline