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

add range support to std.string.stripLeft #3187

Merged
merged 1 commit into from
Apr 26, 2015

Conversation

WalterBright
Copy link
Member

unit test coverage 100%

@JakobOvrum
Copy link
Member

std.algorithm.mutation already has generic strip, stripLeft and stripRight. The string versions that use isWhite should probably be composed in terms of the generic ones?

@WalterBright
Copy link
Member Author

Unfortunately, the generic strip does not decode ranges of char or wchar:

import std.stdio;
import std.algorithm;
import std.utf;
import std.array;

void main() {
    assert("ëëêéüŗōpéêëë".strip('ë') == "êéüŗōpéê"); // works
    assert("ëëêéüŗōpéêëë".byCodeUnit.strip('ë').array == "êéüŗōpéê"); // fails
}


import std.utf : byChar;
import std.array;
assert(stripLeft(" hello world "w.byChar).array ==
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of calling .array, you should be able to use .equal to verify equality and you won't have an allocation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Being a test case, the allocation doesn't matter.

@JakobOvrum
Copy link
Member

While I would prefer changing std.algorithm's strip functions and deferring to those, the interface would be the same and this is a tiny patch, so LGTM.

@JakobOvrum
Copy link
Member

Auto-merge toggled on

JakobOvrum added a commit that referenced this pull request Apr 26, 2015
add range support to std.string.stripLeft
@JakobOvrum JakobOvrum merged commit 50ae113 into dlang:master Apr 26, 2015
@WalterBright WalterBright deleted the stripLeft-Range branch April 26, 2015 19:33
@aG0aep6G
Copy link
Contributor

This introduced a regression: https://issues.dlang.org/show_bug.cgi?id=14827

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.

5 participants