Fix Issue 18166 - std.array.replace should be usable in @safe for dstrings

This commit is contained in:
Jack Stouffer 2018-03-09 14:21:06 -05:00
parent 9194efbf4d
commit 13cf12dfda

View file

@ -2268,8 +2268,15 @@ if (isInputRange!Range &&
copy(stuff, retval[from .. from + stuff.length]); copy(stuff, retval[from .. from + stuff.length]);
retval[from + stuff.length .. $] = subject[to .. $]; retval[from + stuff.length .. $] = subject[to .. $];
static if (is(T == const) || is(T == immutable))
{
return () @trusted { return cast(T[]) retval; } ();
}
else
{
return cast(T[]) retval; return cast(T[]) retval;
} }
}
else else
{ {
auto app = appender!(T[])(); auto app = appender!(T[])();
@ -2362,6 +2369,13 @@ if (isInputRange!Range &&
assert(replace(d, 5, 10, "⁴³²¹⁰"d) == "⁰¹²³⁴⁴³²¹⁰"d); assert(replace(d, 5, 10, "⁴³²¹⁰"d) == "⁰¹²³⁴⁴³²¹⁰"d);
} }
// Issue 18166
@safe pure unittest
{
auto str = replace("aaaaa"d, 1, 4, "***"d);
assert(str == "a***a");
}
/++ /++
Replaces elements from `array` with indices ranging from `from` Replaces elements from `array` with indices ranging from `from`
(inclusive) to `to` (exclusive) with the range `stuff`. Expands or (inclusive) to `to` (exclusive) with the range `stuff`. Expands or