From: Steve Brokenshire Date: Sun, 13 Dec 2015 00:47:41 +0000 (+0000) Subject: Finished remaining code and unit tests for the N vCard property for ContactDataObject. X-Git-Tag: release-0.09~237 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=1c717d77d60dabd298622aec1f022094bce77c23;p=xestiaab%2F.git Finished remaining code and unit tests for the N vCard property for ContactDataObject. --- diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index 5f9ca27..55d2a14 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -505,6 +505,82 @@ void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){ // Split the name data. + int intSplitSeek = 0; + int intSplitsFound = 0; + int intSplitSize = 0; + int intPropertyLen = PropertySeg2.Len(); + + std::map NameValues; + intPrevValue = 0; + + for (int i = 0; i <= intPropertyLen; i++){ + + if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){ + + NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize))); + + intSplitSeek = i; + intSplitSeek++; + + if (intSplitsFound == 4){ + + NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos))); + break; + + } + + intSplitSize = 0; + continue; + + } + + intSplitSize++; + + } + + // Split the data into several parts. + + for (std::map::iterator iter = NameValues.begin(); + iter != NameValues.end(); ++iter){ + + if (iter->first == 1){ + + // Deal with family name. + + NameSurname = iter->second; + + } else if (iter->first == 2){ + + // Deal with given names. + + NameForename = iter->second; + + } else if (iter->first == 3){ + + // Deal with additional names. + + NameOtherNames = iter->second; + + } else if (iter->first == 4){ + + // Deal with honorifix prefixes and suffixes. + + NameTitle = iter->second; + + iter++; + + if (iter == NameValues.end()){ + + break; + + } + + NameSuffix = iter->second; + + } + + } + // Add the name token data. if (!PropertyTokens.IsEmpty()){ diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index 9b3cdcd..2688e29 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -4,5 +4,6 @@ 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;SORT-AS="Contact,Test";TEST=Yes:Test +N;ALTID=3;LANGUAGE=kw;SORT-AS="Contact,Test";TEST=Yes:Contact;Test;Example;R + obot;LOONY END:VCARD diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index c573175..10f0b5d 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -133,7 +133,11 @@ TEST(ContactLoad, ContactLoadTests){ // Check that the name has been read (N). + ASSERT_EQ("Contact", TestFile.NameSurname); ASSERT_EQ("Test", TestFile.NameForename); + ASSERT_EQ("Example", TestFile.NameOtherNames); + ASSERT_EQ("Robot", TestFile.NameTitle); + ASSERT_EQ("LOONY", TestFile.NameSuffix); // Check the ALTID parameter.