Skip to content

Commit 0875582

Browse files
committed
implements #16 - added a helper method for reading multi-line values as one-line text
1 parent ee60daf commit 0875582

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/ConfigParser.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ public virtual string GetValue(string sectionName, string keyName, string defaul
208208
return GetRawValue(sectionName, keyName, defaultValue);
209209
}
210210

211+
/// <summary>Joins a multiline value using a separator.</summary>
212+
/// <param name="sectionName">Name of the section.</param>
213+
/// <param name="keyName">Name of the key.</param>
214+
/// <param name="separator">The separator (defaults to whitespace).</param>
215+
/// <returns>
216+
/// <br />
217+
/// </returns>
218+
public string JoinMultilineValue(string sectionName, string keyName, string separator = " ")
219+
{
220+
var multiLineVal = GetValue(sectionName, keyName);
221+
return string.Join(separator, multiLineVal?.Split(new[] { Settings.NewLine }, StringSplitOptions.None));
222+
}
223+
211224
/// <summary>
212225
/// Gets the value.
213226
/// </summary>

tests/ConfigParserTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,25 @@ from table
8181
Assert.Equal("from table", arrayValues[1]);
8282
Assert.Equal("where ID = '5'", arrayValues[2]);
8383
}
84+
85+
[Fact]
86+
public void JoinMultilineValueWorks()
87+
{
88+
// Set up
89+
var settings = new ConfigParserSettings { MultiLineValues = MultiLineValues.Simple };
90+
var configFile = new ConfigParser(
91+
@"[Advanced]
92+
ExampleValue = Lorem ipsum dolor sit amet
93+
consectetur adipiscing elit
94+
sed do eiusmod tempor incididunt
95+
",
96+
settings);
97+
98+
// Act
99+
var multiLineJoint = configFile.JoinMultilineValue("Advanced", "ExampleValue", " ");
100+
101+
// Assert
102+
Assert.Equal("Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt", multiLineJoint);
103+
}
84104
}
85105
}

0 commit comments

Comments
 (0)