Skip to content

Commit

Permalink
Merge pull request #457 from CBATeam/add-removeWhitespace
Browse files Browse the repository at this point in the history
add 'CBA_fnc_removeWhitespace'
  • Loading branch information
Killswitch00 authored Aug 10, 2016
2 parents bdfb3d8 + 30eb1f5 commit eb9e5ed
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
6 changes: 6 additions & 0 deletions addons/strings/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class CfgFunctions
description = "Trims white-space (space, tab, newline) from the left end of a string.";
file = "\x\cba\addons\strings\fnc_leftTrim.sqf";
};
// CBA_fnc_removeWhitespace
class removeWhitespace
{
description = "Removes whitespace (space, tab, newline) from string.";
file = "\x\cba\addons\strings\fnc_removeWhitespace.sqf";
};
// CBA_fnc_replace
class replace
{
Expand Down
32 changes: 32 additions & 0 deletions addons/strings/fnc_removeWhitespace.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* ----------------------------------------------------------------------------
Function: CBA_fnc_removeWhitespace
Description:
Removes whitespace (space, tab, newline) from string.
Parameters:
_string - Any String <STRING>
_seperate - Seperate leftovers with spaces? (optional, default: false) <BOOLEAN>
Returns:
String without whitespace <STRING>
Example:
(begin example)
" foo bar " call CBA_fnc_removeWhitespace;
// "foobar"
[" foo bar ", true] call CBA_fnc_removeWhitespace;
// "foo bar"
(end)
Author:
commy2
---------------------------------------------------------------------------- */
#include "script_component.hpp"
#include "script_strings.hpp"
SCRIPT(removeWhitespace);

params [["_string", "", [""]], ["_seperate", false, [true]]];

(_string splitString toString WHITE_SPACE) joinString (["", " "] select _seperate) // return
2 changes: 1 addition & 1 deletion addons/strings/test.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ LOG("=== Testing Strings ===");
call compile preprocessFileLineNumbers format ["\x\cba\addons\strings\test_%1.sqf", _x];
} forEach TESTS;

nil;
nil
21 changes: 20 additions & 1 deletion addons/strings/test_strings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,23 @@ _result = ["aardwolf", "aardvark"] call CBA_fnc_compare;
TEST_OP(_result, ==, +1, _fn);
*/

nil;
// ----------------------------------------------------------------------------
// UNIT TESTS (removeWhitespace)
_fn = "CBA_fnc_removeWhitespace";

TEST_DEFINED("CBA_fnc_removeWhitespace","");

_str = " foo bar " call CBA_fnc_removeWhitespace;
_expected = "foobar";
TEST_OP(_str,isEqualTo,_expected,_fn);

_str = [" foo bar ", true] call CBA_fnc_removeWhitespace;
_expected = "foo bar";
TEST_OP(_str,isEqualTo,_expected,_fn);

_str = "tab: newline:
space: " call CBA_fnc_removeWhitespace;
_expected = "tab:newline:space:";
TEST_OP(_str,isEqualTo,_expected,_fn);

nil

0 comments on commit eb9e5ed

Please sign in to comment.