Skip to content

Commit

Permalink
refactor: added constructor for ConfigSetting
Browse files Browse the repository at this point in the history
FossilOrigin-Name: e223e0266f42b985d7e84775016be2be2a1e990e868c5d0615271e252c167ffd
  • Loading branch information
thindil committed Jun 5, 2024
1 parent a4f6104 commit 95b7690
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 95b7690

Please sign in to comment.