From 02c28b750d6eb441da1053646ca981a4a6473b75 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sat, 12 Dec 2015 21:14:56 +0000 Subject: [PATCH] Added property value, ALTID, LANGUAGE source, header and unit tests for the N vCard property in ContactDataObject. --- source/contacteditor/ContactDataObject.cpp | 57 ++++++++++++++++++++++ source/contacteditor/ContactDataObject.h | 1 + source/tests/LoadCheck-Load4.vcf | 1 + source/tests/xestiaab_contactload.h | 7 +++ 4 files changed, 66 insertions(+) diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index 266a5e0..54e0bfd 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -74,6 +74,7 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ bool QuoteMode = FALSE; bool PropertyFind = TRUE; bool KindProcessed = FALSE; + bool NameProcessed = FALSE; int ContactLineLen = 0; int QuoteBreakPoint = 0; int GroupCount = 0; @@ -190,6 +191,11 @@ ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){ ProcessFN(PropertySeg1, PropertySeg2, &FNCount); FNCount++; + } else if (Property == wxT("N") && NameProcessed == FALSE){ + + ProcessN(PropertySeg1, PropertySeg2); + NameProcessed = TRUE; + } } @@ -428,6 +434,57 @@ void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, } +void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){ + + std::map SplitPoints; + std::map SplitLength; + + int intPrevValue = 3; + int intPref = 0; + int intType = 0; + + SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue); + + intPrevValue = 2; + + NameForename = PropertySeg2; + + wxString PropertyName; + wxString PropertyValue; + wxString PropertyData; + wxString PropertyTokens; + std::map::iterator SLiter; + bool FirstToken = TRUE; + + for (std::map::iterator intiter = SplitPoints.begin(); + intiter != SplitPoints.end(); ++intiter){ + + SLiter = SplitLength.find(intiter->first); + + PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second)); + + wxStringTokenizer PropertyElement (PropertyData, wxT("=")); + PropertyName = PropertyElement.GetNextToken(); + PropertyValue = PropertyElement.GetNextToken(); + + intPrevValue = intiter->second; + + CaptureString(&PropertyValue, FALSE); + + if (PropertyName == wxT("ALTID")){ + + NameAltID = PropertyValue; + + } else if (PropertyName == wxT("LANGUAGE")){ + + NameLanguage = PropertyValue; + + } + + } + +} + void SplitValues(wxString *PropertyLine, std::map *SplitPoints, std::map *SplitLength, diff --git a/source/contacteditor/ContactDataObject.h b/source/contacteditor/ContactDataObject.h index b62c6a8..ead05b8 100644 --- a/source/contacteditor/ContactDataObject.h +++ b/source/contacteditor/ContactDataObject.h @@ -561,6 +561,7 @@ class ContactDataObject{ void ProcessKind(wxString KindData); void ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount); void ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount); + void ProcessN(wxString PropertySeg1, wxString PropertySeg2); }; diff --git a/source/tests/LoadCheck-Load4.vcf b/source/tests/LoadCheck-Load4.vcf index a3b057b..866e808 100644 --- a/source/tests/LoadCheck-Load4.vcf +++ b/source/tests/LoadCheck-Load4.vcf @@ -4,4 +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 END:VCARD diff --git a/source/tests/xestiaab_contactload.h b/source/tests/xestiaab_contactload.h index b3e53f4..4585abc 100644 --- a/source/tests/xestiaab_contactload.h +++ b/source/tests/xestiaab_contactload.h @@ -131,6 +131,13 @@ TEST(ContactLoad, ContactLoadTests){ ASSERT_NE(TestFile.FullNamesListTokens.end(), TestFileIter); ASSERT_EQ("EXAMPLE=Baaa", TestFileIter->second); + // Check that the name has been read (N). + + ASSERT_EQ("Test", TestFile.NameForename); + ASSERT_EQ("3", TestFile.NameAltID); + ASSERT_EQ("kw", TestFile.NameLanguage); + + } // TODO: Add tests for the Contact Loading process. \ No newline at end of file -- 2.39.2