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

findSplitBefore/After should have needle-less overloads #10000

Open
dlangBugzillaToGithub opened this issue Aug 30, 2013 · 1 comment
Open

findSplitBefore/After should have needle-less overloads #10000

dlangBugzillaToGithub opened this issue Aug 30, 2013 · 1 comment

Comments

@dlangBugzillaToGithub
Copy link

jakobovrum (@JakobOvrum) reported this on 2013-08-30T23:26:46Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=10933

CC List

Description

`find` has an overload that doesn't take a needle but requires an unary predicate function. `findSplitBefore` and `findSplitAfter` should have equivalent overloads.

Test illustrating use:

----
unittest
{
	import std.algorithm : findSplitBefore;
	import std.uni : isWhite;
	import std.string : stripLeft;

	immutable tests = [
		"prefix postfix lorem ipsum",
		"prefix\tpostfix lorem ipsum"
	];

	foreach(test; tests)
	{
		auto result = test.findSplitBefore!isWhite();
		assert(result[0] == "prefix");
		assert(result[1].stripLeft() == "postfix lorem ipsum");
	}
}
----

It would be especially useful because `until` is strictly lazy and thus can't be used with slicing to reproduce the above results.
@dlangBugzillaToGithub
Copy link
Author

luis commented on 2018-03-21T18:25:16Z

Yup, I've ran into the same issue multiple times. This last time with the plain findSplit; I don't recall if also with findSplitBefore/After.

This workaround works:

range.byCodeUnit.findSplit!((a, b) => a.isWhite)(" ");

Interestingly, if you use "" instead of " " it won't work, which arguably is a bug, since the predicate doesn't even use b.

@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants