123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #define SCALAR (typeName 123)
- #define ARRAY (typeName [])
- private ["_pairs","_key","_add","_copy","_index","_value","_tValue","_tAdd","_return"];
- _pairs = [_this,0,[],[[]]] call bis_fnc_param;
- _key = [_this,1,"",[""]] call bis_fnc_param;
- _add = [_this,2,1] call bis_fnc_param;
- _index = -1;
- _return = "";
- {
- if (typeName _x != typeName []) exitWith
- {
- ["Every item in the pair array must be an array!"] call BIS_fnc_error;
- _index = -2;
- };
- if (count _x != 2) exitWith
- {
- ["Pair array must contain exactly 2 items, key and value!"] call BIS_fnc_error;
- _index = -2;
- };
- if (isNil{_x select 0}) exitWith
- {
- ["Key cannot be nil!"] call BIS_fnc_error;
- _index = -2;
- };
- if (typeName(_x select 0) != typeName "") exitWith
- {
- ["Key must be a string!"] call BIS_fnc_error;
- _index = -2;
- };
- if (isNil{_x select 1}) exitWith
- {
- ["Value cannot be nil!"] call BIS_fnc_error;
- _index = -2;
- };
- if (_key == (_x select 0)) exitWith
- {
- _index = _forEachIndex;
- _value = _x select 1;
- };
- }
- forEach _pairs;
- if (_index == -2) exitWith {nil};
- if (_index == -1) then
- {
- _pairs pushBack [_key, _add];
- _return = _add;
- }
- else
- {
- _tValue = typeName _value;
- _tAdd = typeName _add;
- switch (true) do
- {
- case (_tValue == SCALAR && _tAdd == SCALAR):
- {
- _return = _value + _add;
- };
- case (_tValue == ARRAY && _tAdd == ARRAY):
- {
- _return = _value + _add;
- };
- case (_tValue == ARRAY):
- {
- _return = _value + [_add];
- };
- case (_tAdd == ARRAY):
- {
- _return = _add + [_value];
- };
-
- default
- {
- _return = _value + [_add];
- };
- };
- _pairs set [_index, [_key, _return]];
- };
- _return
|