diff --git a/addons/settings/fnc_import.sqf b/addons/settings/fnc_import.sqf index 77937df76..be135e334 100644 --- a/addons/settings/fnc_import.sqf +++ b/addons/settings/fnc_import.sqf @@ -18,7 +18,7 @@ Author: params [["_info", "", [""]], ["_source", "client", [""]]]; -_info = [_info, true, _source] call FUNC(parse); +_info = [_info, true, _source, false] call FUNC(parse); { _x params ["_setting", "_value", "_priority"]; diff --git a/addons/settings/fnc_parse.sqf b/addons/settings/fnc_parse.sqf index 5c7f0af99..160b4c3a3 100644 --- a/addons/settings/fnc_parse.sqf +++ b/addons/settings/fnc_parse.sqf @@ -6,9 +6,10 @@ Description: Convert settings in file format into array. Parameters: - _info - Content of file or clipboard to parse. - _validate - Check if settings are valid. (optional, default: false) - _source - Can be "client", "mission" or "server" (optional, default: "") + _info - Content of file or clipboard to parse. + _validate - Check if settings are valid. (optional, default: false) + _source - Can be "client", "mission" or "server" (optional, default: "") + _isPreprocessed - If the contents have already been preprocessed or not (optional, default: true) Returns: Settings with values and priority states. @@ -17,7 +18,7 @@ Author: commy2, johnb43 ---------------------------------------------------------------------------- */ -params [["_info", "", [""]], ["_validate", false, [false]], ["_source", "", [""]]]; +params [["_info", "", [""]], ["_validate", false, [false]], ["_source", "", [""]], ["_isPreprocessed", true, [false]]]; // Parses bools, numbers, strings private _fnc_parseAny = { @@ -27,11 +28,10 @@ private _fnc_parseAny = { }; // If string comes from the "import" button, it is not preprocessed -// Therefore, remove single line comments (//) -_info = _info regexReplace ["/{2}[^\n\r]*((\n|\r)?)", ""]; - -// Remove multiline comments too (/* */) -_info = _info regexReplace ["/\*[^(\*/)]*((\*/)?)", ""]; +if (!_isPreprocessed) then { + // Remove single line and multiline comments, ignoring comments in strings + _info = _info regexReplace ["(""(?:\\.|[^""\\])*""|'(?:\\.|[^'\\])*')|(\/{2}.*?$)|(\/\*[\s\S]*?(\*\/))|(\/\*[\s\S]*$)", "$1"]; +}; // Remove whitespaces at the start and end of each statement, a statement being defined by the ";" at its end private _parsed = []; diff --git a/addons/settings/test_parse.sqf b/addons/settings/test_parse.sqf index 162b1813b..d28258f68 100644 --- a/addons/settings/test_parse.sqf +++ b/addons/settings/test_parse.sqf @@ -57,35 +57,40 @@ TEST_TRUE(_result,_funcName); _settings = (preprocessFile "x\cba\addons\settings\test_settings_strings.inc.sqf") call FUNC(parse); _result = _settings isEqualTo [ - ["test1", "", 0], - ["test2", "", 0], - ["test3", " T E S T " , 0], - ["test4", " T E S T ", 0], - ["test5", "[ ' t e s t ' , "" T E S T "" ]", 0], - ["test6", "[ "" t e s t "" , + ["test1", "", 0], + ["test2", "", 0], + ["test3", " T E S T " , 0], + ["test4", " T E S T ", 0], + ["test5", "[ ' t e s t ' , "" T E S T "" ]", 0], + ["test6", "[ "" t e s t "" , """" T E S T """" ]", 0], - ["test7", "[ true, false ]", 0], - ["test8", "[ "" item_1 "" , "" item_2 "" ]", 0], - ["test9", "[ ' item_1 ' , ' item_2 ' ]", 0], - ["test10", "[ ' item_1 ' , "" item_2 "" ]", 0], - ["test11", "[ '"" item_1 ""' , ' item_2 ' ]", 0], - ["test12", "[ ' item_1 ' , ""' item_2 '"" ]", 0] + ["test7", "[ true, false ]", 0], + ["test8", "[ "" item_1 "" , "" item_2 "" ]", 0], + ["test9", "[ ' item_1 ' , ' item_2 ' ]", 0], + ["test10", "[ ' item_1 ' , "" item_2 "" ]", 0], + ["test11", "[ '"" item_1 ""' , ' item_2 ' ]", 0], + ["test12", "[ ' item_1 ' , ""' item_2 '"" ]", 0], + ["test13", "'", 0], + ["test14", "''", 0] ]; TEST_TRUE(_result,_funcName); // Don't preprocess for testing comments -_settings = (loadFile "x\cba\addons\settings\test_settings_comments.inc.sqf") call FUNC(parse); +_settings = [loadFile "x\cba\addons\settings\test_settings_comments.inc.sqf", false, "", false] call FUNC(parse); _result = _settings isEqualTo [ ["test2", "[true,false]", 1], ["test4", "[ ' t e s t ' , "" T E S T "" ]", 0], + ["test8", "https://github.com/CBATeam/CBA_A3", 0], + ["test11", "/* test */", 0], + ["test14", "/* test /", 0], ["ace_advanced_ballistics_ammoTemperatureEnabled", true, 0], ["ace_advanced_ballistics_barrelLengthInfluenceEnabled", true, 2], ["ace_advanced_ballistics_bulletTraceEnabled", true, 1] ]; TEST_TRUE(_result,_funcName); -_settings = (loadFile "x\cba\addons\settings\test_settings_comments_eof.inc.sqf") call FUNC(parse); +_settings = [loadFile "x\cba\addons\settings\test_settings_comments_eof.inc.sqf", false, "", false] call FUNC(parse); _result = _settings isEqualTo [ ["test1", "[""item_1"",""item_2""]", 1] ]; diff --git a/addons/settings/test_settings_comments.inc.sqf b/addons/settings/test_settings_comments.inc.sqf index 6d573ccd5..93588b841 100644 --- a/addons/settings/test_settings_comments.inc.sqf +++ b/addons/settings/test_settings_comments.inc.sqf @@ -17,6 +17,21 @@ test6 = ''; // "settings,"; test7 = " T S T "; */ +test8 = "https://github.com/CBATeam/CBA_A3"; +// test9 = "https://github.com/CBATeam/CBA_A3"; + +/* +test10 = "https://github.com/CBATeam/CBA_A3"; +*/ + +test11 = "/* test */"; +// test12 = "/* test */"; + +/* +test13 = "/* test /"; +*/ + +test14 = "/* test /"; // ACE Advanced Ballistics ace_advanced_ballistics_ammoTemperatureEnabled = true; diff --git a/addons/settings/test_settings_strings.inc.sqf b/addons/settings/test_settings_strings.inc.sqf index c763042c1..ccf1360f0 100644 --- a/addons/settings/test_settings_strings.inc.sqf +++ b/addons/settings/test_settings_strings.inc.sqf @@ -23,3 +23,7 @@ test10 = "[ ' item_1 ' , "" item_2 "" ]"; test11 = "[ '"" item_1 ""' , ' item_2 ' ]"; test12 = "[ ' item_1 ' , ""' item_2 '"" ]"; + +test13 = "'"; + +test14 = "''";