27 lines
683 B
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;
|
||
|
}
|