Merge branch 'Enquote' of Common/Utils into dev

This commit is contained in:
Jack Kanarish
2018-06-12 18:07:48 +00:00
committed by Gogs
2 changed files with 27 additions and 0 deletions

View File

@@ -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));
}
}
}

View File

@@ -688,5 +688,24 @@ namespace ICD.Common.Utils
return output;
}
/// <summary>
/// Ensures the value starts and ends with a double quote.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string Enquote(string value)
{
if (value == null)
throw new ArgumentNullException("value");
if (!value.StartsWith('"'))
value = '"' + value;
if (!value.EndsWith('"'))
value += '"';
return value;
}
}
}