Skip to content

Commit c3dae4c

Browse files
committed
imp - Consolidated type-based info parsers
We've consolidated type-based info parsers --- We've made a substantial change to type-based info parsers by determining the types from the value and parsing them more efficiently. We've cut down the constants so that there are no repeat types with a difference in the delimiter. --- Type: imp Breaking: False Doc Required: False Part: 1/1
1 parent 9258ddd commit c3dae4c

21 files changed

+741
-467
lines changed

VisualCard.Tests/ContactData.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static class ContactData
4242
BEGIN:VCARD
4343
VERSION:3.0
4444
FN:Rick Hood
45-
N:Hood;Rick;;;;
45+
N:Hood;Rick;;;
4646
END:VCARD
4747
4848
"""
@@ -147,7 +147,7 @@ public static class ContactData
147147
BEGIN:VCARD
148148
VERSION:3.0
149149
FN:John Sanders
150-
N:Sanders;John;;;;
150+
N:Sanders;John;;;
151151
TEL;TYPE=CELL:495-522-3560
152152
ADR;TYPE=HOME:;;Los Angeles;;;;USA
153153
EMAIL;TYPE=HOME:[email protected]
@@ -720,6 +720,7 @@ public static class ContactData
720720
TEL;TYPE=cell:589-210-1059
721721
TITLE:Chief Executive Officer
722722
URL:https://sso.org/
723+
BDAY:19890222
723724
X-SIP-SIP:sip test
724725
END:VCARD
725726
@@ -789,7 +790,7 @@ public static class ContactData
789790
new ImppInfo(0, Array.Empty<string>(), "aim:IM", new string[] { "HOME" }),
790791
new ImppInfo(0, Array.Empty<string>(), "msn:Windows LIVE", new string[] { "HOME" }),
791792
new ImppInfo(0, Array.Empty<string>(), "ymsgr:Yahoo", new string[] { "HOME" })
792-
}
793+
},
793794
};
794795
private static readonly Card multipleVcardFourContactsInstanceThree = new
795796
(
@@ -827,7 +828,8 @@ public static class ContactData
827828
ContactXNames = new XNameInfo[]
828829
{
829830
new XNameInfo(0, Array.Empty<string>(), "SIP-SIP", new string[] { "sip test" }, Array.Empty<string>()),
830-
}
831+
},
832+
ContactBirthdate = new DateTime(1989, 2, 22),
831833
};
832834
private static readonly Card multipleVcardFourContactsInstanceFour = singleVcardFourContactInstance;
833835
#endregion
@@ -891,7 +893,8 @@ public static class ContactData
891893
ContactMails = new EmailInfo[]
892894
{
893895
new EmailInfo(0, Array.Empty<string>(), new string[] { "INTERNET" }, "[email protected]")
894-
}
896+
},
897+
ContactBirthdate = new DateTime(1963, 9, 21),
895898
};
896899
private static readonly Card vcardThreeOldSampleInstanceTwo = new
897900
(

VisualCard/Converters/MeCard.cs

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,6 @@ public static List<BaseVcardParser> GetContactsFromMeCardString(string meCardStr
8383
var nameSplits = value.Substring(2).Split(',');
8484
fullName = $"{nameSplits[1]} {nameSplits[0]}";
8585
}
86-
87-
// As VisualCard doesn't support ADR: yet, why don't we just make it ADR; until we improve type detecion?
88-
if (value.StartsWith("ADR:"))
89-
values[i] = $"ADR;TYPE=HOME{values[i].Substring(3)}";
90-
91-
// As VisualCard doesn't support EMAIL: yet, why don't we just make it EMAIL; until we improve type detecion?
92-
if (value.StartsWith("EMAIL:"))
93-
values[i] = $"EMAIL;TYPE=HOME{values[i].Substring(5)}";
94-
95-
// MeCard stores birthday date in this format:
96-
// 19700310
97-
// Digit 1-4: Year
98-
// Digit 5-6: Month
99-
// Digit 7-8: Day
100-
// However, .NET's DateTime doesn't support it, so we verify the number, split it, and make an appropriate string for this.
101-
if (value.StartsWith("BDAY:"))
102-
{
103-
int birthNum = int.Parse(value.Substring(5));
104-
var birthDigits = GetDigits(birthNum).ToList();
105-
int birthYear = (birthDigits[0] * 1000) + (birthDigits[1] * 100) + (birthDigits[2] * 10) + birthDigits[3];
106-
int birthMonth = (birthDigits[4] * 10) + birthDigits[5];
107-
int birthDay = (birthDigits[6] * 10) + birthDigits[7];
108-
var birthDate = new DateTime(birthYear, birthMonth, birthDay);
109-
values[i] = $"BDAY:{birthDate:g}";
110-
}
11186
}
11287

11388
// Install the values!
@@ -132,18 +107,5 @@ public static List<BaseVcardParser> GetContactsFromMeCardString(string meCardStr
132107
return cardParsers;
133108
}
134109

135-
private static IEnumerable<int> GetDigits(int num)
136-
{
137-
int individualFactor = 0;
138-
int tennerFactor = Convert.ToInt32(Math.Pow(10, num.ToString().Length));
139-
while (tennerFactor > 1)
140-
{
141-
num -= tennerFactor * individualFactor;
142-
tennerFactor /= 10;
143-
individualFactor = num / tennerFactor;
144-
yield return individualFactor;
145-
}
146-
}
147-
148110
}
149111
}

0 commit comments

Comments
 (0)