bayernfahrplan/source/substitution.d

30 lines
535 B
D
Raw Normal View History

2016-12-02 12:46:39 +01:00
module substitution;
public:
void loadSubstitutionFile(string fileName)
{
import std.file : slurp, exists, isFile;
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 substitute(string s)
{
return s in map ? map[s] : s;
}
private:
string[string] map;