From 08755820fbfaf52f6ceba8cd6543d8c65e5b0e5f Mon Sep 17 00:00:00 2001 From: Salaros Date: Mon, 15 Mar 2021 19:44:16 +0300 Subject: [PATCH] implements #16 - added a helper method for reading multi-line values as one-line text --- src/ConfigParser.cs | 13 +++++++++++++ tests/ConfigParserTests.cs | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/ConfigParser.cs b/src/ConfigParser.cs index 2aa34bc..c9fde03 100644 --- a/src/ConfigParser.cs +++ b/src/ConfigParser.cs @@ -208,6 +208,19 @@ public virtual string GetValue(string sectionName, string keyName, string defaul return GetRawValue(sectionName, keyName, defaultValue); } + /// Joins a multiline value using a separator. + /// Name of the section. + /// Name of the key. + /// The separator (defaults to whitespace). + /// + ///
+ ///
+ 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)); + } + /// /// Gets the value. /// diff --git a/tests/ConfigParserTests.cs b/tests/ConfigParserTests.cs index 152ff12..ea2ef28 100644 --- a/tests/ConfigParserTests.cs +++ b/tests/ConfigParserTests.cs @@ -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); + } } }