1 module nxt.inplace_substitution;
2 
3 import std.ascii : isASCII;
4 
5 /** Returns: in-place substitution `from` by `to` in `source`. */
6 char[] substituteASCIIInPlace(char from, char to)(return scope char[] source) @safe pure nothrow @nogc
7 if (isASCII(from) &&
8     isASCII(to))
9 {
10     foreach (ref char ch; source)
11     {
12         if (ch == from)
13         {
14             ch = to;
15         }
16     }
17     return source;
18 }
19 
20 ///
21 @safe pure nothrow @nogc unittest
22 {
23     const x = "_a_b_c_";
24     char[7] y = x;
25     y.substituteASCIIInPlace!('_', ' ');
26     assert(y[] == " a b c ");
27 }