Skip to content

Commit

Permalink
add - doc - Added support for CATEGORIES in vCard 2.1
Browse files Browse the repository at this point in the history
---

We've added support for CATEGORIES in vCard contacts that use the v2.1 version of the specification.

---

Type: add
Breaking: False
Doc Required: True
Part: 1/1
  • Loading branch information
AptiviCEO committed Dec 16, 2023
1 parent 578928a commit 51ba51a
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion VisualCard/Parsers/Two/VcardTwo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public override Card Parse()
List<LogoInfo> _logos = [];
List<SoundInfo> _sounds = [];
List<RoleInfo> _roles = [];
List<string> _categories = [];
List<TimeZoneInfo> _timezones = [];
List<GeoInfo> _geos = [];
List<ImppInfo> _impps = [];
Expand Down Expand Up @@ -269,6 +270,16 @@ public override Card Parse()
if (_value.StartsWith(VcardConstants._roleSpecifier + delimiter))
_roles.Add(RoleInfo.FromStringVcardTwo(_value));

// Categories (CATEGORIES:INTERNET or CATEGORIES:INTERNET,IETF,INDUSTRY,INFORMATION TECHNOLOGY)
if (_value.StartsWith(VcardConstants._categoriesSpecifier + delimiter))
{
// Get the value
string categoriesValue = _value.Substring(VcardConstants._categoriesSpecifier.Length + 1);

// Populate field
_categories.AddRange(Regex.Unescape(categoriesValue).Split(','));
}

// Time Zone (TZ;VALUE=text:-05:00; EST; Raleigh/North America)
if (_value.StartsWith(VcardConstants._timeZoneSpecifier + delimiter))
{
Expand Down Expand Up @@ -344,7 +355,7 @@ public override Card Parse()
ContactBirthdate = _bday,
ContactMailer = _mailer,
ContactRoles = [.. _roles],
ContactCategories = [],
ContactCategories = [.. _categories],
ContactLogos = [.. _logos],
ContactProdId = "",
ContactSortString = "",
Expand Down Expand Up @@ -415,6 +426,8 @@ internal override string SaveToString(Card card)
cardBuilder.AppendLine($"{VcardConstants._mailerSpecifier}:{card.ContactMailer}");
foreach (RoleInfo role in card.ContactRoles)
cardBuilder.AppendLine(role.ToStringVcardTwo());
if (card.ContactCategories is not null && card.ContactCategories.Length > 0)
cardBuilder.AppendLine($"{VcardConstants._categoriesSpecifier}:{string.Join(",", card.ContactCategories)}");
foreach (TimeZoneInfo timeZone in card.ContactTimeZone)
cardBuilder.AppendLine(timeZone.ToStringVcardTwo());
foreach (GeoInfo geo in card.ContactGeo)
Expand Down

0 comments on commit 51ba51a

Please sign in to comment.