namespace Insight.Web.Extensions;

public static class StringExtensions
{
    public static string? Escape(this string? value)
    {
        if (value is null) return value;

        return value.Replace("(", @"\(").Replace(")", @"\)").Replace(@"\", @"\\");
    }

    public static string? UriEscape(this string? value, bool revert = false)
    {
        if (value is null) return value;

        if (revert)
        {
            value = value.Replace(@"$pc", @"%");
            value = value.Replace(@"$fs", @"/");
            value = value.Replace(@"$bs", @"\");
        }
        else
        {
            value = value.Replace(@"%", @"$pc");
            value = value.Replace(@"/", @"$fs");
            value = value.Replace(@"\", @"$bs");
        }

        return value;
    }
}