using System.Text; namespace GoogleSheetsScheduleImport; /// /// Google Sheets cells can contain line breaks as LF/CR or Unicode line/paragraph separators. /// Import text must be one logical line per occurrence. /// public static class TextNormalization { public static string ForSheetCell(string? raw) { if (string.IsNullOrWhiteSpace(raw)) return string.Empty; return CollapseWhitespace(Core.Utility.TextUtil.SanitizeInput(raw.Trim())); } public static string ForEmitLine(string? raw) { if (string.IsNullOrWhiteSpace(raw)) return string.Empty; return CollapseWhitespace(Core.Utility.TextUtil.SanitizeInput(raw.Trim())); } private static string CollapseWhitespace(string s) { var sb = new StringBuilder(s.Length); var pendingSpace = false; foreach (var ch in s) { if (char.IsWhiteSpace(ch)) pendingSpace = true; else { if (pendingSpace && sb.Length > 0) sb.Append(' '); pendingSpace = false; sb.Append(ch); } } return sb.ToString().Trim(); } }