1.1 --- a/plugins/include/regex.inc Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,173 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.8 - * =============================================================================
1.9 - *
1.10 - * This file is part of the SourceMod/SourcePawn SDK.
1.11 - *
1.12 - * This program is free software; you can redistribute it and/or modify it under
1.13 - * the terms of the GNU General Public License, version 3.0, as published by the
1.14 - * Free Software Foundation.
1.15 - *
1.16 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.17 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 - * details.
1.20 - *
1.21 - * You should have received a copy of the GNU General Public License along with
1.22 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.23 - *
1.24 - * As a special exception, AlliedModders LLC gives you permission to link the
1.25 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.26 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.27 - * by the Valve Corporation. You must obey the GNU General Public License in
1.28 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.29 - * this exception to all derivative works. AlliedModders LLC defines further
1.30 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.31 - * or <http://www.sourcemod.net/license.php>.
1.32 - *
1.33 - * Version: $Id$
1.34 - */
1.35 -
1.36 -#if defined _regex_included
1.37 - #endinput
1.38 -#endif
1.39 -#define _regex_included
1.40 -
1.41 -/**
1.42 - * @section Flags for compiling regex expressions. These come directly from the
1.43 - * pcre library and can be used in MatchRegex and CompileRegex.
1.44 - */
1.45 -#define PCRE_CASELESS 0x00000001 /* Ignore Case */
1.46 -#define PCRE_MULTILINE 0x00000002 /* Multilines (affects ^ and $ so that they match the start/end of a line rather than matching the start/end of the string). */
1.47 -#define PCRE_DOTALL 0x00000004 /* Single line (affects . so that it matches any character, even new line characters). */
1.48 -#define PCRE_EXTENDED 0x00000008 /* Pattern extension (ignore whitespace and # comments). */
1.49 -#define PCRE_UNGREEDY 0x00000200 /* Invert greediness of quantifiers */
1.50 -#define PCRE_UTF8 0x00000800 /* Use UTF-8 Chars */
1.51 -#define PCRE_NO_UTF8_CHECK 0x00002000 /* Do not check the pattern for UTF-8 validity (only relevant if PCRE_UTF8 is set) */
1.52 -
1.53 -
1.54 -/**
1.55 - * Regex expression error codes.
1.56 - */
1.57 -enum RegexError
1.58 -{
1.59 - REGEX_ERROR_NONE = 0, /* No error */
1.60 - REGEX_ERROR_NOMATCH = -1, /* No match was found */
1.61 - REGEX_ERROR_NULL = -2,
1.62 - REGEX_ERROR_BADOPTION = -3,
1.63 - REGEX_ERROR_BADMAGIC = -4,
1.64 - REGEX_ERROR_UNKNOWN_OPCODE = -5,
1.65 - REGEX_ERROR_NOMEMORY = -6,
1.66 - REGEX_ERROR_NOSUBSTRING = -7,
1.67 - REGEX_ERROR_MATCHLIMIT = -8,
1.68 - REGEX_ERROR_CALLOUT = -9, /* Never used by PCRE itself */
1.69 - REGEX_ERROR_BADUTF8 = -10,
1.70 - REGEX_ERROR_BADUTF8_OFFSET = -11,
1.71 - REGEX_ERROR_PARTIAL = -12,
1.72 - REGEX_ERROR_BADPARTIAL = -13,
1.73 - REGEX_ERROR_INTERNAL = -14,
1.74 - REGEX_ERROR_BADCOUNT = -15,
1.75 - REGEX_ERROR_DFA_UITEM = -16,
1.76 - REGEX_ERROR_DFA_UCOND = -17,
1.77 - REGEX_ERROR_DFA_UMLIMIT = -18,
1.78 - REGEX_ERROR_DFA_WSSIZE = -19,
1.79 - REGEX_ERROR_DFA_RECURSE = -20,
1.80 - REGEX_ERROR_RECURSIONLIMIT = -21,
1.81 - REGEX_ERROR_NULLWSLIMIT = -22, /* No longer actually used */
1.82 - REGEX_ERROR_BADNEWLINE = -23
1.83 -};
1.84 -
1.85 -/**
1.86 - * Precompile a regular expression. Use this if you intend on using the
1.87 - * same expression multiple times. Pass the regex handle returned here to
1.88 - * MatchRegex to check for matches.
1.89 - *
1.90 - * @param pattern The regular expression pattern.
1.91 - * @param flags General flags for the regular expression.
1.92 - * @param error Error message encountered, if applicable.
1.93 - * @param maxLen Maximum string length of the error buffer.
1.94 - * @param errcode Regex type error code encountered, if applicable.
1.95 - * @return Valid regex handle on success, INVALID_HANDLE on failure.
1.96 - */
1.97 -native Handle:CompileRegex(const String:pattern[], flags = 0, String:error[]="", maxLen = 0, &RegexError:errcode = REGEX_ERROR_NONE);
1.98 -
1.99 -/**
1.100 - * Matches a string against a pre-compiled regular expression pattern.
1.101 - *
1.102 - * @param str The string to check.
1.103 - * @param regex Regex Handle from CompileRegex()
1.104 - * @param ret Error code, if applicable.
1.105 - * @return Number of substrings found or -1 on failure.
1.106 - *
1.107 - * @note Use the regex handle passed to this function to extract
1.108 - * matches with GetRegexSubString().
1.109 - */
1.110 -native MatchRegex(Handle:regex, const String:str[], &RegexError:ret = REGEX_ERROR_NONE);
1.111 -
1.112 -/**
1.113 - * Returns a matched substring from a regex handle.
1.114 - * Substring ids start at 0 and end at substrings-1, where substrings is the number returned
1.115 - * by MatchRegex
1.116 - *
1.117 - * @param regex The regex handle to extract data from.
1.118 - * @param str_id The index of the expression to get - starts at 0, and ends at substrings - 1.
1.119 - * @param buffer The buffer to set to the matching substring.
1.120 - * @param maxLen The maximum string length of the buffer.
1.121 - * @return True if a substring was found, False on fail/error
1.122 - */
1.123 -native bool:GetRegexSubString(Handle:regex, str_id, String:buffer[], maxlen);
1.124 -
1.125 -/**
1.126 - * Matches a string against a regular expression pattern.
1.127 - *
1.128 - * @note If you intend on using the same regular expression pattern
1.129 - * multiple times, consider using CompileRegex and MatchRegex
1.130 - * instead of making this function reparse the expression each time.
1.131 - *
1.132 - * @param str The string to check.
1.133 - * @param pattern The regular expression pattern.
1.134 - * @param flags General flags for the regular expression.
1.135 - * @param error Error message, if applicable.
1.136 - * @param maxLen Maximum length of the error buffer.
1.137 - * @return Number of substrings found or -1 on failure.
1.138 - */
1.139 -stock SimpleRegexMatch(const String:str[], const String:pattern[], flags = 0, String:error[]="", maxLen = 0)
1.140 -{
1.141 - new Handle:regex = CompileRegex(pattern, flags, error, maxLen);
1.142 -
1.143 - if (regex == INVALID_HANDLE)
1.144 - {
1.145 - return -1;
1.146 - }
1.147 -
1.148 - new substrings = MatchRegex(regex, str);
1.149 -
1.150 - CloseHandle(regex);
1.151 -
1.152 - return substrings;
1.153 -}
1.154 -
1.155 -/**
1.156 - * @endsection
1.157 - */
1.158 -
1.159 -/**
1.160 - * Do not edit below this line!
1.161 - */
1.162 -public Extension:__ext_regex =
1.163 -{
1.164 - name = "Regex Extension",
1.165 - file = "regex.ext",
1.166 -#if defined AUTOLOAD_EXTENSIONS
1.167 - autoload = 1,
1.168 -#else
1.169 - autoload = 0,
1.170 -#endif
1.171 -#if defined REQUIRE_EXTENSIONS
1.172 - required = 1,
1.173 -#else
1.174 - required = 0,
1.175 -#endif
1.176 -};