Add ReplaceNodeOption flag (#710)

This commit is contained in:
Stef Heyenrath
2022-01-05 17:03:29 +01:00
committed by GitHub
parent e8e28c21a1
commit b153024de3
24 changed files with 563 additions and 174 deletions

View File

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

View 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;
}
}
}