|
| 1 | +#include "script_component.hpp" |
| 2 | +/* ---------------------------------------------------------------------------- |
| 3 | +Function: CBA_fnc_prettyFormat |
| 4 | +
|
| 5 | +Description: |
| 6 | + Makes an array easy to read. |
| 7 | +
|
| 8 | +Parameters: |
| 9 | + _array - Array to format <ARRAY> |
| 10 | + _indents - Indentation string (optional, default: " ") <STRING> |
| 11 | + _lineBreak - Seperator string (optional, default: endl) <STRING> |
| 12 | + _depth - Initial indentation count (optional, default: 0) <NUMBER> |
| 13 | +
|
| 14 | +Returns: |
| 15 | + Formatted string <STRING> |
| 16 | +
|
| 17 | +Examples: |
| 18 | + (begin example) |
| 19 | + [[0, 1, ["22", 33, []], 4]] call CBA_fnc_prettyFormat; |
| 20 | + //[ |
| 21 | + // 0, |
| 22 | + // 1, |
| 23 | + // [ |
| 24 | + // "22", |
| 25 | + // 33, |
| 26 | + // [] |
| 27 | + // ], |
| 28 | + // 4 |
| 29 | + //] |
| 30 | +
|
| 31 | + [[0, 1, ["22", 33, []], 4], ">---"] call CBA_fnc_prettyFormat; |
| 32 | + //[ |
| 33 | + //>---0, |
| 34 | + //>---1, |
| 35 | + //>---[ |
| 36 | + //>--->---"22", |
| 37 | + //>--->---33, |
| 38 | + //>--->---[] |
| 39 | + //>---], |
| 40 | + //>---4 |
| 41 | + //] |
| 42 | +
|
| 43 | + [[0, 1, ["22", 33, []], 4], ">---", "\n"] call CBA_fnc_prettyFormat; |
| 44 | + //[\n>---0,\n>---1,\n>---[\n>--->---"22",\n>--->---33,\n>--->---[]\n>---],\n>---4\n] |
| 45 | + (end) |
| 46 | +
|
| 47 | +Author: |
| 48 | + Terra, Dystopian, commy2 |
| 49 | +
|
| 50 | +---------------------------------------------------------------------------- */ |
| 51 | +params [ |
| 52 | + ["_array", [], [[]]], |
| 53 | + ["_indent", " ", [""]], |
| 54 | + ["_lineBreak", endl, [""]], |
| 55 | + ["_depth", 0, [0]] |
| 56 | +]; |
| 57 | + |
| 58 | +private _indents = STRING_REPEAT(_indent, _depth); |
| 59 | + |
| 60 | +if (_array isEqualTo []) exitWith { |
| 61 | + _indents + "[]" // return |
| 62 | +}; |
| 63 | + |
| 64 | +private _lines = _array apply { |
| 65 | + if (_x isEqualType []) then { |
| 66 | + [_x, _indent, _lineBreak, _depth + 1] call CBA_fnc_prettyFormat |
| 67 | + } else { |
| 68 | + _indents + _indent + str _x |
| 69 | + }; |
| 70 | +}; |
| 71 | + |
| 72 | +_indents + "[" + _lineBreak + (_lines joinString ("," + _lineBreak)) + _lineBreak + _indents + "]" // return |
0 commit comments