Files
wehub-resource-sync b957a53def
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:21:23 +08:00

25 lines
884 B
C#

// Copyright (c) Microsoft. All rights reserved.
// ReSharper disable InconsistentNaming
public static class Utils
{
// Function used to wrap long lines of text
public static string WordWrap(string text, int maxLineLength)
{
var result = new StringBuilder();
int i;
var last = 0;
var space = new[] { ' ', '\r', '\n', '\t' };
do
{
i = last + maxLineLength > text.Length
? text.Length
: (text.LastIndexOfAny(new[] { ' ', ',', '.', '?', '!', ':', ';', '-', '\n', '\r', '\t' }, Math.Min(text.Length - 1, last + maxLineLength)) + 1);
if (i <= last) i = Math.Min(last + maxLineLength, text.Length);
result.AppendLine(text.Substring(last, i - last).Trim(space));
last = i;
} while (i < text.Length);
return result.ToString();
}
}