Skip to content

Commit

Permalink
match_
Browse files Browse the repository at this point in the history
  • Loading branch information
omicronrex committed Nov 26, 2024
1 parent 98d76ce commit 8b361b7
Show file tree
Hide file tree
Showing 2 changed files with 300 additions and 1 deletion.
139 changes: 138 additions & 1 deletion gm82core.gej
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"folder": "gm82",
"version": "1.6",
"author": "renex, Floogle, Lovey01, cam900, Adamcake, YellowAfterlife, Verve",
"date": "20/11/2024",
"date": "26/11/2024",
"license": "Free to use, also for commercial games.",
"description": "Part of the standard Game Maker 8.2 distribution. This extension package contains a number of helper functions that are commonly used, and also geometry functions introduced in GM:Studio. This extension is also required for using the other GM 8.2 extensions, Sound and Joystick.",
"helpfile": "",
Expand Down Expand Up @@ -2818,6 +2818,143 @@
}
],
"constants": []
},
{
"filename": "match.gml",
"origname": "C:\\Users\\rene\\Desktop\\github\\gm82core\\source\\match.gml",
"kind": 2,
"init": "",
"final": "",
"functions": [
{
"name": "match_any",
"extname": "",
"calltype": 2,
"helpline": "match_any(substr,str)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
},
{
"name": "match_exact",
"extname": "",
"calltype": 2,
"helpline": "match_exact(pattern,str)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
},
{
"name": "match_found",
"extname": "",
"calltype": 2,
"helpline": "match_found([...])",
"hidden": false,
"argtypes": null,
"returntype": 2
},
{
"name": "match_not_any",
"extname": "",
"calltype": 2,
"helpline": "match_not_any(pattern,str)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
},
{
"name": "match_not_exact",
"extname": "",
"calltype": 2,
"helpline": "match_not_exact(pattern,str)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
},
{
"name": "match_not_some",
"extname": "",
"calltype": 2,
"helpline": "match_not_some(pattern,str)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
},
{
"name": "match_some",
"extname": "",
"calltype": 2,
"helpline": "match_some(substr,str)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
}
],
"constants": [
{
"name": "match_lower",
"value": "\"abcdefghijklmnopqrstuvwxyz\"",
"hidden": false
},
{
"name": "match_upper",
"value": "\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"",
"hidden": false
},
{
"name": "match_letters",
"value": "match_lower+match_upper",
"hidden": false
},
{
"name": "match_digits",
"value": "\"0123456789\"",
"hidden": false
},
{
"name": "match_alphanum",
"value": "match_letters+match_digits",
"hidden": false
},
{
"name": "match_identifier",
"value": "match_alphanum+\"_\"",
"hidden": false
},
{
"name": "match_identifier_start",
"value": "match_letters+\"_\"",
"hidden": false
},
{
"name": "match_whitespace",
"value": "chr(9)+chr(10)+chr(13)+\" \"",
"hidden": false
},
{
"name": "match_quotes",
"value": "\"'\"+'\"'",
"hidden": false
}
]
}
]
}
162 changes: 162 additions & 0 deletions source/match.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#define match_some
///match_some(pattern,str)
//pattern: string to match
//str: string to search in
//returns: trimmed string if pattern matches, or empty if failure
//Finds any of pattern characters in str. Fails on empty or no matches.

globalvar __gm82core_match_result;

var substr; substr=argument0;
var str; str=argument1;

//win condition
__gm82core_match_result=false
if (str=="") return ""

__gm82core_match_result=true

var len; len=string_length(str)

p=len
while (string_pos(string_char_at(str,p),substr) && p) p-=1
if (p<len) return string_copy(str,1,p)

__gm82core_match_result=false return ""


#define match_any
///match_any(pattern,str)
//pattern: string to match
//str: string to search in
//returns: trimmed string if pattern matches, or input if failure
//Finds any of pattern characters in str. Does not fail.

globalvar __gm82core_match_result;

var substr; substr=argument0;
var str; str=argument1;

//win condition
if (str=="") return ""

__gm82core_match_result=true

var p;p=string_length(str)
while (string_pos(string_char_at(str,p),substr) && p) p-=1
return string_copy(str,1,p)


#define match_not_any
///match_not_any(pattern,str)
//pattern: string to match
//str: string to search in
//returns: trimmed string if pattern matches, or input if failure
//Trims any characters in str that aren't in pattern. Does not fail.

globalvar __gm82core_match_result;

var substr; substr=argument0;
var str; str=argument1;

//win condition
if (str=="") return ""

__gm82core_match_result=true

var p;p=string_length(str)
while (!string_pos(string_char_at(str,p),substr) && p) p-=1
return string_copy(str,1,p)


#define match_not_some
///match_not_some(pattern,str)
//pattern: string to match
//str: string to search in
//returns: input if success, or empty if failure
//Finds any of pattern characters in str. Fails on any matches.

globalvar __gm82core_match_result;

var substr; substr=argument0;
var str; str=argument1;

//win condition
if (str=="") return ""

__gm82core_match_result=true

var len; len=string_length(str)

p=len
while (!string_pos(string_char_at(str,p),substr) && p) p-=1
if (p<len) return str

__gm82core_match_result=false return ""


#define match_exact
///match_exact(pattern,str)
//pattern: string to match
//str: string to search in
//returns: trimmed string if pattern matches, or empty if failure
//Matches the exact pattern at the end of str. Fails on empty or no match.

globalvar __gm82core_match_result;

var substr; substr=argument0;
var str; str=argument1;

//win condition
__gm82core_match_result=false
if (str=="") return ""

__gm82core_match_result=true

var len,sublen;

len=string_length(str)
sublen=string_length(substr)

if (string_copy(str,len-sublen+1,sublen)==substr)
return string_delete(str,len-sublen+1,sublen)

__gm82core_match_result=false return ""


#define match_not_exact
///match_not_exact(pattern,str)
//pattern: string to match
//str: string to search in
//returns: input if pattern matches, or empty if failure
//Fails if the pattern matches the end of str. Otherwise returns str.

globalvar __gm82core_match_result;

var substr; substr=argument0;
var str; str=argument1;

//win condition
if (str=="") return ""

__gm82core_match_result=true

var len,sublen;

len=string_length(str)
sublen=string_length(substr)

if (string_copy(str,len-sublen+1,sublen)!=substr) {
return str
}

__gm82core_match_result=false return ""


#define match_found
///match_found([...])
//returns whether the match functions succeeded.
globalvar __gm82core_match_result;
return __gm82core_match_result
//
//

0 comments on commit 8b361b7

Please sign in to comment.