Skip to content

Commit

Permalink
ds_map_read_safe
Browse files Browse the repository at this point in the history
  • Loading branch information
omicronrex committed Nov 29, 2024
1 parent 2ba6d9a commit c1aec21
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
14 changes: 13 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": "26/11/2024",
"date": "29/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 @@ -1572,6 +1572,18 @@
"hidden": true,
"argtypes": null,
"returntype": 2
},
{
"name": "ds_map_read_safe",
"extname": "",
"calltype": 2,
"helpline": "ds_map_read_safe(map,str)",
"hidden": false,
"argtypes": [
2,
2
],
"returntype": 2
}
],
"constants": []
Expand Down
20 changes: 20 additions & 0 deletions source/data_structures.gml
Original file line number Diff line number Diff line change
Expand Up @@ -447,5 +447,25 @@

if (__gm82core_bag_check(argument0,"ds_bag_empty")) exit
return (ds_list_size(argument0)==1)


#define ds_map_read_safe
///ds_map_read_safe(map,str)
//map: empty ds_map
//str: string to read
//returns: success
//Cehcks if a string is supposedly a valid written dsmap before attempting to read it.
var str,i,l;

str=string(argument1)
l=string_length(str)
if (l mod 2) return 0

//check first and last 16 characters only for speed
for (i=1;i<=16;i+=1) if (!string_pos(string_char_at(str,i),"0123456789ABCDEF")) return 0
for (i=l;i>=l-16;i-=1) if (!string_pos(string_char_at(str,i),"0123456789ABCDEF")) return 0

ds_map_read(argument0,str)
return 1
//
//

0 comments on commit c1aec21

Please sign in to comment.