Moved check for the existance of the substitution file from

loadSubstitutionFile to main
This commit is contained in:
Johannes Loher 2017-04-10 21:07:53 +02:00
parent d657873f9f
commit 99d36745eb
2 changed files with 10 additions and 14 deletions

View file

@ -1,5 +1,6 @@
import std.array : array, replace; import std.array : array, replace;
import std.datetime : Clock; import std.datetime : Clock;
import std.file : exists, isFile;
import std.format : format; import std.format : format;
import std.getopt : defaultGetoptPrinter, getopt; import std.getopt : defaultGetoptPrinter, getopt;
import std.json : JSONValue; import std.json : JSONValue;
@ -36,7 +37,10 @@ void main(string[] args)
"type_dm" : "any", "type_dm" : "any",
"itdLPxx_bcl" : "true"]); "itdLPxx_bcl" : "true"]);
if (substitutionFileName.exists && substitutionFileName.isFile)
{
loadSubstitutionFile(substitutionFileName); loadSubstitutionFile(substitutionFileName);
}
auto currentTime = Clock.currTime; auto currentTime = Clock.currTime;
JSONValue j = ["time" : "%02s:%02s".format(currentTime.hour, currentTime.minute)]; JSONValue j = ["time" : "%02s:%02s".format(currentTime.hour, currentTime.minute)];

View file

@ -4,20 +4,12 @@ public:
void loadSubstitutionFile(string fileName) void loadSubstitutionFile(string fileName)
{ {
import std.file : slurp, exists, isFile; import std.file : slurp;
import std.algorithm.iteration : each; import std.algorithm.iteration : each;
if (fileName.exists && fileName.isFile)
{
auto data = slurp!(string, string)(fileName, `"%s" = "%s"`); auto data = slurp!(string, string)(fileName, `"%s" = "%s"`);
map = (string[string]).init; map = (string[string]).init;
data.each!(pair => map[pair[0]] = pair[1]); data.each!(pair => map[pair[0]] = pair[1]);
} }
else
{
map = (string[string]).init;
}
}
auto substitute(string s) @safe nothrow auto substitute(string s) @safe nothrow
{ {