Skip to content

Commit

Permalink
imp - prt - Condensed to/from parsers
Browse files Browse the repository at this point in the history
---

We've successfully managed to condense parsers. Now, we need to also condense the vCard string builder to maintain consistency.

The equality comparison, however, needs to be fixed.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/2
  • Loading branch information
AptiviCEO committed Mar 31, 2024
1 parent e255c12 commit 1a23dbf
Show file tree
Hide file tree
Showing 28 changed files with 264 additions and 943 deletions.
11 changes: 0 additions & 11 deletions VisualCard.ShowContacts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,13 @@ static void Main(string[] args)
TextWriterColor.Write("First name: {0}", name.ContactFirstName);
TextWriterColor.Write("Last name: {0}", name.ContactLastName);
TextWriterColor.Write("ALTID: {0}", name.AltId);
if (name.AltArguments?.Length > 0)
TextWriterColor.Write("Reason for ALTID: {0}", name.AltArguments);
}

// List titles
foreach (TitleInfo title in Contact.GetPartsArray(PartsArrayEnum.Titles))
{
TextWriterColor.Write("Title or Job: {0}", title.ContactTitle);
TextWriterColor.Write("ALTID: {0}", title.AltId);
if (title.AltArguments?.Length > 0)
TextWriterColor.Write("Reason for ALTID: {0}", title.AltArguments);
}

// List addresses
Expand All @@ -122,7 +118,6 @@ static void Main(string[] args)
// List e-mails
foreach (EmailInfo Email in Contact.GetPartsArray(PartsArrayEnum.Mails))
{
TextWriterColor.Write("Email types: {0}", Email.ContactEmailTypes);
TextWriterColor.Write("Email address: {0}", Email.ContactEmailAddress);
}

Expand All @@ -137,19 +132,15 @@ static void Main(string[] args)
// List telephones
foreach (TelephoneInfo Telephone in Contact.GetPartsArray(PartsArrayEnum.Telephones))
{
TextWriterColor.Write("Phone types: {0}", Telephone.ContactPhoneTypes);
TextWriterColor.Write("Phone number: {0}", Telephone.ContactPhoneNumber);
}

// List photos
foreach (PhotoInfo Photo in Contact.GetPartsArray(PartsArrayEnum.Photos))
{
TextWriterColor.Write("Photo encoding: {0}", Photo.Encoding);
TextWriterColor.Write("Photo type: {0}", Photo.PhotoType);
TextWriterColor.Write("Photo value type: {0}", Photo.ValueType);
TextWriterColor.Write("ALTID: {0}", Photo.AltId);
if (Photo.AltArguments?.Length > 0)
TextWriterColor.Write("Reason for ALTID: {0}", Photo.AltArguments);
TextWriterColor.Write("Photo data: \n{0}", Photo.PhotoEncoded);
}

Expand All @@ -158,8 +149,6 @@ static void Main(string[] args)
{
TextWriterColor.Write("Role: {0}", Role.ContactRole);
TextWriterColor.Write("ALTID: {0}", Role.AltId);
if (Role.AltArguments?.Length > 0)
TextWriterColor.Write("Reason for ALTID: {0}", Role.AltArguments);
}

// List remaining
Expand Down
16 changes: 7 additions & 9 deletions VisualCard/Parsers/VcardParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ public Card Parse()

// Get the part type and handle it
bool xNonstandard = prefix.StartsWith(VcardConstants._xSpecifier);
var (type, enumeration, classType, fromString, fromStringWithType) = VcardParserTools.GetPartType(xNonstandard ? VcardConstants._xSpecifier : prefix);
bool specifierRequired = CardVersion.Major >= 3;
var (type, enumeration, classType, fromString, defaultType, defaultValue) = VcardParserTools.GetPartType(xNonstandard ? VcardConstants._xSpecifier : prefix);
string[] elementTypes = VcardParserTools.GetTypes(splitArgs, defaultType, specifierRequired);
string values = VcardParserTools.GetValuesString(splitArgs, defaultValue, VcardConstants._valueArgumentSpecifier);
switch (type)
{
case PartType.Strings:
Expand Down Expand Up @@ -195,10 +198,7 @@ public Card Parse()
continue;

// Now, get the part info
var partInfo =
isWithType ?
fromStringWithType(_value, [.. finalArgs], altId, CardVersion) :
fromString(_value, altId, CardVersion);
var partInfo = fromString(value, [.. finalArgs], altId, elementTypes, values, CardVersion);
card.SetPart(partsType, partInfo);
}
break;
Expand All @@ -211,10 +211,8 @@ public Card Parse()
continue;

// Now, get the part info
var partInfo =
isWithType ?
fromStringWithType(_value, [.. finalArgs], altId, CardVersion) :
fromString(_value, altId, CardVersion);
string finalValue = partsArrayType == PartsArrayEnum.NonstandardNames ? _value : value;
var partInfo = fromString(finalValue, [.. finalArgs], altId, elementTypes, values, CardVersion);
card.AddPartToArray(partsArrayType, partInfo);
}
break;
Expand Down
Loading

0 comments on commit 1a23dbf

Please sign in to comment.