commit 4461987947b5fed5b407befd47f8bab86c5d1634 Author: Alexander Date: Thu May 5 22:32:47 2022 +0300 Добавлен модуль cfg.d diff --git a/README.md b/README.md new file mode 100644 index 0000000..67d646b --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Наработки D + +**Содержит модули:** +- [cfg.d](cdf.d) - чтение конфигурационного файла в формате `Параметр = Значение` \ No newline at end of file diff --git a/cfg.d b/cfg.d new file mode 100644 index 0000000..bd3a6f0 --- /dev/null +++ b/cfg.d @@ -0,0 +1,24 @@ +module azh.cfg; + +import std.stdio; +import std.regex; + +string[string] readConfigFile(string path) +{ + auto file = File(path, "r"); + string[string] properties; + auto p_property = regex(r"^(\w+) *= *(.+)$", "m"); + while (!file.eof()) + { + string line = file.readln(); + auto m = matchFirst(line, p_property); + if (m) + { + auto property = m[1]; + auto value = m[2]; + properties[property] = value; + } + } + file.close(); + return properties; +}