From 527ed3283b51a76995049c2dca7e8acb9143ffa7 Mon Sep 17 00:00:00 2001 From: "[VB]AWOL" Date: Wed, 6 Nov 2013 20:50:22 -0600 Subject: [PATCH] better fn_string by KK --- SQF/dayz_code/compile/fn_inString.sqf | 55 ++++++++++++++------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/SQF/dayz_code/compile/fn_inString.sqf b/SQF/dayz_code/compile/fn_inString.sqf index e704e97ac..12203f544 100644 --- a/SQF/dayz_code/compile/fn_inString.sqf +++ b/SQF/dayz_code/compile/fn_inString.sqf @@ -1,28 +1,31 @@ -//Kilzone_Kid's megafast inString function -//caseinsensitive -//params [needle,haystack] -private["_needle","_haystack","_found","_haystackArr","_haystackLen","_needleLen","_hayArr"]; -scopeName "main"; -_needle = _this select 0; -_haystack = _this select 1; -_haystackArr = toArray _haystack; -_haystackLen = count _haystackArr; -_needleLen = count (toArray _needle); +/* +Author: Killzone_Kid + +Description: +Find a string within a string (case insensitive) + +Parameter(s): +_this select 0: string to be found +_this select 1: string to search in + +Returns: +Boolean (true when string is found) + +How to use: +_found = ["needle", "Needle in Haystack"] call KK_fnc_inString; +*/ + +private ["_needle","_haystack","_needleLen","_hay","_found"]; +_needle = [_this, 0, "", [""]] call BIS_fnc_param; +_haystack = toArray ([_this, 1, "", [""]] call BIS_fnc_param); +_needleLen = count toArray _needle; +_hay = +_haystack; +_hay resize _needleLen; _found = false; -if (_needleLen <= _haystackLen) then { - _hayArr = []; - for "_i" from 0 to (_needleLen - 1) do { - _hayArr set [count _hayArr, _haystackArr select _i]; - }; - for "_i" from _needleLen to _haystackLen do { - if (toString _hayArr != _needle) then { - _hayArr set [_needleLen, _haystackArr select _i]; - _hayArr set [0, "x"]; - _hayArr = _hayArr - ["x"]; - } else { - _found = true; - breakTo "main"; - }; - }; +for "_i" from _needleLen to count _haystack do { + if (toString _hay == _needle) exitWith {_found = true}; + _hay set [_needleLen, _haystack select _i]; + _hay set [0, "x"]; + _hay = _hay - ["x"] }; -_found +_found \ No newline at end of file