From 95b769032a5a76771c627924c81f398c823bbb50 Mon Sep 17 00:00:00 2001 From: thindil Date: Wed, 5 Jun 2024 04:51:27 +0000 Subject: [PATCH] refactor: added constructor for ConfigSetting FossilOrigin-Name: e223e0266f42b985d7e84775016be2be2a1e990e868c5d0615271e252c167ffd --- src/config.nim | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/config.nim b/src/config.nim index 2dde54a..7cee1ac 100644 --- a/src/config.nim +++ b/src/config.nim @@ -230,6 +230,19 @@ proc parseConfig*(configFile: FilePath; sections: var ExtendedNatural): tuple[ value: ConfigValue index: ExtendedNatural + proc initConfigSetting(name: ConfigName; value: ConfigValue; + index: ExtendedNatural): ConfigSetting {.raises: [], tags: [], + contractual.} = + ## Initialize a new instance of ConfigSetting object + ## + ## * name - the name of the setting from the file + ## * value - the value of the setting from the file + ## * index - the index of the setting in configOptions list. If it is an + ## invalid option, it is -1. + ## + ## Returns the new instance of ConfigSetting object + return ConfigSetting(name: name, value: value, index: index) + proc addFile(fileName: FilePath; sources: var seq[FilePath]) {.gcsafe, raises: [], tags: [RootEffect], contractual.} = ## Add the selected file as a source code to check for the program @@ -259,9 +272,9 @@ proc parseConfig*(configFile: FilePath; sections: var ExtendedNatural): tuple[ lineNumber.inc let configLine: seq[string] = line.split - setting: ConfigSetting = ConfigSetting(name: configLine[ - 0].toLowerAscii, value: configLine[1..^1].join(sep = " "), - index: configOptions.find(item = configLine[0].toLowerAscii)) + setting: ConfigSetting = initConfigSetting(name = configLine[ + 0].toLowerAscii, value = configLine[1..^1].join(sep = " "), + index = configOptions.find(item = configLine[0].toLowerAscii)) # Comment line, skip if line.startsWith(prefix = '#') or line.len == 0: continue