diff options
Diffstat (limited to 'webAO/iniParse.ts')
| -rw-r--r-- | webAO/iniParse.ts | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/webAO/iniParse.ts b/webAO/iniParse.ts index ca84c35..74bd764 100644 --- a/webAO/iniParse.ts +++ b/webAO/iniParse.ts @@ -9,10 +9,6 @@ const regexPatterns = { comment: /^\s*;.*$/, }; -const valueHandler = (matchKey: string, matchValue: string): string => { - return matchKey === "showname" ? matchValue : matchValue.toLowerCase(); -}; - const lineFilter = (value: string): boolean => { const isEmpty: boolean = value.length === 0; const isComment: boolean = regexPatterns.comment.test(value); @@ -31,24 +27,16 @@ const iniParse = (data: string): ParsedIni => { let currentSection: string | undefined; filteredLines.forEach((line) => { - const isParameter: boolean = regexPatterns.param.test(line); - const isSection: boolean = regexPatterns.section.test(line); - if (isParameter && currentSection) { - const match: RegExpMatchArray | null = line.match(regexPatterns.param); - - if (match) { - const matchKey: string = match[1].toLowerCase(); - const matchValue: string = match[2]; - parsedIni[currentSection][matchKey] = valueHandler(matchKey, matchValue); - } - } else if (isSection) { - const match: RegExpMatchArray | null = line.match(regexPatterns.section); - - if (match) { - const matchKey: string = match[1].toLowerCase(); - parsedIni[matchKey] = {}; - currentSection = matchKey; - } + const paramMatch: RegExpMatchArray | null = line.match(regexPatterns.param); + const sectionMatch: RegExpMatchArray | null = line.match(regexPatterns.section); + if (paramMatch && currentSection) { + const matchKey: string = paramMatch[1].toLowerCase(); + const matchValue: string = paramMatch[2]; + parsedIni[currentSection][matchKey] = matchValue; + } else if (sectionMatch) { + const matchKey: string = sectionMatch[1].toLowerCase(); + parsedIni[matchKey] = {}; + currentSection = matchKey; } }); |
