Skip to content
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

Merged
merged 3 commits into from
May 18, 2016
Merged

Replace replace #331

merged 3 commits into from
May 18, 2016

Conversation

BaerMitUmlaut
Copy link
Contributor

This PR replaces the replace function. The old one does not work properly with some characters (for example öüäß) due to buggy BI commands:

("ü" splitString "") apply {toArray _x}
-> [[65533],[65533]]
"abcßdef" find "ß"
-> 3
"abcßdef" find "d"
-> 5

It also adds params checking and doesn't use any toArray/toString stuff anymore.

// ----------------------------------------------------------------------------
params [["_string", "", [""]], ["_find", "", [""]], ["_replace", "", [""]]];
private ["_offset", "_index"];
if (_find == "" || {_replace find _find != -1}) exitWith {_string};
Copy link
Contributor

@commy2 commy2 May 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. ...?

Copy link
Contributor Author

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:

["Hello", "e", "ee"] call CBA_fnc_replace;

@commy2
Copy link
Contributor

commy2 commented May 17, 2016

Before:

["TEST","E","EA"] call CBA_fnc_replace
"TEAST"

After:

["TEST","E","EA"] call CBA_fnc_replace
"TEST"

@BaerMitUmlaut
Copy link
Contributor Author

This works now:

["TEST","E","EA"] call CBA_fnc_replace
-> "TEAST"

@commy2
Copy link
Contributor

commy2 commented May 17, 2016

Passes the test now

0 spawn compile preprocessFileLineNumbers  "\x\cba\addons\strings\test_strings.sqf"

The benefit of this PR:
Before:

["Mörser","ö","oe"] call CBA_fnc_replace
-> "Moeser"

After:

["Mörser","ö","oe"] call CBA_fnc_replace
-> "Moerser"

We should probably add that and "TEAST" to the test.

@commy2
Copy link
Contributor

commy2 commented May 17, 2016

Performance:
["Mörser","ö","oe"] call CBA_fnc_replace

Before: 0.0525 ms
After: 0.0432 ms

@Killswitch00
Copy link
Contributor

Agree - please add the two new tests to the unit test suite.

@BaerMitUmlaut
Copy link
Contributor Author

Those two tests have been added.

@Killswitch00 Killswitch00 merged commit 9a43d4c into CBATeam:master May 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants