From 7f3611a5ed542f5436d61b9da39937b89fdf0065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Nordl=C3=B6w?= Date: Tue, 2 Sep 2014 14:14:51 +0200 Subject: [PATCH] Add empty check for haystack range r in skipOver() Remove space --- std/algorithm.d | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/std/algorithm.d b/std/algorithm.d index ec37d88a6..bc107b217 100644 --- a/std/algorithm.d +++ b/std/algorithm.d @@ -6164,7 +6164,7 @@ unchanged and return $(D false). bool skipOver(alias pred = "a == b", R, E)(ref R r, E e) if (is(typeof(binaryFun!pred(r.front, e)))) { - if (!binaryFun!pred(r.front, e)) + if (r.empty || !binaryFun!pred(r.front, e)) return false; r.popFront(); return true; @@ -6183,6 +6183,9 @@ unittest { assert(r == ["abc", "def", "hij"]); assert(skipOver!((a, b) => a.equal(b))(r, e)); assert(r == ["def", "hij"]); + + auto s2 = ""; + assert(!s2.skipOver('a')); } /* (Not yet documented.)