This commit refactors the EventOccurrence parsing logic to utilize the EventOccurrenceParseGroup class, enhancing the organization of parsed occurrences by grouping them based on event definitions and optional section levels. The changes include updates to the EventOccurrenceParseResult, EventOccurrenceParser, and EventOccurrenceParserService to accommodate the new grouping structure. Additionally, tests are modified to reflect these changes, ensuring that the parsing functionality remains intact and accurate. This refactor improves data handling and aligns with the overall architecture of the application.
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.Text;
|
|
|
|
namespace GoogleSheetsScheduleImport;
|
|
|
|
/// <summary>
|
|
/// Google Sheets cells can contain line breaks as LF/CR or Unicode line/paragraph separators.
|
|
/// Import text must be one logical line per occurrence.
|
|
/// </summary>
|
|
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();
|
|
}
|
|
}
|