plugins/include/regex.inc
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/plugins/include/regex.inc	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,141 +0,0 @@
     1.4 -#if defined _regex_included
     1.5 -  #endinput
     1.6 -#endif
     1.7 -#define _regex_included
     1.8 -
     1.9 -/**
    1.10 - * @section 	Flags for compiling regex expressions.  These come directly from the 
    1.11 - * pcre library and can be used in MatchRegex and CompileRegex.
    1.12 - */
    1.13 -#define PCRE_CASELESS           0x00000001 /* Ignore Case */
    1.14 -#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.15 -#define PCRE_DOTALL             0x00000004 /* Single line (affects . so that it matches any character, even new line characters). */
    1.16 -#define PCRE_EXTENDED           0x00000008 /* Pattern extension (ignore whitespace and # comments). */
    1.17 -#define PCRE_UNGREEDY           0x00000200 /* Invert greediness of quantifiers */
    1.18 -#define PCRE_UTF8               0x00000800 /* Use UTF-8 Chars */
    1.19 -#define PCRE_NO_UTF8_CHECK      0x00002000 /* Do not check the pattern for UTF-8 validity (only relevant if PCRE_UTF8 is set) */
    1.20 -
    1.21 -
    1.22 -/**
    1.23 - * Regex expression error codes.
    1.24 - */
    1.25 -enum RegexError
    1.26 -{
    1.27 -	REGEX_ERROR_NONE = 0,				/* No error */
    1.28 -	REGEX_ERROR_NOMATCH = -1,			/* No match was found */
    1.29 -	REGEX_ERROR_NULL = -2,
    1.30 -	REGEX_ERROR_BADOPTION = -3,
    1.31 -	REGEX_ERROR_BADMAGIC = -4,
    1.32 -	REGEX_ERROR_UNKNOWN_OPCODE = -5,
    1.33 -	REGEX_ERROR_NOMEMORY = -6,
    1.34 -	REGEX_ERROR_NOSUBSTRING = -7,
    1.35 -	REGEX_ERROR_MATCHLIMIT = -8,
    1.36 -	REGEX_ERROR_CALLOUT = -9,  			/* Never used by PCRE itself */
    1.37 -	REGEX_ERROR_BADUTF8 = -10,
    1.38 -	REGEX_ERROR_BADUTF8_OFFSET = -11,
    1.39 -	REGEX_ERROR_PARTIAL = -12,
    1.40 -	REGEX_ERROR_BADPARTIAL = -13,
    1.41 -	REGEX_ERROR_INTERNAL = -14,
    1.42 -	REGEX_ERROR_BADCOUNT = -15,
    1.43 -	REGEX_ERROR_DFA_UITEM = -16,
    1.44 -	REGEX_ERROR_DFA_UCOND = -17,
    1.45 -	REGEX_ERROR_DFA_UMLIMIT = -18,
    1.46 -	REGEX_ERROR_DFA_WSSIZE = -19,
    1.47 -	REGEX_ERROR_DFA_RECURSE = -20,
    1.48 -	REGEX_ERROR_RECURSIONLIMIT = -21,
    1.49 -	REGEX_ERROR_NULLWSLIMIT = -22,  	/* No longer actually used */
    1.50 -	REGEX_ERROR_BADNEWLINE = -23
    1.51 -}
    1.52 -
    1.53 -/**
    1.54 - * Precompile a regular expression.  Use this if you intend on using the 
    1.55 - * same expression multiple times.  Pass the regex handle returned here to
    1.56 - * MatchRegex to check for matches.
    1.57 - *
    1.58 - * @param pattern		The regular expression pattern.
    1.59 - * @param flags			General flags for the regular expression.
    1.60 - * @param error			Error message encountered, if applicable.
    1.61 - * @param maxLen		Maximum string length of the error buffer.
    1.62 - * @param errcode		Regex type error code encountered, if applicable.
    1.63 - * @return				Valid regex handle on success, INVALID_HANDLE on failure.
    1.64 - */
    1.65 -native Handle:CompileRegex(const String:pattern[], flags = 0, String:error[]="", maxLen = 0, &RegexError:errcode = REGEX_ERROR_NONE);
    1.66 -
    1.67 -/**
    1.68 - * Matches a string against a pre-compiled regular expression pattern.
    1.69 - *
    1.70 - * @param str			The string to check.
    1.71 - * @param regex			Regex Handle from CompileRegex()
    1.72 - * @param ret			Error code, if applicable.
    1.73 - * @return				Number of substrings found or -1 on failure.
    1.74 - *
    1.75 - * @note				Use the regex handle passed to this function to extract
    1.76 - *						matches with GetRegexSubString().
    1.77 - */
    1.78 -native MatchRegex(Handle:regex, const String:str[], &RegexError:ret = REGEX_ERROR_NONE);
    1.79 -
    1.80 -/**
    1.81 - * Returns a matched substring from a regex handle.
    1.82 - * Substring ids start at 0 and end at substrings-1, where substrings is the number returned 
    1.83 - * by MatchRegex
    1.84 - *
    1.85 - * @param regex			The regex handle to extract data from.
    1.86 - * @param str_id		The index of the expression to get - starts at 0, and ends at substrings - 1.
    1.87 - * @param buffer		The buffer to set to the matching substring.
    1.88 - * @param maxLen		The maximum string length of the buffer.
    1.89 - * @return				True if a substring was found, False on fail/error
    1.90 - */
    1.91 -native bool:GetRegexSubString(Handle:regex, str_id, String:buffer[], maxlen);
    1.92 -
    1.93 -/**
    1.94 - * Matches a string against a regular expression pattern.
    1.95 - *
    1.96 - * @note				If you intend on using the same regular expression pattern
    1.97 - *						multiple times, consider using CompileRegex and MatchRegex 
    1.98 - *						instead of making this function reparse the expression each time.
    1.99 - *
   1.100 - * @param str			The string to check.
   1.101 - * @param pattern		The regular expression pattern.
   1.102 - * @param flags			General flags for the regular expression.
   1.103 - * @param error			Error message, if applicable.
   1.104 - * @param maxLen		Maximum length of the error buffer.
   1.105 - * @return				Number of substrings found or -1 on failure.
   1.106 - */
   1.107 -stock SimpleRegexMatch(const String:str[], const String:pattern[], flags = 0, String:error[]="", maxLen = 0)
   1.108 -{
   1.109 -	new Handle:regex = CompileRegex(pattern, flags, error, maxLen);
   1.110 -	
   1.111 -	if (regex == INVALID_HANDLE)
   1.112 -	{
   1.113 -		return -1;	
   1.114 -	}
   1.115 -	
   1.116 -	new substrings = MatchRegex(regex, str);
   1.117 -	
   1.118 -	CloseHandle(regex);
   1.119 -	
   1.120 -	return substrings;	
   1.121 -}
   1.122 -
   1.123 -/**
   1.124 - * @endsection
   1.125 - */
   1.126 -
   1.127 -/**
   1.128 - * Do not edit below this line!
   1.129 - */
   1.130 -public Extension:__ext_regex = 
   1.131 -{
   1.132 -	name = "Regex Extension",
   1.133 -	file = "regex.ext",
   1.134 -#if defined AUTOLOAD_EXTENSIONS
   1.135 -	autoload = 1,
   1.136 -#else
   1.137 -	autoload = 0,
   1.138 -#endif
   1.139 -#if defined REQUIRE_EXTENSIONS
   1.140 -	required = 1,
   1.141 -#else
   1.142 -	required = 0,
   1.143 -#endif
   1.144 -};