StringBuilderExtensions.cs 951 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Text;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. static class StringBuilderExtensions
  6. {
  7. public static void AppendIndentedLines(this StringBuilder sb, string lines, string indentation)
  8. {
  9. sb.EnsureCapacity(sb.Length + lines.Length);
  10. var charIndex = 0;
  11. while (charIndex < lines.Length)
  12. {
  13. var nextNewLineIndex = lines.IndexOf(Environment.NewLine, charIndex, StringComparison.Ordinal);
  14. if (nextNewLineIndex == -1)
  15. {
  16. nextNewLineIndex = lines.Length;
  17. }
  18. sb.Append(indentation);
  19. for (var i = charIndex; i < nextNewLineIndex; i++)
  20. {
  21. sb.Append(lines[i]);
  22. }
  23. sb.AppendLine();
  24. charIndex = nextNewLineIndex + Environment.NewLine.Length;
  25. }
  26. }
  27. }
  28. }