using System;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text.RegularExpressions;
namespace ComputeSharp.Shaders.Extensions
{
///
/// A that provides extension methods for the type
///
internal static class StringExtensions
{
///
/// Removes the left padding for an input multiline
///
/// The input to process
/// A left-aligned with the same text as the input
[Pure]
public static string RemoveLeftPadding(this string text)
{
string[] lines = text.Split(Environment.NewLine);
int spaces = text.TakeWhile(c => c == ' ').Count();
Regex regex = new Regex($"^{new string(Enumerable.Repeat(' ', spaces).ToArray())}");
return lines.Aggregate(string.Empty, (result, line) => $"{result}{Environment.NewLine}{regex.Replace(line, string.Empty)}");
}
}
}