From f7b5d07c386bb3186da6f1dd4bd39fa0b295a15c Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Tue, 12 Jun 2018 13:31:44 -0400 Subject: [PATCH] feat: Adding enquote util method --- ICD.Common.Utils.Tests/StringUtilsTest.cs | 8 ++++++++ ICD.Common.Utils/StringUtils.cs | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) 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; + } } }