mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-11 10:45:05 +00:00
Merge branch 'Enquote' of Common/Utils into dev
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user