//------------------------------------------------------------------------------ public static String NormalizeLineEndings(String text, EolType eol) { String eolString = (eol == EolType.Unix) ? "\n" : "\r\n"; String normalized = Regex.Replace(text, @"\r*\n", eolString, RegexOptions.Multiline); return(normalized); }
// // Public methods // //------------------------------------------------------------------------------ public static String EolTypeToEolString(EolType eolType) { switch (eolType) { case EolType.Unix: return("\n"); case EolType.Windows: return("\r\n"); } throw new Exception(String.Format("Unsupported EOL string!")); }
public async Task ValidCsprojFormatPathLoadUtf8BomTest(string csprojPath, EolType eol, string eolString) { // delay to avoid file read conflict await Task.Delay(TimeSpan.FromMilliseconds(100)); // Load Should be success var csproj = Project.Load(csprojPath); csproj.Root.ToString().Should().NotBeNullOrEmpty(); // Encoding csproj.Encoding.Should().Be(new UTF8Encoding(true)); // Eol csproj.Eol.Should().Be(eol); csproj.Eol.ToEolString().Should().Be(eolString); // Initialized Should be true csproj.Initialized.Should().BeTrue(); // TODO: Save test }
public async Task ValidCsprojFormatStreamLoadUtf8Test(string csprojPath, EolType eol, string eolString) { // delay to avoid file read conflict await Task.Delay(TimeSpan.FromMilliseconds(100)); // Load Should be success using (var stream = File.Open(csprojPath, FileMode.Open, FileAccess.Read)) { var csproj = Project.Load(stream); csproj.Root.ToString().Should().NotBeNullOrEmpty(); // Encoding csproj.Encoding.Should().Be(new UTF8Encoding(false)); // Eol csproj.Eol.Should().Be(eol); csproj.Eol.ToEolString().Should().Be(eolString); // Initialized Should be true csproj.Initialized.Should().BeTrue(); // TODO: Save test } }
public static string ToEolString(this EolType eol) => eol == EolType.CRLF ? "\r\n" : "\n";