Skip to content

Commit

Permalink
Merge pull request CBATeam#208 from CBATeam/FixSplit154
Browse files Browse the repository at this point in the history
Fix split154
  • Loading branch information
Killswitch00 committed Dec 3, 2015
2 parents e23bea7 + 565f6c9 commit fcc90c0
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions addons/strings/fnc_split.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,33 @@ _split = [];
_index = 0;
_inputCount = count _input;
_separatorCount = count _separator;
//Return array if split count > input count (Match default behavior):
if (_separatorCount > _inputCount) exitWith {[_input]};
if (_separatorCount > 1) then {
_lastWasSeperator = true;
while {_index < _inputCount} do {
_find = (_input select [_index, (_inputCount - _index)]) find _separator;
if (_find == 0) then {
_index = _index + _separatorCount;
if (_lastWasSeperator) then {_split pushBack "";};
_lastWasSeperator = true;
// Corner cases
if (_separatorCount == 0 && _inputCount == 0) exitWith {[]};
if (_separatorCount == 0) exitWith {_input splitString ""};
if (_inputCount > 0 && _separatorCount > _inputCount) exitWith {[_input]};
if (_input == _separator) exitWith {["",""]};

_lastWasSeperator = true;
while {_index < _inputCount} do {
_find = (_input select [_index, (_inputCount - _index)]) find _separator;
if (_find == 0) then {
_index = _index + _separatorCount;
if (_lastWasSeperator) then {_split pushBack "";};
_lastWasSeperator = true;
} else {
_lastWasSeperator = false;
if (_find == -1) then {
_split pushBack (_input select [_index, (_inputCount - _index)]);
_index = _inputCount;
} else {
_lastWasSeperator = false;
if (_find == -1) then {
_split pushBack (_input select [_index, (_inputCount - _index)]);
_index = _inputCount;
} else {
_split pushBack (_input select [_index, _find]);
_index = _index + _find;
};
_split pushBack (_input select [_index, _find]);
_index = _index + _find;
};
};
//Handle split at end:
if ((_inputCount >= _separatorCount) && {(_input select [(_inputCount - _separatorCount), _separatorCount]) isEqualTo _separator}) then {
_split pushBack "";
};
} else {
_split = _input splitString _separator;
};
//Handle split at end:
if ((_inputCount >= _separatorCount) && {(_input select [(_inputCount - _separatorCount), _separatorCount]) isEqualTo _separator}) then {
_split pushBack "";
};
_split

0 comments on commit fcc90c0

Please sign in to comment.