From 2ef09b95a3d7e94163f11b2e628f5f087801abbc Mon Sep 17 00:00:00 2001 From: Robert burner Schadek Date: Mon, 19 Oct 2015 01:04:37 +0200 Subject: [PATCH] std.string.strip_alias_string_fix make strip take custom types again that have an alias this to string test stuff --- std/string.d | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/std/string.d b/std/string.d index b01d86373..fb13b9d02 100644 --- a/std/string.d +++ b/std/string.d @@ -2943,6 +2943,16 @@ unittest Returns: slice of $(D str) stripped of leading and trailing whitespace. +/ +auto strip(Range)(auto ref Range str) + if (!(isSomeString!Range || + isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && + isSomeChar!(ElementEncodingType!Range)) + && is(StringTypeOf!Range)) +{ + return stripRight(stripLeft(str)); +} + +/// Ditto auto strip(Range)(Range str) if (isSomeString!Range || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && @@ -2967,6 +2977,18 @@ auto strip(Range)(Range str) "hello world"); } +@safe pure unittest +{ + static struct TestStruct + { + string s; + alias s this; + } + + string s = " hello world "; + assert(strip(s) == strip(TestStruct(s))); +} + @safe pure unittest { import std.conv : to;