Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse settings array instead of compiling them #449

Merged
merged 1 commit into from
Aug 1, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions addons/settings/fnc_parse.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ Author:
#define ASCII_ARRAY_OPEN (toArray "[" select 0)
#define ASCII_ARRAY_CLOSE (toArray "]" select 0)

private _fnc_parseArray = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function takes a string as input, so _fnc_parseString?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a stringified array. "[<...>]". parseNumber for example also takes and not

parseNumber "1"
-> 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

params [["_array", "", [""]]];
_array = _array call CBA_fnc_trim;

if ((_array select [0,1]) isEqualTo "[" && {(_array select [count _array - 1]) isEqualTo "]"}) then {
_array = (_array select [1, count _array - 2]) splitString ",";

// parse numbers and strings
_array = _array apply {
_x = _x call CBA_fnc_trim;

if ((_x select [0,1]) isEqualTo """") then {
_x select [1, count _x - 2]
} else {
parseNumber _x;
};
};

_array
} else {
[]
};
};

params [["_info", "", [""]]];

private _result = [];
Expand Down Expand Up @@ -66,9 +90,7 @@ private _result = [];
};
//--- array
case (_value0 == ASCII_ARRAY_OPEN && {_valueE == ASCII_ARRAY_CLOSE}): {
// prevent abusing for SQF injection, by clearing white space -> no command syntax possible
_value = (_value splitString toString WHITE_SPACE) joinString "";
call compile _value
_value call _fnc_parseArray
};
default {nil};
};
Expand Down