Skip to content

Commit

Permalink
ref - Moved common internal parsing tools
Browse files Browse the repository at this point in the history
---

Type: ref
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 29, 2024
1 parent 229e0f1 commit 3125b57
Show file tree
Hide file tree
Showing 29 changed files with 332 additions and 317 deletions.
4 changes: 2 additions & 2 deletions VisualCard.Calendar/Parsers/VCalendarParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Parts.Calendar Parse()
}

// Check the type for allowed types
string[] elementTypes = VcardParserTools.GetTypes(splitArgs, defaultType, specifierRequired);
string[] elementTypes = VcardCommonTools.GetTypes(splitArgs, defaultType, specifierRequired);
foreach (string elementType in elementTypes)
{
string elementTypeUpper = elementType.ToUpper();
Expand All @@ -168,7 +168,7 @@ public Parts.Calendar Parse()

// Handle the part type
Type calendarType = subPart is not null ? subPart.GetType() : calendar.GetType();
string values = VcardParserTools.GetValuesString(splitArgs, defaultValue, VCalendarConstants._valueArgumentSpecifier);
string values = VcardCommonTools.GetValuesString(splitArgs, defaultValue, VCalendarConstants._valueArgumentSpecifier);
switch (type)
{
case PartType.Strings:
Expand Down
4 changes: 2 additions & 2 deletions VisualCard.Calendar/Parts/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum,
// Now, locate the prefix and assemble the line
string prefix = VCalendarParserTools.GetPrefixFromStringsEnum(stringEnum);
cardBuilder.Append($"{prefix}{VCalendarConstants._argumentDelimiter}");
cardBuilder.AppendLine($"{VcardParserTools.MakeStringBlock(stringValue, prefix.Length)}");
cardBuilder.AppendLine($"{VcardCommonTools.MakeStringBlock(stringValue, prefix.Length)}");
}

// Then, enumerate all the integers
Expand Down Expand Up @@ -318,7 +318,7 @@ internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum,
string[] partArgumentsLines = partArguments.SplitNewLines();
partBuilder.Append($"{prefix}");
partBuilder.Append($"{partArguments}");
partBuilder.Append($"{VcardParserTools.MakeStringBlock(partRepresentation, partArgumentsLines[partArgumentsLines.Length - 1].Length + prefix.Length)}");
partBuilder.Append($"{VcardCommonTools.MakeStringBlock(partRepresentation, partArgumentsLines[partArgumentsLines.Length - 1].Length + prefix.Length)}");
cardBuilder.AppendLine($"{partBuilder}");
}
}
Expand Down
8 changes: 4 additions & 4 deletions VisualCard.Calendar/Parts/Implementations/AttachInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class AttachInfo : BaseCalendarPartInfo, IEquatable<AttachInfo>
/// Whether this attach is a blob or not
/// </summary>
public bool IsBlob =>
VcardParserTools.IsEncodingBlob(Arguments, AttachEncoded);
VcardCommonTools.IsEncodingBlob(Arguments, AttachEncoded);

internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, string[] finalArgs, string[] elementTypes, string valueType, Version calendarVersion) =>
new AttachInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, calendarVersion);
Expand All @@ -55,8 +55,8 @@ internal override string ToStringVcalendarInternal(Version calendarVersion) =>
internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version calendarVersion)
{
// Check to see if the value is prepended by the ENCODING= argument
string attachEncoding = VcardParserTools.GetValuesString(finalArgs, "b", VCalendarConstants._encodingArgumentSpecifier);
if (!VcardParserTools.IsEncodingBlob(finalArgs, value))
string attachEncoding = VcardCommonTools.GetValuesString(finalArgs, "b", VCalendarConstants._encodingArgumentSpecifier);
if (!VcardCommonTools.IsEncodingBlob(finalArgs, value))
{
// Since we don't need embedded attachs, we need to check a URL.
if (!Uri.TryCreate(value, UriKind.Absolute, out Uri uri))
Expand All @@ -74,7 +74,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value,
/// </summary>
/// <returns>A stream that contains image data</returns>
public Stream GetStream() =>
VcardParserTools.GetBlobData(Arguments, AttachEncoded);
VcardCommonTools.GetBlobData(Arguments, AttachEncoded);

/// <inheritdoc/>
public override bool Equals(object obj) =>
Expand Down
4 changes: 2 additions & 2 deletions VisualCard.Calendar/Parts/Implementations/DateCreatedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str
new DateCreatedInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SavePosixDate(DateCreated)}";
$"{VcardCommonTools.SavePosixDate(DateCreated)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
DateTimeOffset created = VcardParserTools.ParsePosixDate(value);
DateTimeOffset created = VcardCommonTools.ParsePosixDate(value);

// Add the fetched information
DateCreatedInfo _time = new(finalArgs, elementTypes, valueType, created);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str
new DateEndInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SavePosixDate(DateEnd)}";
$"{VcardCommonTools.SavePosixDate(DateEnd)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
DateTimeOffset end = VcardParserTools.ParsePosixDate(value);
DateTimeOffset end = VcardCommonTools.ParsePosixDate(value);

// Add the fetched information
DateEndInfo _time = new(finalArgs, elementTypes, valueType, end);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str
new DateStampInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SavePosixDate(DateStamp)}";
$"{VcardCommonTools.SavePosixDate(DateStamp)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
DateTimeOffset stamp = VcardParserTools.ParsePosixDate(value);
DateTimeOffset stamp = VcardCommonTools.ParsePosixDate(value);

// Add the fetched information
DateStampInfo _time = new(finalArgs, elementTypes, valueType, stamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str
new DateStartInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SavePosixDate(DateStart)}";
$"{VcardCommonTools.SavePosixDate(DateStart)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
DateTimeOffset start = VcardParserTools.ParsePosixDate(value);
DateTimeOffset start = VcardCommonTools.ParsePosixDate(value);

// Add the fetched information
DateStartInfo _time = new(finalArgs, elementTypes, valueType, start);
Expand Down
4 changes: 2 additions & 2 deletions VisualCard.Calendar/Parts/Implementations/LastModifiedInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str
new LastModifiedInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SavePosixDate(LastModified)}";
$"{VcardCommonTools.SavePosixDate(LastModified)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
DateTimeOffset created = VcardParserTools.ParsePosixDate(value);
DateTimeOffset created = VcardCommonTools.ParsePosixDate(value);

// Add the fetched information
LastModifiedInfo _time = new(finalArgs, elementTypes, valueType, created);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str

internal override string ToStringVcalendarInternal(Version calendarVersion)
{
string posixRunTime = VcardParserTools.SavePosixDate(RunTime);
string posixRunTime = VcardCommonTools.SavePosixDate(RunTime);
return $"{posixRunTime};{SnoozeTime};{RepeatCount};{AudioResource}";
}

Expand All @@ -71,7 +71,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value,
string audioResource = split[3];

// Process the run time and the repeat times
DateTimeOffset runTime = VcardParserTools.ParsePosixDate(unprocessedRunTime);
DateTimeOffset runTime = VcardCommonTools.ParsePosixDate(unprocessedRunTime);
int repeat = 0;
if (!string.IsNullOrWhiteSpace(unprocessedRepeat) && !int.TryParse(unprocessedRepeat, out repeat))
throw new ArgumentException("Invalid repeat times");
Expand Down
12 changes: 6 additions & 6 deletions VisualCard.Calendar/Parts/Implementations/Legacy/DaylightInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ internal override string ToStringVcalendarInternal(Version calendarVersion)
{
if (!Flag)
return "FALSE";
string posixUtc = VcardParserTools.SaveUtcOffset(UtcOffset);
string posixStart = VcardParserTools.SavePosixDate(DaylightStart);
string posixEnd = VcardParserTools.SavePosixDate(DaylightEnd);
string posixUtc = VcardCommonTools.SaveUtcOffset(UtcOffset);
string posixStart = VcardCommonTools.SavePosixDate(DaylightStart);
string posixEnd = VcardCommonTools.SavePosixDate(DaylightEnd);
return $"TRUE;{posixUtc};{posixStart};{posixEnd};{StandardDesignation};{DaylightDesignation}";
}

Expand All @@ -88,9 +88,9 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value,
string daylight = split[5];

// Process the UTC offset and start/end dates
TimeSpan utcOffset = VcardParserTools.ParseUtcOffset(unprocessedUtc);
DateTimeOffset startDate = VcardParserTools.ParsePosixDate(unprocessedStart);
DateTimeOffset endDate = VcardParserTools.ParsePosixDate(unprocessedEnd);
TimeSpan utcOffset = VcardCommonTools.ParseUtcOffset(unprocessedUtc);
DateTimeOffset startDate = VcardCommonTools.ParsePosixDate(unprocessedStart);
DateTimeOffset endDate = VcardCommonTools.ParsePosixDate(unprocessedEnd);

// Populate the fields
DaylightInfo _geo = new(finalArgs, elementTypes, valueType, true, utcOffset, startDate, endDate, standard, daylight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str

internal override string ToStringVcalendarInternal(Version calendarVersion)
{
string posixRunTime = VcardParserTools.SavePosixDate(RunTime);
string posixRunTime = VcardCommonTools.SavePosixDate(RunTime);
return $"{posixRunTime};{SnoozeTime};{RepeatCount};{Display}";
}

Expand All @@ -71,7 +71,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value,
string display = split[3];

// Process the run time and the repeat times
DateTimeOffset runTime = VcardParserTools.ParsePosixDate(unprocessedRunTime);
DateTimeOffset runTime = VcardCommonTools.ParsePosixDate(unprocessedRunTime);
int repeat = 0;
if (!string.IsNullOrWhiteSpace(unprocessedRepeat) && !int.TryParse(unprocessedRepeat, out repeat))
throw new ArgumentException("Invalid repeat times");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str

internal override string ToStringVcalendarInternal(Version calendarVersion)
{
string posixRunTime = VcardParserTools.SavePosixDate(RunTime);
string posixRunTime = VcardCommonTools.SavePosixDate(RunTime);
return $"{posixRunTime};{SnoozeTime};{RepeatCount};{Address};{Note}";
}

Expand All @@ -77,7 +77,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value,
string note = split[4];

// Process the run time and the repeat times
DateTimeOffset runTime = VcardParserTools.ParsePosixDate(unprocessedRunTime);
DateTimeOffset runTime = VcardCommonTools.ParsePosixDate(unprocessedRunTime);
int repeat = 0;
if (!string.IsNullOrWhiteSpace(unprocessedRepeat) && !int.TryParse(unprocessedRepeat, out repeat))
throw new ArgumentException("Invalid repeat times");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str

internal override string ToStringVcalendarInternal(Version calendarVersion)
{
string posixRunTime = VcardParserTools.SavePosixDate(RunTime);
string posixRunTime = VcardCommonTools.SavePosixDate(RunTime);
return $"{posixRunTime};{SnoozeTime};{RepeatCount};{Procedure}";
}

Expand All @@ -71,7 +71,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value,
string procedure = split[3];

// Process the run time and the repeat times
DateTimeOffset runTime = VcardParserTools.ParsePosixDate(unprocessedRunTime);
DateTimeOffset runTime = VcardCommonTools.ParsePosixDate(unprocessedRunTime);
int repeat = 0;
if (!string.IsNullOrWhiteSpace(unprocessedRepeat) && !int.TryParse(unprocessedRepeat, out repeat))
throw new ArgumentException("Invalid repeat times");
Expand Down
6 changes: 3 additions & 3 deletions VisualCard.Calendar/Parts/Implementations/RecDateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ internal override string ToStringVcalendarInternal(Version cardVersion)

var builder = new StringBuilder();
if (cardVersion.Major == 1)
builder.Append(string.Join(";", RecDates.Select((dt) => VcardParserTools.SavePosixDate(dt))));
builder.Append(string.Join(";", RecDates.Select((dt) => VcardCommonTools.SavePosixDate(dt))));
else
builder.Append(VcardParserTools.SavePosixDate(RecDates[0]));
builder.Append(VcardCommonTools.SavePosixDate(RecDates[0]));
return builder.ToString();
}

Expand All @@ -61,7 +61,7 @@ internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value,
cardVersion.Major == 1 ?
Regex.Unescape(value).Split(';') :
[Regex.Unescape(value)];
var recDates = recDateStrings.Select(VcardParserTools.ParsePosixDate).ToArray();
var recDates = recDateStrings.Select(VcardCommonTools.ParsePosixDate).ToArray();

// Add the fetched information
RecDateInfo _time = new([], elementTypes, valueType, recDates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str
new TimeZoneOffsetFromInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SaveUtcOffset(Offset)}";
$"{VcardCommonTools.SaveUtcOffset(Offset)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
TimeSpan start = VcardParserTools.ParseUtcOffset(value);
TimeSpan start = VcardCommonTools.ParseUtcOffset(value);

// Add the fetched information
TimeZoneOffsetFromInfo _time = new(finalArgs, elementTypes, valueType, start);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str
new TimeZoneOffsetToInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SaveUtcOffset(Offset)}";
$"{VcardCommonTools.SaveUtcOffset(Offset)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
TimeSpan start = VcardParserTools.ParseUtcOffset(value);
TimeSpan start = VcardCommonTools.ParseUtcOffset(value);

// Add the fetched information
TimeZoneOffsetToInfo _time = new(finalArgs, elementTypes, valueType, start);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str
new DateCompletedInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SavePosixDate(DateCompleted)}";
$"{VcardCommonTools.SavePosixDate(DateCompleted)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
DateTimeOffset completed = VcardParserTools.ParsePosixDate(value);
DateTimeOffset completed = VcardCommonTools.ParsePosixDate(value);

// Add the fetched information
DateCompletedInfo _time = new(finalArgs, elementTypes, valueType, completed);
Expand Down
4 changes: 2 additions & 2 deletions VisualCard.Calendar/Parts/Implementations/Todo/DueDateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal static BaseCalendarPartInfo FromStringVcalendarStatic(string value, str
new DueDateInfo().FromStringVcalendarInternal(value, finalArgs, elementTypes, valueType, cardVersion);

internal override string ToStringVcalendarInternal(Version cardVersion) =>
$"{VcardParserTools.SavePosixDate(DueDate)}";
$"{VcardCommonTools.SavePosixDate(DueDate)}";

internal override BaseCalendarPartInfo FromStringVcalendarInternal(string value, string[] finalArgs, string[] elementTypes, string valueType, Version cardVersion)
{
// Populate the fields
DateTimeOffset completed = VcardParserTools.ParsePosixDate(value);
DateTimeOffset completed = VcardCommonTools.ParsePosixDate(value);

// Add the fetched information
DueDateInfo _time = new(finalArgs, elementTypes, valueType, completed);
Expand Down
Loading

0 comments on commit 3125b57

Please sign in to comment.