This repository has been archived on 2022-05-05. You can view files and clone it, but cannot push or open issues or pull requests.
azh/cfg_oneline.d

27 lines
683 B
D

module azh.cfg_oneline;
import std.regex;
import std.stdio;
import std.algorithm;
import std.array;
import std.typecons;
import std.functional;
/**
* Тестовая функция
* Params:
* path = путь к файлу конфигурации
* Returns: ассоциативный массив ['Параметр' => 'Значение']
*/
string[string] readConfigFile(string path)
{
auto p_property = regex(r"^ *(\w+) *= *(.+) *$", "r");
const properties = File(path)
.byLineCopy
.map!(line => matchFirst(line, p_property))
.filter!(m => !m.empty) // OR: .filter!(not!empty)
.map!(m => tuple(m[1], m[2]))
.assocArray;
return properties;
}