dev #1

Merged
alexander merged 9 commits from dev into master 2023-03-26 08:38:23 +00:00
1 changed files with 68 additions and 51 deletions
Showing only changes of commit 5b3141cb16 - Show all commits

View File

@ -11,7 +11,7 @@ class Config
private: private:
static Config config; static Config config;
string path; string path;
Partition[string] partitions; ConfigSection[string] sections;
bool readed = false; bool readed = false;
const string pattern = "^( |\\t)*(((\\w(\\w|-)+)(( |\\t)*(=>|=){1}" const string pattern = "^( |\\t)*(((\\w(\\w|-)+)(( |\\t)*(=>|=){1}"
~ "( |\\t)*)(?!\\/(\\/|\\*))(([^ >\"'=\\n\\t#;].*?)|(\"(.+)\")" ~ "( |\\t)*)(?!\\/(\\/|\\*))(([^ >\"'=\\n\\t#;].*?)|(\"(.+)\")"
@ -35,21 +35,38 @@ private:
auto regular = regex(this.pattern, "m"); auto regular = regex(this.pattern, "m");
// if main section
string sectionName = "[]";
while (!configuration.eof()) while (!configuration.eof())
{ {
string line = configuration.readln(); string line = configuration.readln();
auto match = matchFirst(line, regular); auto match = matchFirst(line, regular);
if (match) if (match)
{ {
int group = 5; // if again main section
if (match[group].length) if (match[20].length)
{ {
if (match[group][0] == '\'') sectionName = match[20];
group = 10; continue;
else if (match[group][0] == '\"')
group = 8;
} }
this.properties[match[1]] = PP(match[1], match[group]); // if other section
if (match[17].length)
{
sectionName = match[18];
continue;
}
// values
int group = 11;
if (match[group][0] == '\'')
group = 14;
else if (match[group][0] == '\"')
group = 16;
if (sectionName !in this.sections)
this.sections[sectionName] = ConfigSection(sectionName);
this.sections[sectionName].add(ConfigParameter(match[4], match[group]));
} }
} }
@ -94,16 +111,56 @@ public:
readConfig(); readConfig();
} }
Partition part(string partishion = "") @property ConfigSection section(string section = "[]")
{ {
return sections[section];
}
}
struct ConfigSection
{
private string name = "[]";
private ConfigParameter[string] parameters;
/**
* Checking for the presence of a partition
* Returns: true if the parameter is missing, otherwise false
*/
@property bool empty()
{
return this.parameters.length == 0;
}
/**
* Get the parameter value
* Params:
* key = parameter from the configuration file
* Returns: the value of the parameter in the PP structure view
*/
ConfigParameter key(string key)
{
return key in this.parameters ? this.parameters[key] : ConfigParameter();
}
/**
* Get all keys and their values
* Returns: collection of properties structures PP
*/
ConfigParameter[string] keys()
{
return this.parameters;
}
void add(ConfigParameter parameter)
{
this.parameters[parameter.property] = parameter;
} }
} }
/** /**
* Parameter and its value with the ability to convert to the desired data type * Parameter and its value with the ability to convert to the desired data type
*/ */
struct Parameter struct ConfigParameter
{ {
private string property; private string property;
private string value; private string value;
@ -139,43 +196,3 @@ struct Parameter
} }
} }
} }
struct Partition
{
private string name = "[]";
private Parameter[string] parameters;
/**
* Checking for the presence of a partition
* Returns: true if the parameter is missing, otherwise false
*/
@property bool empty()
{
return this.parameters.length == 0;
}
/**
* Get the parameter value
* Params:
* key = parameter from the configuration file
* Returns: the value of the parameter in the PP structure view
*/
Parameter key(string key)
{
return key in this.parameters ? this.parameters[key] : Parameter();
}
/**
* Get all keys and their values
* Returns: collection of properties structures PP
*/
Parameter[string] keys()
{
return this.parameters;
}
bool add(Parameter parameter)
{
}
}