Issue 10933 - findSplitBefore/After should have needle-less overloads
Summary: findSplitBefore/After should have needle-less overloads
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-30 23:26 UTC by Jakob Ovrum
Modified: 2024-12-01 16:18 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jakob Ovrum 2013-08-30 23:26:46 UTC
`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.
Comment 1 Luís Marques 2018-03-21 18:25:16 UTC
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.
Comment 2 dlangBugzillaToGithub 2024-12-01 16:18:40 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10000

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB