From b19bbc6c6d83edfefba9c98e78a57d21eb8aa1a8 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sat, 12 Dec 2015 21:41:38 +0000 Subject: [PATCH] Added SORT-AS and extra tokens code and unit tests for the N vCard parameter in ContactDataObject. --- source/contacteditor/ContactDataObject.cpp | 30 ++++++++++++++++++++++ source/tests/LoadCheck-Load4.vcf | 2 +- source/tests/xestiaab_contactload.h | 19 +++++++++++--- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index 54e0bfd..5f9ca27 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -479,9 +479,39 @@ void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){ NameLanguage = PropertyValue; + } else if (PropertyName == wxT("SORT-AS")){ + + if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") && + PropertyValue.Len() >= 3){ + NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2)); + } + + } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){ + + if (FirstToken == TRUE){ + + PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue); + FirstToken = FALSE; + + } else { + + PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue); + + } + } } + + // Split the name data. + + // Add the name token data. + + if (!PropertyTokens.IsEmpty()){ + + NameTokens = PropertyTokens; + + } } diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index 866e808..9b3cdcd 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -4,5 +4,5 @@ KIND:individual MEMBER;ALTID=35;PID=40;PREF=45;MEDIATYPE=text/plain;EXAMPLE=Meep:7a2af44d-64 31-4797-a55f-d86d56304fda FN;TYPE=work;LANGUAGE=kw;ALTID=500;PID=40;PREF=45;EXAMPLE=Baaa:Test Contact -N;ALTID=3;LANGUAGE=kw:Test +N;ALTID=3;LANGUAGE=kw;SORT-AS="Contact,Test";TEST=Yes:Test END:VCARD diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index 4585abc..c573175 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -133,10 +133,23 @@ TEST(ContactLoad, ContactLoadTests){ // Check that the name has been read (N). - ASSERT_EQ("Test", TestFile.NameForename); - ASSERT_EQ("3", TestFile.NameAltID); - ASSERT_EQ("kw", TestFile.NameLanguage); + ASSERT_EQ("Test", TestFile.NameForename); + + // Check the ALTID parameter. + + ASSERT_EQ("3", TestFile.NameAltID); + + // Check the LANGUAGE parameter. + + ASSERT_EQ("kw", TestFile.NameLanguage); + + // Check the SORT-AS parameter. + + ASSERT_EQ("Contact,Test", TestFile.NameDisplayAs); + // Check the extra tokens parameter. + + ASSERT_EQ("TEST=Yes", TestFile.NameTokens); } -- 2.39.5