Remove HTTP status formatting/parsing from ResultView
Removed FormatHttpStatusInfo, ParseHttpStatusInfo, and the related Regex from the ResultView class. These methods are no longer needed and have been deleted to simplify the codebase.
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
using ReC.Domain.Constants;
|
using ReC.Domain.Constants;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Net;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
namespace ReC.Domain.Views;
|
namespace ReC.Domain.Views;
|
||||||
|
|
||||||
@@ -82,34 +80,4 @@ public class ResultView
|
|||||||
|
|
||||||
[Column("CHANGED_WHEN")]
|
[Column("CHANGED_WHEN")]
|
||||||
public DateTime? ChangedWhen { get; set; }
|
public DateTime? ChangedWhen { get; set; }
|
||||||
|
|
||||||
private static readonly Regex HttpStatusInfoRegex = new(@"^(\d{3})\s+(.+)$", RegexOptions.Compiled);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Formats an <see cref="HttpStatusCode"/> into a string in the form "statusCode statusName".
|
|
||||||
/// For example, <see cref="HttpStatusCode.NotFound"/> becomes "404 Not Found".
|
|
||||||
/// </summary>
|
|
||||||
public static string FormatHttpStatusInfo(HttpStatusCode statusCode)
|
|
||||||
{
|
|
||||||
var code = (int)statusCode;
|
|
||||||
var name = statusCode.ToString();
|
|
||||||
var displayName = Regex.Replace(name, "(?<!^)([A-Z])", " $1");
|
|
||||||
return $"{code} {displayName}";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Parses an Info string in the form "statusCode statusName" back into its components.
|
|
||||||
/// Returns <c>null</c> if the string does not match the expected format.
|
|
||||||
/// </summary>
|
|
||||||
public static (int StatusCode, string StatusName)? ParseHttpStatusInfo(string? info)
|
|
||||||
{
|
|
||||||
if (info is null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
var match = HttpStatusInfoRegex.Match(info);
|
|
||||||
if (!match.Success)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return (int.Parse(match.Groups[1].Value), match.Groups[2].Value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user