using System.Text.RegularExpressions;
namespace API.Helpers;
#nullable enable
public static class StringHelper
{
///
/// Used to squash duplicate break and new lines with a single new line.
///
/// Test br br Test -> Test br Test
///
///
public static string? SquashBreaklines(string? summary)
{
if (string.IsNullOrWhiteSpace(summary))
{
return null;
}
// First standardize all br tags to
format
summary = Regex.Replace(summary, @"
", "
", RegexOptions.IgnoreCase | RegexOptions.Compiled);
// Replace multiple consecutive br tags with a single br tag
summary = Regex.Replace(summary, @"(?:
\s*)+", "
", RegexOptions.IgnoreCase | RegexOptions.Compiled);
// Normalize remaining whitespace (replace multiple spaces with a single space)
summary = Regex.Replace(summary, @"\s+", " ").Trim();
return summary.Trim();
}
///
/// Removes the (Source: MangaDex) type of tags at the end of descriptions from AL
///
///
///
public static string? RemoveSourceInDescription(string? description)
{
return description?.Trim();
}
}