From 58747094071b9173b33ea7a29de81d5d0a157751 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 27 Oct 2014 22:05:37 -0700 Subject: [PATCH] Add transitional syntax support for regex.inc. --- plugins/include/regex.inc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/plugins/include/regex.inc b/plugins/include/regex.inc index d045eae8..03a1bd16 100644 --- a/plugins/include/regex.inc +++ b/plugins/include/regex.inc @@ -104,7 +104,7 @@ enum RegexError * @param errcode Regex type error code encountered, if applicable. * @return Valid regex handle on success, INVALID_HANDLE on failure. */ -native Handle:CompileRegex(const String:pattern[], flags = 0, String:error[]="", maxLen = 0, &RegexError:errcode = REGEX_ERROR_NONE); +native Regex CompileRegex(const char[] pattern, int flags = 0, char[] error="", int maxLen = 0, RegexError &errcode = REGEX_ERROR_NONE); /** * Matches a string against a pre-compiled regular expression pattern. @@ -117,7 +117,7 @@ native Handle:CompileRegex(const String:pattern[], flags = 0, String:error[]="", * @note Use the regex handle passed to this function to extract * matches with GetRegexSubString(). */ -native MatchRegex(Handle:regex, const String:str[], &RegexError:ret = REGEX_ERROR_NONE); +native int MatchRegex(Handle regex, const char[] str, RegexError &ret = REGEX_ERROR_NONE); /** * Returns a matched substring from a regex handle. @@ -130,7 +130,14 @@ native MatchRegex(Handle:regex, const String:str[], &RegexError:ret = REGEX_ERRO * @param maxlen The maximum string length of the buffer. * @return True if a substring was found, False on fail/error */ -native bool:GetRegexSubString(Handle:regex, str_id, String:buffer[], maxlen); +native bool GetRegexSubString(Handle regex, int str_id, char[] buffer, int maxlen); + +methodmap Regex < Handle +{ + public Regex() = CompileRegex; + public Match() = MatchRegex; + public GetSubString() = GetRegexSubString; +}; /** * Matches a string against a regular expression pattern. @@ -146,19 +153,15 @@ native bool:GetRegexSubString(Handle:regex, str_id, String:buffer[], maxlen); * @param maxLen Maximum length of the error buffer. * @return Number of substrings found or -1 on failure. */ -stock SimpleRegexMatch(const String:str[], const String:pattern[], flags = 0, String:error[]="", maxLen = 0) +stock int SimpleRegexMatch(const char[] str, const char[] pattern, int flags = 0, char[] error="", int maxLen = 0) { - new Handle:regex = CompileRegex(pattern, flags, error, maxLen); - - if (regex == INVALID_HANDLE) - { + Regex regex = Regex(pattern, flags, error, maxLen); + if (!regex) return -1; - } - - new substrings = MatchRegex(regex, str); - - CloseHandle(regex); + int substrings = regex.Match(str); + delete regex; + return substrings; }