-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace replace #331
Replace replace #331
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,35 +19,22 @@ Example: | |
(end) | ||
|
||
Author: | ||
jaynus | ||
BaerMitUmlaut | ||
--------------------------------------------------------------------------- */ | ||
|
||
#include "script_component.hpp" | ||
|
||
SCRIPT(replace); | ||
|
||
// ---------------------------------------------------------------------------- | ||
params [["_string", "", [""]], ["_find", "", [""]], ["_replace", "", [""]]]; | ||
private ["_offset", "_index"]; | ||
if (_find == "" || {_replace find _find != -1}) exitWith {_string}; | ||
|
||
params ["_string","_pattern","_replacement"]; | ||
private["_i", "_cp", "_findIndex", "_stringArray", "_replaceArray", "_returnArray"]; | ||
_offset = count (_find splitString ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this not be simply Also, can switch this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point of
|
||
|
||
_returnArray = []; | ||
_cp = count _pattern; | ||
_stringArray = toArray _string; | ||
_replaceArray = toArray _replacement; | ||
|
||
_findIndex = _string find _pattern; | ||
while { _findIndex != -1 } do { | ||
_i = 0; | ||
while { _i < _findIndex } do { | ||
_returnArray pushBack (_stringArray select _i); | ||
_i = _i + 1; | ||
}; | ||
_returnArray append _replaceArray; | ||
_stringArray deleteRange [0, _i + _cp]; | ||
|
||
_string = toString _stringArray; | ||
_findIndex = _string find _pattern; | ||
while {_string find _find != -1} do { | ||
_index = _string find _find; | ||
_string = (_string select [0, _index]) + _replace + (_string select [_index + _offset]); | ||
}; | ||
_returnArray append _stringArray; | ||
toString _returnArray | ||
|
||
_string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed. ...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This checks for infinite loops when you would do something like: