diff --git a/source/app.d b/source/app.d index 1c4b745..604f62d 100644 --- a/source/app.d +++ b/source/app.d @@ -1,5 +1,6 @@ import std.array : array, replace; import std.datetime : Clock; +import std.file : exists, isFile; import std.format : format; import std.getopt : defaultGetoptPrinter, getopt; import std.json : JSONValue; @@ -35,8 +36,11 @@ void main(string[] args) "mode" : "direct", "type_dm" : "any", "itdLPxx_bcl" : "true"]); - - loadSubstitutionFile(substitutionFileName); + + if (substitutionFileName.exists && substitutionFileName.isFile) + { + loadSubstitutionFile(substitutionFileName); + } auto currentTime = Clock.currTime; JSONValue j = ["time" : "%02s:%02s".format(currentTime.hour, currentTime.minute)]; diff --git a/source/substitution.d b/source/substitution.d index d743fe9..9275705 100644 --- a/source/substitution.d +++ b/source/substitution.d @@ -4,19 +4,11 @@ public: void loadSubstitutionFile(string fileName) { - import std.file : slurp, exists, isFile; + import std.file : slurp; import std.algorithm.iteration : each; - - if (fileName.exists && fileName.isFile) - { - auto data = slurp!(string, string)(fileName, `"%s" = "%s"`); - map = (string[string]).init; - data.each!(pair => map[pair[0]] = pair[1]); - } - else - { - map = (string[string]).init; - } + auto data = slurp!(string, string)(fileName, `"%s" = "%s"`); + map = (string[string]).init; + data.each!(pair => map[pair[0]] = pair[1]); } auto substitute(string s) @safe nothrow