Skip to content

Commit

Permalink
string_trim()
Browse files Browse the repository at this point in the history
  • Loading branch information
omicronrex committed Feb 28, 2024
1 parent dd18bae commit db0d404
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 25 deletions.
59 changes: 34 additions & 25 deletions 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": "07/02/2024",
"date": "28/02/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 @@ -2053,6 +2053,30 @@
],
"returntype": 2
},
{
"name": "string_copy_end",
"extname": "",
"calltype": 2,
"helpline": "string_copy_end(string,count)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
},
{
"name": "string_delete_end",
"extname": "",
"calltype": 2,
"helpline": "string_delete_end(string,count)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
},
{
"name": "string_ends_with",
"extname": "",
Expand Down Expand Up @@ -2123,6 +2147,15 @@
],
"returntype": 2
},
{
"name": "string_trim",
"extname": "",
"calltype": 2,
"helpline": "string_trim(string,[trim1,trim2...])",
"hidden": false,
"argtypes": null,
"returntype": 2
},
{
"name": "strong",
"extname": "str_cat",
Expand Down Expand Up @@ -2158,30 +2191,6 @@
"hidden": false,
"argtypes": null,
"returntype": 2
},
{
"name": "string_delete_end",
"extname": "",
"calltype": 2,
"helpline": "string_delete_end(string,count)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
},
{
"name": "string_copy_end",
"extname": "",
"calltype": 2,
"helpline": "string_copy_end(string,count)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
}
],
"constants": []
Expand Down
38 changes: 38 additions & 0 deletions source/strings.gml
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,43 @@
//returns: copy from provided string
return string_copy(argument0, max(string_length(argument0) - argument1 + 1, 1), argument1);
#define string_trim
///string_trim(string,[trim1,trim2...])
//string: string to process
//arguments: strings to trim out
//returns: trimmed string
//This function will remove occurrences of the trims from the edges of a string.
//If no extra arguments are specified, spaces are removed instead.
var __i,__p1,__p2,__str,__trim,__trimlen;
__str=argument[0]
__i=1
if (argument_count==1) {
__j=string_length(__str)
while (string_char_at(__str,__i)==" " && __i<__j) __i+=1
while (string_char_at(__str,__j)==" " && __j>0) __j-=1
return string_copy(__str,__i,__j-__i+1)
}
repeat (argument_count-1) {
__trim=argument[__i]
__trimlen=string_length(__trim)
while (string_copy(__str,1,__trimlen)==__trim) {
__str=string_delete(__str,1,__trimlen)
}
while (string_copy(__str,string_length(__str)+1-__trimlen,__trimlen)==__trim) {
__str=string_delete(__str,string_length(__str)+1-__trimlen,__trimlen)
}
__i+=1}
return __str
//
//

0 comments on commit db0d404

Please sign in to comment.