Skip to content

Commit a7ace64

Browse files
committed
Implement multiline value parsing
1 parent b8b396c commit a7ace64

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

Src/ConfigurationReader.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ private static void Parse(StringReader reader, Configuration config)
8989
}
9090
else // Setting
9191
{
92-
var setting =
93-
ParseSetting(Configuration.IgnoreInlineComments ? line : lineWithoutComment, lineNumber);
92+
var setting = ParseSetting(
93+
Configuration.IgnoreInlineComments ? line : lineWithoutComment, reader, ref lineNumber);
9494

9595
if (!Configuration.IgnoreInlineComments)
9696
{
@@ -183,7 +183,7 @@ private static Section ParseSection(string line, int lineNumber)
183183
: new Section(sectionName);
184184
}
185185

186-
private static Setting ParseSetting(string line, int lineNumber)
186+
private static Setting ParseSetting(string line, StringReader reader, ref int lineNumber)
187187
{
188188
// Format(s) of a setting:
189189
// 1) <name> = <value>
@@ -239,6 +239,35 @@ private static Setting ParseSetting(string line, int lineNumber)
239239

240240
var settingValue = line.Substring(equalSignIndex + 1).Trim();
241241

242+
// A setting value that only consists of a quote mark can indicate a multiline value.
243+
// Read it until we encounter a line that consists of a single quote mark.
244+
if (settingValue == "[[")
245+
{
246+
var settingValueBuffer = new StringBuilder();
247+
settingValueBuffer.Append("[[");
248+
249+
while ((line = reader.ReadLine()) != null)
250+
{
251+
++lineNumber;
252+
253+
if (line == "]]")
254+
{
255+
break;
256+
}
257+
258+
settingValueBuffer.AppendLine(line);
259+
}
260+
261+
if (settingValueBuffer.Length > 0 && settingValueBuffer[settingValueBuffer.Length - 1] == '\n')
262+
{
263+
settingValueBuffer.Remove(settingValueBuffer.Length - 1, 1);
264+
}
265+
266+
settingValueBuffer.Append("]]");
267+
268+
settingValue = settingValueBuffer.ToString();
269+
}
270+
242271
return new Setting(settingName, settingValue);
243272
}
244273

0 commit comments

Comments
 (0)