Skip to content

Commit

Permalink
imp - Improved support for integers
Browse files Browse the repository at this point in the history
---

Integers are now more compatible, because there can be floating point values.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 1, 2024
1 parent a1d6ac7 commit c089b0e
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 199 deletions.
14 changes: 7 additions & 7 deletions VisualCard.Calendar/Parsers/VCalendarParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Parts.Calendar Parse()
// Get the part type
bool xNonstandard = prefix.StartsWith(VCalendarConstants._xSpecifier);
bool specifierRequired = CalendarVersion.Major >= 3;
var (type, enumeration, classType, fromString, defaultType, defaultValue, extraAllowedTypes) = VCalendarParserTools.GetPartType(xNonstandard ? VCalendarConstants._xSpecifier : prefix);
var (type, enumeration, classType, fromString, defaultType, defaultValue, defaultValueType, extraAllowedTypes) = VCalendarParserTools.GetPartType(xNonstandard ? VCalendarConstants._xSpecifier : prefix);

// Handle arguments
if (isWithType)
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 = VcardCommonTools.GetValuesString(splitArgs, defaultValue, VCalendarConstants._valueArgumentSpecifier);
string valueType = VcardCommonTools.GetFirstValue(splitArgs, defaultValue, VCalendarConstants._valueArgumentSpecifier);
switch (type)
{
case PartType.Strings:
Expand All @@ -179,7 +179,7 @@ public Parts.Calendar Parse()
continue;

// Get the final value
string finalValue = VCalendarParserTools.ProcessStringValue(value, values, stringType, calendarType, CalendarVersion);
string finalValue = VcardParserTools.ProcessStringValue(value, valueType);

// Set the string for real
if (subPart is not null)
Expand All @@ -196,7 +196,7 @@ public Parts.Calendar Parse()
continue;

// Get the final value
int finalValue = VCalendarParserTools.ProcessIntegerValue(value, integerType);
double finalValue = VcardParserTools.ProcessIntegerValue(value, valueType);

// Set the integer for real
if (subPart is not null)
Expand All @@ -217,7 +217,7 @@ public Parts.Calendar Parse()

// Now, get the part info
string finalValue = partsArrayType is CalendarPartsArrayEnum.IanaNames or CalendarPartsArrayEnum.NonstandardNames ? _value : value;
var partInfo = fromString(finalValue, [.. finalArgs], elementTypes, values, CalendarVersion);
var partInfo = fromString(finalValue, [.. finalArgs], elementTypes, valueType, CalendarVersion);

// Set the array for real
if (subPart is not null)
Expand Down Expand Up @@ -326,7 +326,7 @@ private bool HasComponent<TComponent>(string expectedFieldName, TComponent compo
where TComponent : Parts.Calendar
{
// Requirement checks
var (type, enumeration, enumType, _, _, _, _) = VCalendarParserTools.GetPartType(expectedFieldName);
var (type, enumeration, enumType, _, _, _, _, _) = VCalendarParserTools.GetPartType(expectedFieldName);
bool exists = false;
switch (type)
{
Expand All @@ -346,7 +346,7 @@ private bool HasComponent<TComponent>(string expectedFieldName, TComponent compo
break;
case PartType.Integers:
{
int value = component.GetInteger((CalendarIntegersEnum)enumeration);
double value = component.GetInteger((CalendarIntegersEnum)enumeration);
exists = value != -1;
}
break;
Expand Down
198 changes: 48 additions & 150 deletions VisualCard.Calendar/Parsers/VCalendarParserTools.cs

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions VisualCard.Calendar/Parts/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Calendar : IEquatable<Calendar>
private readonly Version version;
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];
private readonly Dictionary<CalendarIntegersEnum, double> integers = [];

/// <summary>
/// The vCalendar version
Expand Down Expand Up @@ -230,10 +230,10 @@ internal string GetString(CalendarStringsEnum key, Version version, Dictionary<C
/// </summary>
/// <param name="key">A key to use</param>
/// <returns>A value or -1 if any other type either doesn't exist or the type is not supported by the card version</returns>
public int GetInteger(CalendarIntegersEnum key) =>
public double GetInteger(CalendarIntegersEnum key) =>
GetInteger(key, integers);

internal int GetInteger(CalendarIntegersEnum key, Dictionary<CalendarIntegersEnum, int> integers)
internal double GetInteger(CalendarIntegersEnum key, Dictionary<CalendarIntegersEnum, double> integers)
{
// Check for version support
if (!VCalendarParserTools.IntegerSupported(key, GetType()))
Expand All @@ -243,7 +243,7 @@ internal int GetInteger(CalendarIntegersEnum key, Dictionary<CalendarIntegersEnu
int fallback = -1;

// Check to see if the integer has a value or not
bool hasValue = integers.TryGetValue(key, out int value);
bool hasValue = integers.TryGetValue(key, out double value);
if (!hasValue)
return fallback;
return value;
Expand All @@ -255,7 +255,7 @@ internal int GetInteger(CalendarIntegersEnum key, Dictionary<CalendarIntegersEnu
public string SaveToString() =>
SaveToString(version, partsArray, strings, integers, VCalendarConstants._objectVCalendarSpecifier);

internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray, Dictionary<CalendarStringsEnum, string> strings, Dictionary<CalendarIntegersEnum, int> integers, string objectType)
internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray, Dictionary<CalendarStringsEnum, string> strings, Dictionary<CalendarIntegersEnum, double> integers, string objectType)
{
// Initialize the card builder
var cardBuilder = new StringBuilder();
Expand Down Expand Up @@ -285,7 +285,7 @@ internal string SaveToString(Version version, Dictionary<CalendarPartsArrayEnum,
foreach (CalendarIntegersEnum integerEnum in integerEnums)
{
// Get the integer value
int integerValue = GetInteger(integerEnum, integers);
double integerValue = GetInteger(integerEnum, integers);
if (integerValue == -1)
continue;

Expand Down Expand Up @@ -425,7 +425,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarTimeZone>>.Default.GetHashCode(timeZones);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, double>>.Default.GetHashCode(integers);
return hashCode;
}

Expand Down Expand Up @@ -482,10 +482,10 @@ internal void SetString(CalendarStringsEnum key, string value, Dictionary<Calend
throw new InvalidOperationException($"Can't overwrite string {key}.");
}

internal void SetInteger(CalendarIntegersEnum key, int value) =>
internal void SetInteger(CalendarIntegersEnum key, double value) =>
SetInteger(key, value, integers);

internal void SetInteger(CalendarIntegersEnum key, int value, Dictionary<CalendarIntegersEnum, int> integers)
internal void SetInteger(CalendarIntegersEnum key, double value, Dictionary<CalendarIntegersEnum, double> integers)
{
if (value == -1)
return;
Expand Down
6 changes: 3 additions & 3 deletions VisualCard.Calendar/Parts/CalendarAlarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CalendarAlarm : Calendar, IEquatable<CalendarAlarm>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];
private readonly Dictionary<CalendarIntegersEnum, double> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -116,7 +116,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, double>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -134,7 +134,7 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
internal new void SetInteger(CalendarIntegersEnum key, double value) =>
SetInteger(key, value, integers);

internal CalendarAlarm(Version version) :
Expand Down
6 changes: 3 additions & 3 deletions VisualCard.Calendar/Parts/CalendarDaylight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CalendarDaylight : Calendar, IEquatable<CalendarDaylight>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];
private readonly Dictionary<CalendarIntegersEnum, double> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -116,7 +116,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, double>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -134,7 +134,7 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
internal new void SetInteger(CalendarIntegersEnum key, double value) =>
SetInteger(key, value, integers);

internal CalendarDaylight(Version version) :
Expand Down
6 changes: 3 additions & 3 deletions VisualCard.Calendar/Parts/CalendarEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class CalendarEvent : Calendar, IEquatable<CalendarEvent>
internal readonly List<CalendarAlarm> alarms = [];
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];
private readonly Dictionary<CalendarIntegersEnum, double> integers = [];

/// <summary>
/// Alarm list
Expand Down Expand Up @@ -125,7 +125,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarAlarm>>.Default.GetHashCode(alarms);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, double>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -143,7 +143,7 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
internal new void SetInteger(CalendarIntegersEnum key, double value) =>
SetInteger(key, value, integers);

internal CalendarEvent(Version version) :
Expand Down
6 changes: 3 additions & 3 deletions VisualCard.Calendar/Parts/CalendarFreeBusy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CalendarFreeBusy : Calendar, IEquatable<CalendarFreeBusy>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];
private readonly Dictionary<CalendarIntegersEnum, double> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -116,7 +116,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, double>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -134,7 +134,7 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
internal new void SetInteger(CalendarIntegersEnum key, double value) =>
SetInteger(key, value, integers);

internal CalendarFreeBusy(Version version) :
Expand Down
6 changes: 3 additions & 3 deletions VisualCard.Calendar/Parts/CalendarJournal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CalendarJournal : Calendar, IEquatable<CalendarJournal>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];
private readonly Dictionary<CalendarIntegersEnum, double> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -116,7 +116,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, double>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -134,7 +134,7 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
internal new void SetInteger(CalendarIntegersEnum key, double value) =>
SetInteger(key, value, integers);

internal CalendarJournal(Version version) :
Expand Down
6 changes: 3 additions & 3 deletions VisualCard.Calendar/Parts/CalendarStandard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class CalendarStandard : Calendar, IEquatable<CalendarStandard>
{
private readonly Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>> partsArray = [];
private readonly Dictionary<CalendarStringsEnum, string> strings = [];
private readonly Dictionary<CalendarIntegersEnum, int> integers = [];
private readonly Dictionary<CalendarIntegersEnum, double> integers = [];

/// <summary>
/// Gets a part array from a specified key
Expand Down Expand Up @@ -116,7 +116,7 @@ public override int GetHashCode()
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, double>>.Default.GetHashCode(integers);
return hashCode;
}

Expand All @@ -134,7 +134,7 @@ public override int GetHashCode()
internal new void SetString(CalendarStringsEnum key, string value) =>
SetString(key, value, strings);

internal new void SetInteger(CalendarIntegersEnum key, int value) =>
internal new void SetInteger(CalendarIntegersEnum key, double value) =>
SetInteger(key, value, integers);

internal CalendarStandard(Version version) :
Expand Down
Loading

0 comments on commit c089b0e

Please sign in to comment.