From a92637ce9a25be3cf3e273fb660d44962b3555d5 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Mon, 8 Nov 2021 14:03:05 +0100 Subject: [PATCH 01/23] New function prettyPrint --- addons/arrays/CfgFunctions.hpp | 1 + addons/arrays/fnc_prettyPrint.sqf | 67 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 addons/arrays/fnc_prettyPrint.sqf diff --git a/addons/arrays/CfgFunctions.hpp b/addons/arrays/CfgFunctions.hpp index 45697ec22e..85ae42f856 100644 --- a/addons/arrays/CfgFunctions.hpp +++ b/addons/arrays/CfgFunctions.hpp @@ -13,6 +13,7 @@ class CfgFunctions { PATHTO_FNC(inject); PATHTO_FNC(insert); PATHTO_FNC(join); + PATHTO_FNC(prettyPrint); PATHTO_FNC(reject); PATHTO_FNC(select); PATHTO_FNC(selectBest); diff --git a/addons/arrays/fnc_prettyPrint.sqf b/addons/arrays/fnc_prettyPrint.sqf new file mode 100644 index 0000000000..e262afe5e0 --- /dev/null +++ b/addons/arrays/fnc_prettyPrint.sqf @@ -0,0 +1,67 @@ +#include "script_component.hpp" +/* ---------------------------------------------------------------------------- +Function: CBA_fnc_prettyPrint + +Description: + Makes an array easier to read. + +Parameters: + _this - Array + +Returns: + Formatted string + +Examples: + (begin example) + _return = [0, 1, ["22", 33, []], 4] call CBA_fnc_prettyPrint; + // _return ==> + // "[ + // 0, + // 1, + // [ + // ""22"", + // 33, + // [] + // ], + // 4 + // ]" + (end) + +Author: + Terra +---------------------------------------------------------------------------- */ +SCRIPT(prettyPrint); + +if (count _this == 0) exitWith { + "[]" +}; +private _lines = ["["]; +// Recursive function calls have _depth already defined +private _depth = if (isNil "_depth") then { + 0 +} else { + _depth + 1 +}; + +{ + private _line = ""; + for "_i" from 1 to (_depth + 1) do { + _line = " " + _line; + }; + _line = if (_x isEqualType []) then { + _line + (_x call CBA_fnc_prettyPrint); + } else { + _line + str _x; + }; + if (_forEachIndex != count _this - 1) then { + _line = _line + ","; + }; + _lines pushBack _line; +} forEach _this; + +private _closingBracket = ""; +for "_i" from 1 to _depth do { + _closingBracket = " " + _closingBracket; +}; +_lines pushBack (_closingBracket + "]"); +_lines joinString endl From 7b9598a0207b05fc3bb6687abb403f7ea813a7e6 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Mon, 8 Nov 2021 14:05:40 +0100 Subject: [PATCH 02/23] Use spaces instead of tabs --- addons/arrays/CfgFunctions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/arrays/CfgFunctions.hpp b/addons/arrays/CfgFunctions.hpp index 85ae42f856..6ecc7cef81 100644 --- a/addons/arrays/CfgFunctions.hpp +++ b/addons/arrays/CfgFunctions.hpp @@ -13,7 +13,7 @@ class CfgFunctions { PATHTO_FNC(inject); PATHTO_FNC(insert); PATHTO_FNC(join); - PATHTO_FNC(prettyPrint); + PATHTO_FNC(prettyPrint); PATHTO_FNC(reject); PATHTO_FNC(select); PATHTO_FNC(selectBest); From d2a61f0a94f0632bbd1d539507ae9e7d0de8f173 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Tue, 9 Nov 2021 00:55:09 +0100 Subject: [PATCH 03/23] Fixed spaces, parameters for tab char and indent --- addons/arrays/fnc_prettyPrint.sqf | 86 +++++++++++++++++-------------- 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/addons/arrays/fnc_prettyPrint.sqf b/addons/arrays/fnc_prettyPrint.sqf index e262afe5e0..cc75a966e5 100644 --- a/addons/arrays/fnc_prettyPrint.sqf +++ b/addons/arrays/fnc_prettyPrint.sqf @@ -3,65 +3,73 @@ Function: CBA_fnc_prettyPrint Description: - Makes an array easier to read. + Makes an array easier to read. Parameters: - _this - Array + _array - The array to format + _tab - The tab char to use (optional, default: tab) + _depth - Starting indent (optional, default: 0) Returns: - Formatted string + Formatted string Examples: (begin example) - _return = [0, 1, ["22", 33, []], 4] call CBA_fnc_prettyPrint; - // _return ==> - // "[ - // 0, - // 1, - // [ - // ""22"", - // 33, - // [] - // ], - // 4 - // ]" + _return = [ [0, 1, ["22", 33, []], 4] ] call CBA_fnc_prettyPrint; + // _return ==> + // "[ + // 0, + // 1, + // [ + // ""22"", + // 33, + // [] + // ], + // 4 + // ]" + _return = [ [0, 1, ["22", 33, []], 4], ">---" ] call CBA_fnc_prettyPrint; + // _return ==> + // [ + // >---0, + // >---1, + // >---[ + // >--->---""22"", + // >--->---33, + // >--->---[] + // >---], + // >---4 + // ] (end) Author: Terra ---------------------------------------------------------------------------- */ SCRIPT(prettyPrint); - -if (count _this == 0) exitWith { - "[]" +params [["_array", [], [[]]], ["_tab", toString[9], [""]], ["_depth", 0, [0]]]; +if (count _array == 0) exitWith { + "[]" }; private _lines = ["["]; -// Recursive function calls have _depth already defined -private _depth = if (isNil "_depth") then { - 0 -} else { - _depth + 1 -}; { - private _line = ""; - for "_i" from 1 to (_depth + 1) do { - _line = " " + _line; - }; - _line = if (_x isEqualType []) then { - _line + (_x call CBA_fnc_prettyPrint); - } else { - _line + str _x; - }; - if (_forEachIndex != count _this - 1) then { - _line = _line + ","; - }; - _lines pushBack _line; -} forEach _this; + private _line = ""; + for "_i" from 1 to (_depth + 1) do { + _line = _tab + _line; + }; + _line = if (_x isEqualType []) then { + _line + ([_x, _tab, _depth + 1] call CBA_fnc_prettyPrint); + } else { + _line + str _x; + }; + if (_forEachIndex != count _array - 1) then { + _line = _line + ","; + }; + _lines pushBack _line; +} forEach _array; private _closingBracket = ""; for "_i" from 1 to _depth do { - _closingBracket = " " + _closingBracket; + _closingBracket = _tab + _closingBracket; }; _lines pushBack (_closingBracket + "]"); _lines joinString endl From 830b4ac1c77f5623c4880694791d277fbeca0ec2 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Tue, 9 Nov 2021 00:57:51 +0100 Subject: [PATCH 04/23] Removed trailing whitespace --- addons/arrays/fnc_prettyPrint.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/arrays/fnc_prettyPrint.sqf b/addons/arrays/fnc_prettyPrint.sqf index cc75a966e5..9ca66099d2 100644 --- a/addons/arrays/fnc_prettyPrint.sqf +++ b/addons/arrays/fnc_prettyPrint.sqf @@ -26,7 +26,7 @@ Examples: // [] // ], // 4 - // ]" + // ]" _return = [ [0, 1, ["22", 33, []], 4], ">---" ] call CBA_fnc_prettyPrint; // _return ==> // [ @@ -42,7 +42,7 @@ Examples: (end) Author: - Terra + Terra ---------------------------------------------------------------------------- */ SCRIPT(prettyPrint); params [["_array", [], [[]]], ["_tab", toString[9], [""]], ["_depth", 0, [0]]]; From b1e6f2b247f35c624fd625c53088d4ea0c7e5897 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:24:51 +0100 Subject: [PATCH 05/23] Use isEqualTo instead of count Co-authored-by: Dystopian --- addons/arrays/fnc_prettyPrint.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/arrays/fnc_prettyPrint.sqf b/addons/arrays/fnc_prettyPrint.sqf index 9ca66099d2..48eb1c8cec 100644 --- a/addons/arrays/fnc_prettyPrint.sqf +++ b/addons/arrays/fnc_prettyPrint.sqf @@ -46,7 +46,7 @@ Author: ---------------------------------------------------------------------------- */ SCRIPT(prettyPrint); params [["_array", [], [[]]], ["_tab", toString[9], [""]], ["_depth", 0, [0]]]; -if (count _array == 0) exitWith { +if (_array isEqualTo []) exitWith { "[]" }; private _lines = ["["]; From f27103850a6c73579d055197a7b92a31f5bf3c89 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:25:50 +0100 Subject: [PATCH 06/23] Added space between command and argument Co-authored-by: Dystopian --- addons/arrays/fnc_prettyPrint.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/arrays/fnc_prettyPrint.sqf b/addons/arrays/fnc_prettyPrint.sqf index 48eb1c8cec..e5696e0768 100644 --- a/addons/arrays/fnc_prettyPrint.sqf +++ b/addons/arrays/fnc_prettyPrint.sqf @@ -45,7 +45,7 @@ Author: Terra ---------------------------------------------------------------------------- */ SCRIPT(prettyPrint); -params [["_array", [], [[]]], ["_tab", toString[9], [""]], ["_depth", 0, [0]]]; +params [["_array", [], [[]]], ["_tab", toString [9], [""]], ["_depth", 0, [0]]]; if (_array isEqualTo []) exitWith { "[]" }; From 53f427bf0df7edf92005b2a4eeebdf6f080b8773 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:47:10 +0100 Subject: [PATCH 07/23] Avoid count every loop --- addons/arrays/fnc_prettyPrint.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/arrays/fnc_prettyPrint.sqf b/addons/arrays/fnc_prettyPrint.sqf index e5696e0768..b4350cc2c4 100644 --- a/addons/arrays/fnc_prettyPrint.sqf +++ b/addons/arrays/fnc_prettyPrint.sqf @@ -50,7 +50,7 @@ if (_array isEqualTo []) exitWith { "[]" }; private _lines = ["["]; - +private _lastIndex = count _array - 1; { private _line = ""; for "_i" from 1 to (_depth + 1) do { @@ -61,7 +61,7 @@ private _lines = ["["]; } else { _line + str _x; }; - if (_forEachIndex != count _array - 1) then { + if (_forEachIndex != _lastIndex) then { _line = _line + ","; }; _lines pushBack _line; From cedbf69864d01dcd5b4dd7eaf60d6f4af301fe80 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:51:45 +0100 Subject: [PATCH 08/23] Correct indentation for empty arrays --- addons/arrays/fnc_prettyPrint.sqf | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/addons/arrays/fnc_prettyPrint.sqf b/addons/arrays/fnc_prettyPrint.sqf index b4350cc2c4..20fa595f1c 100644 --- a/addons/arrays/fnc_prettyPrint.sqf +++ b/addons/arrays/fnc_prettyPrint.sqf @@ -46,20 +46,20 @@ Author: ---------------------------------------------------------------------------- */ SCRIPT(prettyPrint); params [["_array", [], [[]]], ["_tab", toString [9], [""]], ["_depth", 0, [0]]]; +private _tabs = []; +_tabs resize _depth; +_tabs = _tabs apply {_tab} joinString ""; if (_array isEqualTo []) exitWith { - "[]" + _tabs + "[]" }; -private _lines = ["["]; +private _lines = [_tabs + "["]; private _lastIndex = count _array - 1; { private _line = ""; - for "_i" from 1 to (_depth + 1) do { - _line = _tab + _line; - }; _line = if (_x isEqualType []) then { _line + ([_x, _tab, _depth + 1] call CBA_fnc_prettyPrint); } else { - _line + str _x; + _tab + _tabs + _line + str _x; }; if (_forEachIndex != _lastIndex) then { _line = _line + ","; @@ -67,9 +67,5 @@ private _lastIndex = count _array - 1; _lines pushBack _line; } forEach _array; -private _closingBracket = ""; -for "_i" from 1 to _depth do { - _closingBracket = _tab + _closingBracket; -}; -_lines pushBack (_closingBracket + "]"); +_lines pushBack (_tabs + "]"); _lines joinString endl From 1424b737e4ed3c9b370e0a998ce171527ee0f86f Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Tue, 9 Nov 2021 15:57:26 +0100 Subject: [PATCH 09/23] Moved variable assignment inside of the if statement --- addons/arrays/fnc_prettyPrint.sqf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/arrays/fnc_prettyPrint.sqf b/addons/arrays/fnc_prettyPrint.sqf index 20fa595f1c..b58cdcec05 100644 --- a/addons/arrays/fnc_prettyPrint.sqf +++ b/addons/arrays/fnc_prettyPrint.sqf @@ -56,10 +56,10 @@ private _lines = [_tabs + "["]; private _lastIndex = count _array - 1; { private _line = ""; - _line = if (_x isEqualType []) then { - _line + ([_x, _tab, _depth + 1] call CBA_fnc_prettyPrint); + if (_x isEqualType []) then { + _line = _line + ([_x, _tab, _depth + 1] call CBA_fnc_prettyPrint); } else { - _tab + _tabs + _line + str _x; + _line = _tab + _tabs + _line + str _x; }; if (_forEachIndex != _lastIndex) then { _line = _line + ","; From 125ea3f7748d1375e2ceab21bec53f5aec6f9160 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Tue, 9 Nov 2021 16:02:21 +0100 Subject: [PATCH 10/23] Renamed prettyPrint to prettyFormat --- addons/arrays/CfgFunctions.hpp | 2 +- addons/arrays/{fnc_prettyPrint.sqf => fnc_prettyFormat.sqf} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename addons/arrays/{fnc_prettyPrint.sqf => fnc_prettyFormat.sqf} (100%) diff --git a/addons/arrays/CfgFunctions.hpp b/addons/arrays/CfgFunctions.hpp index 6ecc7cef81..cf8a4afe28 100644 --- a/addons/arrays/CfgFunctions.hpp +++ b/addons/arrays/CfgFunctions.hpp @@ -13,7 +13,7 @@ class CfgFunctions { PATHTO_FNC(inject); PATHTO_FNC(insert); PATHTO_FNC(join); - PATHTO_FNC(prettyPrint); + PATHTO_FNC(prettyFormat); PATHTO_FNC(reject); PATHTO_FNC(select); PATHTO_FNC(selectBest); diff --git a/addons/arrays/fnc_prettyPrint.sqf b/addons/arrays/fnc_prettyFormat.sqf similarity index 100% rename from addons/arrays/fnc_prettyPrint.sqf rename to addons/arrays/fnc_prettyFormat.sqf From 64a2ac84e0549b6f63c73a2888f56eb6d035d41b Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Tue, 9 Nov 2021 22:49:39 +0100 Subject: [PATCH 11/23] Changed prettyPrint to prettyFormat in files --- addons/arrays/fnc_prettyFormat.sqf | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index b58cdcec05..0d688c0cc4 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -1,6 +1,6 @@ #include "script_component.hpp" /* ---------------------------------------------------------------------------- -Function: CBA_fnc_prettyPrint +Function: CBA_fnc_prettyFormat Description: Makes an array easier to read. @@ -15,7 +15,7 @@ Returns: Examples: (begin example) - _return = [ [0, 1, ["22", 33, []], 4] ] call CBA_fnc_prettyPrint; + _return = [ [0, 1, ["22", 33, []], 4] ] call CBA_fnc_prettyFormat; // _return ==> // "[ // 0, @@ -27,7 +27,7 @@ Examples: // ], // 4 // ]" - _return = [ [0, 1, ["22", 33, []], 4], ">---" ] call CBA_fnc_prettyPrint; + _return = [ [0, 1, ["22", 33, []], 4], ">---" ] call CBA_fnc_prettyFormat; // _return ==> // [ // >---0, @@ -44,7 +44,7 @@ Examples: Author: Terra ---------------------------------------------------------------------------- */ -SCRIPT(prettyPrint); +SCRIPT(prettyFormat); params [["_array", [], [[]]], ["_tab", toString [9], [""]], ["_depth", 0, [0]]]; private _tabs = []; _tabs resize _depth; @@ -57,7 +57,7 @@ private _lastIndex = count _array - 1; { private _line = ""; if (_x isEqualType []) then { - _line = _line + ([_x, _tab, _depth + 1] call CBA_fnc_prettyPrint); + _line = _line + ([_x, _tab, _depth + 1] call CBA_fnc_prettyFormat); } else { _line = _tab + _tabs + _line + str _x; }; From a3977ae6100ce62aca49a81e2c52dc584e20963d Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Wed, 10 Nov 2021 22:02:47 +0100 Subject: [PATCH 12/23] Assign variable from if statement --- addons/arrays/fnc_prettyFormat.sqf | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index 0d688c0cc4..9ebe3928b1 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -55,11 +55,10 @@ if (_array isEqualTo []) exitWith { private _lines = [_tabs + "["]; private _lastIndex = count _array - 1; { - private _line = ""; - if (_x isEqualType []) then { - _line = _line + ([_x, _tab, _depth + 1] call CBA_fnc_prettyFormat); + private _line = if (_x isEqualType []) then { + ([_x, _tab, _depth + 1] call CBA_fnc_prettyFormat); } else { - _line = _tab + _tabs + _line + str _x; + _tab + _tabs + str _x; }; if (_forEachIndex != _lastIndex) then { _line = _line + ","; From a2bf956c92cc9836685afb725512222c7bca6a4f Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Thu, 11 Nov 2021 13:06:55 +0100 Subject: [PATCH 13/23] Join all elements explicitly at end of script --- addons/arrays/fnc_prettyFormat.sqf | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index 9ebe3928b1..d26c0878e1 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -49,22 +49,13 @@ params [["_array", [], [[]]], ["_tab", toString [9], [""]], ["_depth", 0, [0]]]; private _tabs = []; _tabs resize _depth; _tabs = _tabs apply {_tab} joinString ""; -if (_array isEqualTo []) exitWith { - _tabs + "[]" -}; -private _lines = [_tabs + "["]; -private _lastIndex = count _array - 1; -{ - private _line = if (_x isEqualType []) then { + +private _lines = { + if (_x isEqualType []) then { ([_x, _tab, _depth + 1] call CBA_fnc_prettyFormat); } else { _tab + _tabs + str _x; }; - if (_forEachIndex != _lastIndex) then { - _line = _line + ","; - }; - _lines pushBack _line; } forEach _array; -_lines pushBack (_tabs + "]"); -_lines joinString endl +_tabs + "[" + endl + (_lines joinString ("," + endl)) + endl + _tabs + "]" From fbfd58c88eaf3858af8ed71d732bfb70925d77e4 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Thu, 11 Nov 2021 13:08:49 +0100 Subject: [PATCH 14/23] Added Dystopian and commy2 as authors --- addons/arrays/fnc_prettyFormat.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index d26c0878e1..7fca8cd7e5 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -42,7 +42,7 @@ Examples: (end) Author: - Terra + Terra, Dystopian, commy2 ---------------------------------------------------------------------------- */ SCRIPT(prettyFormat); params [["_array", [], [[]]], ["_tab", toString [9], [""]], ["_depth", 0, [0]]]; From 18c48abea3fd46b56217659a1ec198db3fc92dc1 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Thu, 11 Nov 2021 13:17:42 +0100 Subject: [PATCH 15/23] Fixed usage of forEach instead of apply --- addons/arrays/fnc_prettyFormat.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index 7fca8cd7e5..b04d9b2724 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -50,12 +50,12 @@ private _tabs = []; _tabs resize _depth; _tabs = _tabs apply {_tab} joinString ""; -private _lines = { +private _lines = _array apply { if (_x isEqualType []) then { ([_x, _tab, _depth + 1] call CBA_fnc_prettyFormat); } else { _tab + _tabs + str _x; }; -} forEach _array; +}; _tabs + "[" + endl + (_lines joinString ("," + endl)) + endl + _tabs + "]" From 5bad5373b8f47b00ad905c0fc25a17b802f4d6d0 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Thu, 11 Nov 2021 13:19:20 +0100 Subject: [PATCH 16/23] Return [] for empty arrays --- addons/arrays/fnc_prettyFormat.sqf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index b04d9b2724..37501fd4a8 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -50,6 +50,10 @@ private _tabs = []; _tabs resize _depth; _tabs = _tabs apply {_tab} joinString ""; +if (_array isEqualTo []) exitWith { + _tabs + "[]" +}; + private _lines = _array apply { if (_x isEqualType []) then { ([_x, _tab, _depth + 1] call CBA_fnc_prettyFormat); From ca2f35d9c1e775fb188168ae66558369126c7561 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Thu, 11 Nov 2021 17:03:24 +0100 Subject: [PATCH 17/23] Removed unnecessary brackets Co-authored-by: Dystopian --- addons/arrays/fnc_prettyFormat.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index 37501fd4a8..a703e548cc 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -56,7 +56,7 @@ if (_array isEqualTo []) exitWith { private _lines = _array apply { if (_x isEqualType []) then { - ([_x, _tab, _depth + 1] call CBA_fnc_prettyFormat); + [_x, _tab, _depth + 1] call CBA_fnc_prettyFormat; } else { _tab + _tabs + str _x; }; From 590ba03a9a0c52447f50ed9edda1489b339ae981 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Thu, 11 Nov 2021 20:12:26 +0100 Subject: [PATCH 18/23] Removed ";" from returned values Co-authored-by: commy2 --- addons/arrays/fnc_prettyFormat.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index a703e548cc..2fcc846e32 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -56,9 +56,9 @@ if (_array isEqualTo []) exitWith { private _lines = _array apply { if (_x isEqualType []) then { - [_x, _tab, _depth + 1] call CBA_fnc_prettyFormat; + [_x, _tab, _depth + 1] call CBA_fnc_prettyFormat } else { - _tab + _tabs + str _x; + _tab + _tabs + str _x }; }; From d82918ffb0dba55971fb3deae2cbe0bd760b808a Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Thu, 11 Nov 2021 20:37:58 +0100 Subject: [PATCH 19/23] Fix linter Co-authored-by: commy2 --- addons/arrays/fnc_prettyFormat.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index 2fcc846e32..52c580114c 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -48,7 +48,7 @@ SCRIPT(prettyFormat); params [["_array", [], [[]]], ["_tab", toString [9], [""]], ["_depth", 0, [0]]]; private _tabs = []; _tabs resize _depth; -_tabs = _tabs apply {_tab} joinString ""; +_tabs = (_tabs apply {_tab}) joinString ""; if (_array isEqualTo []) exitWith { _tabs + "[]" From 3b58529d5b06aad7a807c76c76a9b05482fcf7e3 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Thu, 11 Nov 2021 21:25:21 +0100 Subject: [PATCH 20/23] Added parameter for line break char --- addons/arrays/fnc_prettyFormat.sqf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index 52c580114c..f53c2750c0 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -45,7 +45,7 @@ Author: Terra, Dystopian, commy2 ---------------------------------------------------------------------------- */ SCRIPT(prettyFormat); -params [["_array", [], [[]]], ["_tab", toString [9], [""]], ["_depth", 0, [0]]]; +params [["_array", [], [[]]], ["_tab", toString [9], [""]], ["_lineBreak", endl, [""]], ["_depth", 0, [0]]]; private _tabs = []; _tabs resize _depth; _tabs = (_tabs apply {_tab}) joinString ""; @@ -56,10 +56,10 @@ if (_array isEqualTo []) exitWith { private _lines = _array apply { if (_x isEqualType []) then { - [_x, _tab, _depth + 1] call CBA_fnc_prettyFormat + [_x, _tab, _lineBreak, _depth + 1] call CBA_fnc_prettyFormat } else { _tab + _tabs + str _x }; }; -_tabs + "[" + endl + (_lines joinString ("," + endl)) + endl + _tabs + "]" +_tabs + "[" + _lineBreak + (_lines joinString ("," + _lineBreak)) + _lineBreak + _tabs + "]" From d24829e61fd719d318be93f87c3d477796e912ac Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Fri, 12 Nov 2021 12:22:23 +0100 Subject: [PATCH 21/23] Documentation for line break param --- addons/arrays/fnc_prettyFormat.sqf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index f53c2750c0..b56835b297 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -8,6 +8,7 @@ Description: Parameters: _array - The array to format _tab - The tab char to use (optional, default: tab) + _lineBreak - The char to use for line breaks (optional, default: endl) _depth - Starting indent (optional, default: 0) Returns: @@ -39,6 +40,8 @@ Examples: // >---], // >---4 // ] + _return = [[0, 1, ["22", 33, []], 4], ">---", "\n"] call CBA_fnc_prettyFormat; + // _return ==> "[\n>---0,\n>---1,\n>---[\n>--->---""22"",\n>--->---33,\n>--->---[]\n>---],\n>---4\n]" (end) Author: From e0d754016d583ecccedf4eb570ab5ae57a0e9617 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Fri, 12 Nov 2021 16:10:43 +0100 Subject: [PATCH 22/23] Default indentation 4 spaces --- addons/arrays/fnc_prettyFormat.sqf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index b56835b297..cced6bdbc9 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -7,7 +7,7 @@ Description: Parameters: _array - The array to format - _tab - The tab char to use (optional, default: tab) + _tab - The tab char to use (optional, default: " ") _lineBreak - The char to use for line breaks (optional, default: endl) _depth - Starting indent (optional, default: 0) @@ -48,7 +48,7 @@ Author: Terra, Dystopian, commy2 ---------------------------------------------------------------------------- */ SCRIPT(prettyFormat); -params [["_array", [], [[]]], ["_tab", toString [9], [""]], ["_lineBreak", endl, [""]], ["_depth", 0, [0]]]; +params [["_array", [], [[]]], ["_tab", " ", [""]], ["_lineBreak", endl, [""]], ["_depth", 0, [0]]]; private _tabs = []; _tabs resize _depth; _tabs = (_tabs apply {_tab}) joinString ""; From dbb7898c4904fbe0d453b1d1d46d025bc9434bb9 Mon Sep 17 00:00:00 2001 From: 7erra <38866692+7erra@users.noreply.github.com> Date: Fri, 12 Nov 2021 16:13:35 +0100 Subject: [PATCH 23/23] Renamed _tabs to _indents --- addons/arrays/fnc_prettyFormat.sqf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/addons/arrays/fnc_prettyFormat.sqf b/addons/arrays/fnc_prettyFormat.sqf index cced6bdbc9..1e5487f8b9 100644 --- a/addons/arrays/fnc_prettyFormat.sqf +++ b/addons/arrays/fnc_prettyFormat.sqf @@ -49,20 +49,20 @@ Author: ---------------------------------------------------------------------------- */ SCRIPT(prettyFormat); params [["_array", [], [[]]], ["_tab", " ", [""]], ["_lineBreak", endl, [""]], ["_depth", 0, [0]]]; -private _tabs = []; -_tabs resize _depth; -_tabs = (_tabs apply {_tab}) joinString ""; +private _indents = []; +_indents resize _depth; +_indents = (_indents apply {_tab}) joinString ""; if (_array isEqualTo []) exitWith { - _tabs + "[]" + _indents + "[]" }; private _lines = _array apply { if (_x isEqualType []) then { [_x, _tab, _lineBreak, _depth + 1] call CBA_fnc_prettyFormat } else { - _tab + _tabs + str _x + _tab + _indents + str _x }; }; -_tabs + "[" + _lineBreak + (_lines joinString ("," + _lineBreak)) + _lineBreak + _tabs + "]" +_indents + "[" + _lineBreak + (_lines joinString ("," + _lineBreak)) + _lineBreak + _indents + "]"