Skip to content

Instantly share code, notes, and snippets.

@TheByKotik
Created February 11, 2020 03:30
Show Gist options
  • Save TheByKotik/bb26b99d780e5f3adde6870490afa075 to your computer and use it in GitHub Desktop.
Save TheByKotik/bb26b99d780e5f3adde6870490afa075 to your computer and use it in GitHub Desktop.
#pragma newdecls required
#pragma semicolon 1
#include <sourcemod>
#include <regex>
public void OnPluginStart()
{
RegServerCmd( "sm_test", TEST );
}
Action TEST (int args)
{
char szBuf[128];
RegexError err;
Regex r = CompileRegex( "[a]", 0, szBuf, sizeof szBuf, err );
if ( szBuf[0] || err ) { PrintToServer( "%s | %i", szBuf, err ); }
if ( MatchRegex( r, "bbbbb", _, 0 ) != 0 ) { PrintToServer( "Error on 0" ); }
if ( MatchRegex( r, "abbbb", _, 0 ) != 1 ) { PrintToServer( "Error on 1" ); }
if ( MatchRegex( r, "aabbb", _, 1 ) != 1 ) { PrintToServer( "Error on 2" ); }
if ( MatchRegex( r, "aaabb", _, 2 ) != 1 ) { PrintToServer( "Error on 3" ); }
if ( MatchRegex( r, "aaaab", _, 3 ) != 1 ) { PrintToServer( "Error on 4" ); }
if ( MatchRegex( r, "aaaaa", _, 4 ) != 1 ) { PrintToServer( "Error on 5" ); }
if ( MatchRegex( r, "baaaa", _, 0 ) != 1 ) { PrintToServer( "Error on 6" ); }
if ( MatchRegex( r, "bbaaa", _, 0 ) != 1 ) { PrintToServer( "Error on 7" ); }
if ( MatchRegex( r, "bbbaa", _, 0 ) != 1 ) { PrintToServer( "Error on 8" ); }
if ( MatchRegex( r, "bbbba", _, 0 ) != 1 ) { PrintToServer( "Error on 9" ); }
if ( r.MatchAll( "bbbbb" ) != 0 ) { PrintToServer( "Error on 10" ); }
if ( r.MatchAll( "abbbb" ) != 1 ) { PrintToServer( "Error on 11" ); }
if ( r.MatchAll( "aabbb" ) != 2 ) { PrintToServer( "Error on 12" ); }
if ( r.MatchAll( "aaabb" ) != 3 ) { PrintToServer( "Error on 13" ); }
if ( r.MatchAll( "aaaab" ) != 4 ) { PrintToServer( "Error on 14" ); }
if ( r.MatchAll( "aaaaa" ) != 5 ) { PrintToServer( "Error on 15" ); }
if ( r.MatchAll( "baaaa" ) != 4 ) { PrintToServer( "Error on 16" ); }
if ( r.MatchAll( "bbaaa" ) != 3 ) { PrintToServer( "Error on 17" ); }
if ( r.MatchAll( "bbbaa" ) != 2 ) { PrintToServer( "Error on 18" ); }
if ( r.MatchAll( "bbbba" ) != 1 ) { PrintToServer( "Error on 19" ); }
int i;
for ( ; i < 100000; ++i ) { r.MatchAll( "aaaaa" ); }
CloseHandle( r );
for ( i = 0 ; i < 100000; ++i ) {
r = CompileRegex( "[a]" );
CloseHandle( r ); }
PrintToServer( "End Regex Test." );
return Plugin_Handled;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment