diff --git a/ICD.Common.Utils.Tests/StringUtilsTest.cs b/ICD.Common.Utils.Tests/StringUtilsTest.cs index 0a56a34..3e75cb3 100644 --- a/ICD.Common.Utils.Tests/StringUtilsTest.cs +++ b/ICD.Common.Utils.Tests/StringUtilsTest.cs @@ -170,5 +170,13 @@ namespace ICD.Common.Utils.Tests Assert.IsTrue(StringUtils.TryParse("true", out testVal)); Assert.AreEqual(true, testVal); } + + [TestCase("test", "\"test\"")] + [TestCase("\"test\"", "\"test\"")] + [TestCase("test test", "\"test test\"")] + public void EnquoteTest(string input, string expected) + { + Assert.AreEqual(expected, StringUtils.Enquote(input)); + } } } diff --git a/ICD.Common.Utils/StringUtils.cs b/ICD.Common.Utils/StringUtils.cs index 171fb1f..51af75b 100644 --- a/ICD.Common.Utils/StringUtils.cs +++ b/ICD.Common.Utils/StringUtils.cs @@ -688,5 +688,24 @@ namespace ICD.Common.Utils return output; } + + /// + /// Ensures the value starts and ends with a double quote. + /// + /// + /// + public static string Enquote(string value) + { + if (value == null) + throw new ArgumentNullException("value"); + + if (!value.StartsWith('"')) + value = '"' + value; + + if (!value.EndsWith('"')) + value += '"'; + + return value; + } } }