Raised This Month: $51 Target: $400
 12% 

Test if a string matches a wildcard?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TinyDeskEngineer
Junior Member
Join Date: May 2023
Location: Inside your walls
Old 05-19-2023 , 18:59   Test if a string matches a wildcard?
Reply With Quote #1

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.
TinyDeskEngineer is offline
sorallll
Senior Member
Join Date: Oct 2018
Old 05-19-2023 , 19:41   Re: Test if a string matches a wildcard?
Reply With Quote #2

regex.inc
sorallll is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 05-20-2023 , 06:33   Re: Test if a string matches a wildcard?
Reply With Quote #3

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);

__________________
Ilusion9 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:41.


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