From 99d36745ebc841311ccc7a51c03855b76ec84ed0 Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Mon, 10 Apr 2017 21:07:53 +0200 Subject: [PATCH] Moved check for the existance of the substitution file from loadSubstitutionFile to main --- source/app.d | 8 ++++++-- source/substitution.d | 16 ++++------------ 2 files changed, 10 insertions(+), 14 deletions(-) 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