Skip to content

Commit

Permalink
imp - brk|doc - Main ALTID is now -1
Browse files Browse the repository at this point in the history
---

ALTID may also be specified as ALTID=0, so we've reserved ALTID -1 to be the main representation of the property.

---

Type: imp
Breaking: True
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Apr 1, 2024
1 parent db0f717 commit fb5a874
Show file tree
Hide file tree
Showing 26 changed files with 34 additions and 63 deletions.
7 changes: 6 additions & 1 deletion VisualCard/Parsers/VcardParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Card Parse()
string[] splitValues = value.Split([VcardConstants._fieldDelimiter], StringSplitOptions.RemoveEmptyEntries);
bool isWithType = splitArgs.Length > 0;
List<string> finalArgs = [];
int altId = 0;
int altId = -1;

// Now, parse a line
try
Expand All @@ -115,9 +115,14 @@ public Card Parse()
{
if (splitArgs[0].StartsWith(VcardConstants._altIdArgumentSpecifier))
{
// We need ALTID to be numeric
if (!int.TryParse(splitArgs[0].Substring(VcardConstants._altIdArgumentSpecifier.Length), out altId))
throw new InvalidDataException("ALTID must be numeric");

// We need ALTID to be positive
if (altId < 0)
throw new InvalidDataException("ALTID must be positive");

// Here, we require arguments for ALTID
if (splitArgs.Length <= 1)
throw new InvalidDataException("ALTID must have one or more arguments to specify why this instance is an alternative");
Expand Down
2 changes: 1 addition & 1 deletion VisualCard/Parts/CardBuilderTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal static string BuildArguments(BaseCardPartInfo partInfo, Version cardVer

// Check to see if we've been provided arguments
bool installAltId = partInfo.AltId >= 0 && partInfo.Arguments.Length > 0 && cardVersion.Major >= 4;
bool noSemicolon = partInfo.AltId == 0 && partInfo.Arguments.Length == 0 && finalElementTypes.Length == 0 && string.IsNullOrEmpty(finalValue);
bool noSemicolon = partInfo.AltId < 0 && partInfo.Arguments.Length == 0 && finalElementTypes.Length == 0 && string.IsNullOrEmpty(finalValue);
string xNonstandardName = partInfo is XNameInfo xName ? xName.XKeyName : "";
if (noSemicolon)
return xNonstandardName + VcardConstants._argumentDelimiter.ToString();
Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/AddressInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ public class AddressInfo : BaseCardPartInfo, IEquatable<AddressInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Get the value
string[] splitAdr = value.Split(VcardConstants._fieldDelimiter);

Expand All @@ -93,7 +91,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
string _addressRegion = Regex.Unescape(splitAdr[4]);
string _addressPostalCode = Regex.Unescape(splitAdr[5]);
string _addressCountry = Regex.Unescape(splitAdr[6]);
AddressInfo _address = new(altIdSupported ? altId : 0, finalArgs, _addressTypes, valueType, _addressPOBox, _addressExtended, _addressStreet, _addressLocality, _addressRegion, _addressPostalCode, _addressCountry);
AddressInfo _address = new(altId, finalArgs, _addressTypes, valueType, _addressPOBox, _addressExtended, _addressStreet, _addressLocality, _addressRegion, _addressPostalCode, _addressCountry);
return _address;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/AgentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,14 @@ internal override string ToStringVcardInternal(Version cardVersion)

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Check the provided agent
if (string.IsNullOrEmpty(value))
throw new InvalidDataException("Agent information must specify exactly one value (agent vCard contents that have their lines delimited by \\n)");

// Populate the fields
string _agentVcard = Regex.Unescape(value).Replace("\\n", "\n");
var _agentVcardParsers = CardTools.GetCardsFromString(_agentVcard);
AgentInfo _agent = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _agentVcardParsers);
AgentInfo _agent = new(altId, finalArgs, elementTypes, valueType, _agentVcardParsers);
return _agent;
}

Expand Down
2 changes: 1 addition & 1 deletion VisualCard/Parts/Implementations/AnniversaryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
anniversary = DateTime.Parse(value);

// Add the fetched information
AnniversaryInfo _time = new(0, [], [], valueType, anniversary);
AnniversaryInfo _time = new(-1, [], [], valueType, anniversary);
return _time;
}

Expand Down
3 changes: 1 addition & 2 deletions VisualCard/Parts/Implementations/BirthDateInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
bday = DateTime.Parse(value);

// Add the fetched information
bool altIdSupported = cardVersion.Major >= 4;
BirthDateInfo _time = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, bday);
BirthDateInfo _time = new(altId, finalArgs, elementTypes, valueType, bday);
return _time;
}

Expand Down
2 changes: 1 addition & 1 deletion VisualCard/Parts/Implementations/CategoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
var categories = Regex.Unescape(value).Split(',');

// Add the fetched information
CategoryInfo _time = new(0, [], elementTypes, valueType, categories);
CategoryInfo _time = new(-1, [], elementTypes, valueType, categories);
return _time;
}

Expand Down
3 changes: 1 addition & 2 deletions VisualCard/Parts/Implementations/EmailInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class EmailInfo : BaseCardPartInfo, IEquatable<EmailInfo>
internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
MailAddress mail;
bool altIdSupported = cardVersion.Major >= 4;

// Try to create mail address
try
Expand All @@ -59,7 +58,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[

// Populate the fields
string _emailAddress = mail.Address;
EmailInfo _address = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _emailAddress);
EmailInfo _address = new(altId, finalArgs, elementTypes, valueType, _emailAddress);
return _address;
}

Expand Down
2 changes: 1 addition & 1 deletion VisualCard/Parts/Implementations/GenderInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
};

// Add the fetched information
GenderInfo _gender = new(0, [], elementTypes, valueType, gender, genderDescription);
GenderInfo _gender = new(-1, [], elementTypes, valueType, gender, genderDescription);
return _gender;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/GeoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
string geoValue = value.Substring(VcardConstants._geoSpecifier.Length + 1);
string _geoStr = Regex.Unescape(geoValue);

bool altIdSupported = cardVersion.Major >= 4;

// Populate the fields
GeoInfo _geo = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _geoStr);
GeoInfo _geo = new(altId, finalArgs, elementTypes, valueType, _geoStr);
return _geo;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/ImppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ public class ImppInfo : BaseCardPartInfo, IEquatable<ImppInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Populate the fields
string _impp = Regex.Unescape(value);
ImppInfo _imppInstance = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _impp);
ImppInfo _imppInstance = new(altId, finalArgs, elementTypes, valueType, _impp);
return _imppInstance;
}

Expand Down
2 changes: 1 addition & 1 deletion VisualCard/Parts/Implementations/KeyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
}

// Populate the fields
KeyInfo _key = new(vCard4 ? altId : 0, finalArgs, elementTypes, valueType, keyEncoding, value);
KeyInfo _key = new(altId, finalArgs, elementTypes, valueType, keyEncoding, value);
return _key;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/LabelAddressInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ public class LabelAddressInfo : BaseCardPartInfo, IEquatable<LabelAddressInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Populate the fields
string _addressLabel = Regex.Unescape(value);
LabelAddressInfo _address = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _addressLabel);
LabelAddressInfo _address = new(altId, finalArgs, elementTypes, valueType, _addressLabel);
return _address;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/LogoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ public class LogoInfo : BaseCardPartInfo, IEquatable<LogoInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Check to see if the value is prepended by the ENCODING= argument
string logoEncoding = VcardParserTools.GetValuesString(finalArgs, "BASE64", VcardConstants._encodingArgumentSpecifier);

// Populate the fields
LogoInfo _logo = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, logoEncoding, value);
LogoInfo _logo = new(altId, finalArgs, elementTypes, valueType, logoEncoding, value);
return _logo;
}

Expand Down
3 changes: 1 addition & 2 deletions VisualCard/Parts/Implementations/NameInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ internal override string ToStringVcardInternal(Version cardVersion)

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;
string[] splitName = value.Split(VcardConstants._fieldDelimiter);
if (splitName.Length < 2)
throw new InvalidDataException("Name field must specify the first two or more of the five values (Last name, first name, alt names, prefixes, and suffixes)");
Expand All @@ -83,7 +82,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
string[] _altNames = splitName.Length >= 3 ? Regex.Unescape(splitName[2]).Split(new char[] { VcardConstants._valueDelimiter }, StringSplitOptions.RemoveEmptyEntries) : [];
string[] _prefixes = splitName.Length >= 4 ? Regex.Unescape(splitName[3]).Split(new char[] { VcardConstants._valueDelimiter }, StringSplitOptions.RemoveEmptyEntries) : [];
string[] _suffixes = splitName.Length >= 5 ? Regex.Unescape(splitName[4]).Split(new char[] { VcardConstants._valueDelimiter }, StringSplitOptions.RemoveEmptyEntries) : [];
NameInfo _name = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _firstName, _lastName, _altNames, _prefixes, _suffixes);
NameInfo _name = new(altId, finalArgs, elementTypes, valueType, _firstName, _lastName, _altNames, _prefixes, _suffixes);
return _name;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/NicknameInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ public class NicknameInfo : BaseCardPartInfo, IEquatable<NicknameInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Populate the fields
string _nick = Regex.Unescape(value);
NicknameInfo _nickInstance = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _nick);
NicknameInfo _nickInstance = new(altId, finalArgs, elementTypes, valueType, _nick);
return _nickInstance;
}

Expand Down
3 changes: 1 addition & 2 deletions VisualCard/Parts/Implementations/OrganizationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ public class OrganizationInfo : BaseCardPartInfo, IEquatable<OrganizationInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;
string[] splitOrg = value.Split(VcardConstants._fieldDelimiter);

// Populate the fields
string _orgName = Regex.Unescape(splitOrg[0]);
string _orgUnit = Regex.Unescape(splitOrg.Length >= 2 ? splitOrg[1] : "");
string _orgUnitRole = Regex.Unescape(splitOrg.Length >= 3 ? splitOrg[2] : "");
OrganizationInfo _org = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _orgName, _orgUnit, _orgUnitRole);
OrganizationInfo _org = new(altId, finalArgs, elementTypes, valueType, _orgName, _orgUnit, _orgUnitRole);
return _org;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/PhotoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ public class PhotoInfo : BaseCardPartInfo, IEquatable<PhotoInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Check to see if the value is prepended by the ENCODING= argument
string photoEncoding = VcardParserTools.GetValuesString(finalArgs, "BASE64", VcardConstants._encodingArgumentSpecifier);

// Populate the fields
PhotoInfo _photo = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, photoEncoding, value);
PhotoInfo _photo = new(altId, finalArgs, elementTypes, valueType, photoEncoding, value);
return _photo;
}

Expand Down
12 changes: 4 additions & 8 deletions VisualCard/Parts/Implementations/RevisionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
DateTime rev = DateTime.Parse(revValue);

// Add the fetched information
bool altIdSupported = cardVersion.Major >= 4;
RevisionInfo _time = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, rev);
RevisionInfo _time = new(altId, finalArgs, elementTypes, valueType, rev);
return _time;
}

Expand Down Expand Up @@ -106,13 +105,10 @@ public override int GetHashCode()

internal RevisionInfo() { }

internal RevisionInfo(int altId, string[] arguments, string[] elementTypes, string valueType, DateTime? birth)
internal RevisionInfo(int altId, string[] arguments, string[] elementTypes, string valueType, DateTime? rev) :
base(arguments, altId, elementTypes, valueType)
{
AltId = altId;
Arguments = arguments;
ElementTypes = elementTypes;
ValueType = valueType;
Revision = birth;
Revision = rev;
}
}
}
3 changes: 1 addition & 2 deletions VisualCard/Parts/Implementations/RoleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ public class RoleInfo : BaseCardPartInfo, IEquatable<RoleInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;
string roleValue = Regex.Unescape(value);

// Populate the fields
RoleInfo _role = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, roleValue);
RoleInfo _role = new(altId, finalArgs, elementTypes, valueType, roleValue);
return _role;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/SoundInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ public class SoundInfo : BaseCardPartInfo, IEquatable<SoundInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Check to see if the value is prepended by the ENCODING= argument
string soundEncoding = VcardParserTools.GetValuesString(finalArgs, "BASE64", VcardConstants._encodingArgumentSpecifier);

// Populate the fields
SoundInfo _sound = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, soundEncoding, value);
SoundInfo _sound = new(altId, finalArgs, elementTypes, valueType, soundEncoding, value);
return _sound;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/TelephoneInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ public class TelephoneInfo : BaseCardPartInfo, IEquatable<TelephoneInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Populate the fields
string _telephoneNumber = Regex.Unescape(value);
TelephoneInfo _telephone = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _telephoneNumber);
TelephoneInfo _telephone = new(altId, finalArgs, elementTypes, valueType, _telephoneNumber);
return _telephone;
}

Expand Down
4 changes: 1 addition & 3 deletions VisualCard/Parts/Implementations/TimeDateZoneInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ public class TimeDateZoneInfo : BaseCardPartInfo, IEquatable<TimeDateZoneInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;

// Get the types and the number
string _tzStr = Regex.Unescape(value);

// Add the fetched information
TimeDateZoneInfo _timeZone = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _tzStr);
TimeDateZoneInfo _timeZone = new(altId, finalArgs, elementTypes, valueType, _tzStr);
return _timeZone;
}

Expand Down
3 changes: 1 addition & 2 deletions VisualCard/Parts/Implementations/TitleInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ public class TitleInfo : BaseCardPartInfo, IEquatable<TitleInfo>

internal override BaseCardPartInfo FromStringVcardInternal(string value, string[] finalArgs, int altId, string[] elementTypes, string valueType, Version cardVersion)
{
bool altIdSupported = cardVersion.Major >= 4;
string _title = Regex.Unescape(value);
TitleInfo _titleInfo = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _title);
TitleInfo _titleInfo = new(altId, finalArgs, elementTypes, valueType, _title);
return _titleInfo;
}

Expand Down
3 changes: 1 addition & 2 deletions VisualCard/Parts/Implementations/XNameInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[
{
string xValue = value.Substring(VcardConstants._xSpecifier.Length);
string[] splitX = xValue.Split(VcardConstants._argumentDelimiter);
bool altIdSupported = cardVersion.Major >= 4;

// Populate the name
string _xName = splitX[0].Contains(VcardConstants._fieldDelimiter.ToString()) ?
Expand All @@ -59,7 +58,7 @@ internal override BaseCardPartInfo FromStringVcardInternal(string value, string[

// Populate the fields
string[] _xValues = splitX[1].Split(VcardConstants._fieldDelimiter);
XNameInfo _x = new(altIdSupported ? altId : 0, finalArgs, elementTypes, valueType, _xName, _xValues);
XNameInfo _x = new(altId, finalArgs, elementTypes, valueType, _xName, _xValues);
return _x;
}

Expand Down
Loading

0 comments on commit fb5a874

Please sign in to comment.