diff --git a/dub.json b/dub.json index 7f3fc7f..7248b91 100644 --- a/dub.json +++ b/dub.json @@ -34,5 +34,6 @@ "targetName": "readconf", "dependencies": { "singlog": "~>0.1.0" - } + }, + "version": "0.1.4" } \ No newline at end of file diff --git a/source/readconf.d b/source/readconf.d index 92e9825..81b95d8 100644 --- a/source/readconf.d +++ b/source/readconf.d @@ -6,6 +6,11 @@ import std.regex; import std.meta; import singlog; +/** + * Read config object + */ +alias rc = Config.file; + class Config { private: @@ -15,7 +20,7 @@ private: bool readed = false; const string pattern = "^( |\\t)*(((\\w(\\w|-)+)(( |\\t)*(=>|=){1}" ~ "( |\\t)*)(?!\\/(\\/|\\*))(([^ >\"'=\\n\\t#;].*?)|(\"(.+)\")" - ~ "|('(.+)')){1})|(\\[(\\w(\\w|-)+)\\])|(\\[()\\]))( |\\t)*" + ~ "|('(.+)')){1})|(\\[(\\w(\\w|-)+)\\])|(\\[\\]))( |\\t)*" ~ "(( |\\t)(#|;|\\/\\/|\\/\\*).*)?$"; /** @@ -58,9 +63,9 @@ private: } // values int group = 11; - if (match[group][0] == '\'') + if (match[group][0] == '\"') group = 14; - else if (match[group][0] == '\"') + else if (match[group][0] == '\'') group = 16; if (sectionName !in this.sections) @@ -111,10 +116,24 @@ public: readConfig(); } - @property ConfigSection section(string section = "[]") + /** + * Get the section + * Params: + * section = section name (default main "[]") + */ + @property ConfigSection sectionName(string section = "[]") { return sections[section]; } + + /** + * Section name + * + * Get the section + * Params: + * section = section name (default main "[]") + */ + alias sn = sectionName; } struct ConfigSection diff --git a/tests/test.d b/tests/test.d index 280c692..796a6f0 100644 --- a/tests/test.d +++ b/tests/test.d @@ -2,20 +2,20 @@ import readconf; unittest { - Config.file.read("./tests/settings.conf"); + rc.read("./tests/settings.conf"); - assert(Config.file.key("value1") == "This is the full value"); - assert(Config.file.key("value2") == "Take the value in quotation marks"); - assert(Config.file.key("value3") == "Or take in apostrophes"); - assert(Config.file.key("value4") == "You can also comment"); - assert(Config.file.key("value5") == "So you can also comment"); - assert(Config.file.key("value6") == "\"And you can even do that!\""); - assert(Config.file.key("value7") == "1234567890"); - assert(Config.file.key("value8") == "12345.67890"); - assert(Config.file.key("value9") == "You can use large margins"); - assert(Config.file.key("value10").empty); - assert(Config.file.key("value11").empty); - assert(Config.file.key("value12") == "//path"); + assert(rc.sn.key("value1") == "This is the full value"); + assert(rc.sn.key("value2") == "Take the value in quotation marks"); + assert(rc.sn.key("value3") == "Or take in apostrophes"); + assert(rc.sn.key("value4") == "You can also comment"); + assert(rc.sn.key("value5") == "So you can also comment"); + assert(rc.sn.key("value6") == "\"And you can even do that!\""); + assert(rc.sn.key("value7") == "1234567890"); + assert(rc.sn.key("value8") == "12345.67890"); + assert(rc.sn.key("value9") == "You can use large margins"); + assert(rc.sn.key("value10").empty); + assert(rc.sn.key("value11").empty); + assert(rc.sn.key("value12") == "//path"); }