Any update on: named paramters DIP and string interpolation?
cc
cc at nevernet.com
Fri Sep 2 17:17:18 UTC 2022
On Friday, 26 August 2022 at 12:57:58 UTC, Martin Tschierschke
wrote:
> Anything new about the status of this language enhancements?
>
> Best regards
> mt.
If you need string interpolation yesterday and don't mind using
mixins...
```d
import std.stdio;
import std.string;
import std.array;
import std.range.primitives;
string mwrite(string str) @safe pure {
size_t istart;
bool inword = false;
auto result = appender!(string[]);
auto vars = appender!(string[]);
foreach (i, dchar c; str) {
if (!inword) {
if (c == '{') {
result.put(str[istart .. i]);
istart = i+1;
inword = true;
}
} else {
if (c == '}') {
result.put("%s");
vars.put(str[istart .. i]);
istart = i+1;
inword = false;
}
}
}
if (!inword && istart < str.length)
put(result, str[istart .. $]);
return format!`writef("%s", %s);`(result.data.join,
vars.data.join(`, `));
}
string mwriteln(string str) @safe pure {
string result = mwrite(str);
enum toReplace = "writef(";
return "writefln(" ~ result[toReplace.length .. $];
}
void main() {
int x = 4;
float y = 3.5;
mixin(mwriteln(`X:{x} Y:{y}`));
mixin(mwriteln(`Which is larger? {x>y?"X":"Y"}`));
}
```
More information about the Digitalmars-d
mailing list