mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-27 02:38:30 +02:00
Add ReplaceNodeOption flag (#710)
This commit is contained in:
@@ -10,6 +10,33 @@ namespace WireMock.Util
|
||||
{
|
||||
internal static class JsonUtils
|
||||
{
|
||||
public static bool TryParseAsComplexObject(string strInput, out JToken token)
|
||||
{
|
||||
token = null;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(strInput))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
strInput = strInput.Trim();
|
||||
if ((!strInput.StartsWith("{") || !strInput.EndsWith("}")) && (!strInput.StartsWith("[") || !strInput.EndsWith("]")))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Try to convert this string into a JToken
|
||||
token = JToken.Parse(strInput);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static string Serialize<T>(T value)
|
||||
{
|
||||
return JsonConvert.SerializeObject(value, JsonSerializationConstants.JsonSerializerSettingsIncludeNullValues);
|
||||
|
||||
42
src/WireMock.Net/Util/StringUtils.cs
Normal file
42
src/WireMock.Net/Util/StringUtils.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace WireMock.Util
|
||||
{
|
||||
internal static class StringUtils
|
||||
{
|
||||
public static bool TryParseQuotedString(string value, out string result, out char quote)
|
||||
{
|
||||
result = null;
|
||||
quote = '\0';
|
||||
|
||||
if (value == null || value.Length < 2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
quote = value[0]; // This can be single or a double quote
|
||||
if (quote != '"' && quote != '\'')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value.Last() != quote)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
result = Regex.Unescape(value.Substring(1, value.Length - 2));
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore Exception, just continue and return false.
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user