From a22bc41cca4a0a33847a9b55b9e333c6e728c9f0 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 1 Jul 2023 13:15:39 +0200 Subject: [PATCH 1/3] Added multiline setting parsing support --- addons/settings/fnc_parse.sqf | 67 ++++++++++++++++------------------- 1 file changed, 30 insertions(+), 37 deletions(-) diff --git a/addons/settings/fnc_parse.sqf b/addons/settings/fnc_parse.sqf index 7f84d0af44..9c24437b97 100644 --- a/addons/settings/fnc_parse.sqf +++ b/addons/settings/fnc_parse.sqf @@ -13,65 +13,58 @@ Returns: Settings with values and priority states. Author: - commy2 + commy2, johnb43 ---------------------------------------------------------------------------- */ -// parses bool, number, string -private _fnc_parseAny = { - params ["_string"]; - - // Remove whitespace so parseSimpleArray can handle arrays. - // Means that strings inside arrays don't support white space chars, but w/e. - // No such setting exists atm anyway. - if (_string find """" != 0) then { - _string = _string splitString WHITESPACE joinString ""; - }; - - parseSimpleArray (["[", _string, "]"] joinString "") select 0 -}; - params [["_info", "", [""]], ["_validate", false, [false]], ["_source", "", [""]]]; -// remove whitespace at start and end of each line -private _result = []; +// Remove whitespace at start and end of each line, a line being define by the ";" at its end +private _parsed = []; { - _result pushBack (_x call CBA_fnc_trim); -} forEach (_info splitString NEWLINE); + _parsed pushBack (trim _x); +} forEach (_info splitString ";"); -{ - if (_x select [count _x - 1] != ";") then { - _result set [_forEachIndex, _x + ";"]; - }; -} forEach _result; +// Remove empty strings +_parsed = _parsed - [""]; -_info = (_result joinString NEWLINE) + NEWLINE; - -// separate statements (setting = value) -_result = []; +// Separate statements (setting = value) +private _result = []; +private _indexEqualSign = -1; +private _setting = ""; +private _priority = 0; +private _value = ""; +private _countForce = count "force"; +private _whitespaces = [toString [ASCII_NEWLINE], toString [ASCII_CARRIAGE_RETURN], toString [ASCII_TAB], toString [ASCII_SPACE]]; { - private _indexEqualSign = _x find "="; + _indexEqualSign = _x find "="; - private _setting = (_x select [0, _indexEqualSign]) call CBA_fnc_rightTrim; - private _priority = 0; + // Setting name is front of "=" + _setting = (_x select [0, _indexEqualSign]) trim [WHITESPACE, 2]; + _priority = 0; - if (_setting select [0, count "force"] == "force") then { - _setting = _setting select [count "force"] call CBA_fnc_leftTrim; + // Check if the first entry is force and not followed by an empty space + if (_setting select [0, _countForce] == "force" && {(_setting select [_countForce, 1]) in _whitespaces}) then { + _setting = (_setting select [_countForce]) trim [WHITESPACE, 1]; _priority = _priority + 1; }; - if (_setting select [0, count "force"] == "force") then { - _setting = _setting select [count "force"] call CBA_fnc_leftTrim; + // Check if the second entry is force and not followed by an empty space + if (_setting select [0, _countForce] == "force" && {(_setting select [_countForce, 1]) in _whitespaces}) then { + _setting = (_setting select [_countForce]) trim [WHITESPACE, 1]; _priority = _priority + 1; }; + // If setting is valid, get it's value if (_setting != "") then { - private _value = ((_x select [_indexEqualSign + 1]) call CBA_fnc_trim) call _fnc_parseAny; + // Remove whitespaces; Parse bool, number, string + _value = parseSimpleArray (["[", (_x select [_indexEqualSign + 1]) splitString WHITESPACE joinString "", "]"] joinString "") select 0; if !(_validate) then { _result pushBack [_setting, _value, _priority]; } else { + // Check if setting is valid if (isNil {[_setting, "default"] call FUNC(get)}) exitWith { ERROR_1("Setting %1 does not exist.",_setting); }; @@ -84,6 +77,6 @@ _result = []; _result pushBack [_setting, _value, _priority]; }; }; -} forEach ([_info, ";" + NEWLINE] call CBA_fnc_split); +} forEach _parsed; _result From 3f5ece00b831bb161bd338ffb8196b01100f9e28 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sun, 2 Jul 2023 15:28:48 +0200 Subject: [PATCH 2/3] Cleanup and fixes --- addons/settings/fnc_parse.sqf | 37 +++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/addons/settings/fnc_parse.sqf b/addons/settings/fnc_parse.sqf index 9c24437b97..c9c1de6edc 100644 --- a/addons/settings/fnc_parse.sqf +++ b/addons/settings/fnc_parse.sqf @@ -18,7 +18,19 @@ Author: params [["_info", "", [""]], ["_validate", false, [false]], ["_source", "", [""]]]; -// Remove whitespace at start and end of each line, a line being define by the ";" at its end +// Parses bools, numbers, strings +private _fnc_parseAny = { + params ["_string"]; + + // Remove whitespace so parseSimpleArray can handle arrays. + // Means that strings inside arrays don't support white space chars, but w/e. + // No such setting exists atm anyway. + _string = _string splitString _whitespace joinString ""; + + parseSimpleArray (["[", _string, "]"] joinString "") select 0 +}; + +// Remove whitespaces at the start and end of each statement, a statement being defined by the ";" at its end private _parsed = []; { @@ -35,31 +47,30 @@ private _setting = ""; private _priority = 0; private _value = ""; private _countForce = count "force"; -private _whitespaces = [toString [ASCII_NEWLINE], toString [ASCII_CARRIAGE_RETURN], toString [ASCII_TAB], toString [ASCII_SPACE]]; +private _whitespace = WHITESPACE; { _indexEqualSign = _x find "="; - // Setting name is front of "=" - _setting = (_x select [0, _indexEqualSign]) trim [WHITESPACE, 2]; + // Setting name is in front of "=" + _setting = (_x select [0, _indexEqualSign]) trim [_whitespace, 2]; _priority = 0; - // Check if the first entry is force and not followed by an empty space - if (_setting select [0, _countForce] == "force" && {(_setting select [_countForce, 1]) in _whitespaces}) then { - _setting = (_setting select [_countForce]) trim [WHITESPACE, 1]; + // Check if the first entry is "force" and not followed by whitespace + if (_setting select [0, _countForce] == "force" && {(_setting select [_countForce, 1]) in _whitespace}) then { + _setting = (_setting select [_countForce]) trim [_whitespace, 1]; _priority = _priority + 1; }; - // Check if the second entry is force and not followed by an empty space - if (_setting select [0, _countForce] == "force" && {(_setting select [_countForce, 1]) in _whitespaces}) then { - _setting = (_setting select [_countForce]) trim [WHITESPACE, 1]; + // Check if the second entry is "force" and not followed by whitespace + if (_setting select [0, _countForce] == "force" && {(_setting select [_countForce, 1]) in _whitespace}) then { + _setting = (_setting select [_countForce]) trim [_whitespace, 1]; _priority = _priority + 1; }; - // If setting is valid, get it's value + // If setting is valid, get its value if (_setting != "") then { - // Remove whitespaces; Parse bool, number, string - _value = parseSimpleArray (["[", (_x select [_indexEqualSign + 1]) splitString WHITESPACE joinString "", "]"] joinString "") select 0; + _value = (_x select [_indexEqualSign + 1]) call _fnc_parseAny; if !(_validate) then { _result pushBack [_setting, _value, _priority]; From eb638959764596546b0fad4bc4739a8b21c89400 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Fri, 11 Aug 2023 21:10:44 +0200 Subject: [PATCH 3/3] Updated comments --- addons/settings/fnc_parse.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/settings/fnc_parse.sqf b/addons/settings/fnc_parse.sqf index c9c1de6edc..44fb7b6cfc 100644 --- a/addons/settings/fnc_parse.sqf +++ b/addons/settings/fnc_parse.sqf @@ -56,13 +56,13 @@ private _whitespace = WHITESPACE; _setting = (_x select [0, _indexEqualSign]) trim [_whitespace, 2]; _priority = 0; - // Check if the first entry is "force" and not followed by whitespace + // Check if the first entry is "force" and followed by whitespace if (_setting select [0, _countForce] == "force" && {(_setting select [_countForce, 1]) in _whitespace}) then { _setting = (_setting select [_countForce]) trim [_whitespace, 1]; _priority = _priority + 1; }; - // Check if the second entry is "force" and not followed by whitespace + // Check if the second entry is "force" and followed by whitespace if (_setting select [0, _countForce] == "force" && {(_setting select [_countForce, 1]) in _whitespace}) then { _setting = (_setting select [_countForce]) trim [_whitespace, 1]; _priority = _priority + 1;