Improve HLSL build error diagnostics for DX12 package

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:04:33 +02:00
1 親 14fa96998f
コミット e1d823a833
5ファイル変更
+94 -40

検索条件に一致するファイルはありません

+53 -1
ファイルの表示
@@ -1,4 +1,7 @@
namespace ComputeSharp.SourceGeneration.Extensions;
using System;
using System.Buffers;
namespace ComputeSharp.SourceGeneration.Extensions;
/// <summary>
/// Extension methods for <see cref="string"/> types.
@@ -14,4 +17,53 @@ internal static class StringExtensions
{
return text.Replace('.', '_').Replace('+', '_');
}
/// <summary>
/// Normalizes a given <see cref="string"/> instance to make it single line and with no repeated spaces.
/// </summary>
/// <param name="text">The input <see cref="string"/> instance to normalize.</param>
/// <returns>The normalized version of <paramref name="text"/>.</returns>
public static string NormalizeToSingleLine(this string text)
{
if (text is "")
{
return text;
}
char[] buffer = ArrayPool<char>.Shared.Rent(text.Length);
int index = 0;
char lastCharacter = '\0';
foreach (char newCharacter in text)
{
char pendingCharacter = newCharacter;
// Ignore '\r' characters
if (pendingCharacter is '\r')
{
continue;
}
// Convert newlines to spaces (this avoids VS droppping multiline diagnostics)
if (pendingCharacter is '\n')
{
pendingCharacter = ' ';
}
// Drop duplicate spaces
if (pendingCharacter is ' ' &&
lastCharacter is ' ')
{
continue;
}
buffer[index++] = lastCharacter = pendingCharacter;
}
text = buffer.AsSpan(0, index).ToString();
ArrayPool<char>.Shared.Return(buffer);
return text;
}
}