Skip to content

Commit

Permalink
implements #16 - added a helper method for reading multi-line values …
Browse files Browse the repository at this point in the history
…as one-line text
  • Loading branch information
salaros committed Mar 15, 2021
1 parent ee60daf commit 0875582
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,19 @@ public virtual string GetValue(string sectionName, string keyName, string defaul
return GetRawValue(sectionName, keyName, defaultValue);
}

/// <summary>Joins a multiline value using a separator.</summary>
/// <param name="sectionName">Name of the section.</param>
/// <param name="keyName">Name of the key.</param>
/// <param name="separator">The separator (defaults to whitespace).</param>
/// <returns>
/// <br />
/// </returns>
public string JoinMultilineValue(string sectionName, string keyName, string separator = " ")
{
var multiLineVal = GetValue(sectionName, keyName);
return string.Join(separator, multiLineVal?.Split(new[] { Settings.NewLine }, StringSplitOptions.None));
}

/// <summary>
/// Gets the value.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions tests/ConfigParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,25 @@ from table
Assert.Equal("from table", arrayValues[1]);
Assert.Equal("where ID = '5'", arrayValues[2]);
}

[Fact]
public void JoinMultilineValueWorks()
{
// Set up
var settings = new ConfigParserSettings { MultiLineValues = MultiLineValues.Simple };
var configFile = new ConfigParser(
@"[Advanced]
ExampleValue = Lorem ipsum dolor sit amet
consectetur adipiscing elit
sed do eiusmod tempor incididunt
",
settings);

// Act
var multiLineJoint = configFile.JoinMultilineValue("Advanced", "ExampleValue", " ");

// Assert
Assert.Equal("Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt", multiLineJoint);
}
}
}

0 comments on commit 0875582

Please sign in to comment.