AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Test if a string matches a wildcard? (https://forums.alliedmods.net/showthread.php?t=342829)

TinyDeskEngineer 05-19-2023 18:59

Test if a string matches a wildcard?
 
I want to make a plugin which will do something when the server finishes loading a map, and I want to allow for users to set a whitelist/blacklist for maps for which the plugin will take effect on. For simplicity, I want these lists to support wildcards, so for example, ctf_* would match all Capture the Flag maps in TF2, and cs_* would match all Hostage Rescue maps in Counter-Strike games. et cetera. I couldn't find anything about wildcards on the Scripting API Reference, and all of the things I could find on these forums about wildcards seem to be unrelated to what I'm trying to do here.

sorallll 05-19-2023 19:41

Re: Test if a string matches a wildcard?
 
regex.inc

Ilusion9 05-20-2023 06:33

Re: Test if a string matches a wildcard?
 
PHP Code:

bool StrEqual_Ex(const char[] str1, const char[] str2bool caseSensitive)
{
    
bool isPattern;
    
int len1 strlen(str1);
    
int len2 strlen(str2);
    
    if (
len1 && str1[len1 1] == '*')
    {
        
isPattern true;
        
len1--;
    }
    
    if (
len2 && str2[len2 1] == '*')
    {
        
isPattern true;
        
len2--;
    }
    
    if (
isPattern)
    {
        
int len len1 len2 len2 len1;
        return 
strncmp(str1str2lencaseSensitive) == 0;
    }
    
    return 
StrEqual(str1str2caseSensitive);




All times are GMT -4. The time now is 02:39.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.