int EmailCount = 0;
int IMCount = 0;
int TelephoneCount = 0;
+ int LanguageCount = 0;
wxString ContactLine;
wxString PropertyLine;
wxString PropertySeg1;
ProcessTelephone(PropertySeg1, PropertySeg2, &TelephoneCount);
TelephoneCount++;
+ } else if (Property == wxT("LANG")){
+
+ // See frmContactEditor-LoadLanguage.cpp
+
+ ProcessLanguage(PropertySeg1, PropertySeg2, &LanguageCount);
+ LanguageCount++;
+
}
}
IMListTokens->insert(std::make_pair(*IMCount, PropertyTokens));
- }
+ }
}
}
+void ContactDataObject::ProcessLanguage(wxString PropertySeg1, wxString PropertySeg2, int *LanguageCount){
+
+ std::map<int, int> SplitPoints;
+ std::map<int, int> SplitLength;
+
+ int intPrevValue = 6;
+ int intPref = 0;
+
+ SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
+
+ intPrevValue = 5;
+
+ PropertyType PropType = PROPERTY_NONE;
+
+ // Look for type before continuing.
+
+ CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
+
+ std::map<int, wxString> *LanguageList = NULL;
+ std::map<int, wxString> *LanguageListType = NULL;
+ std::map<int, wxString> *LanguageListAltID = NULL;
+ std::map<int, wxString> *LanguageListPID = NULL;
+ std::map<int, wxString> *LanguageListTokens = NULL;
+ std::map<int, int> *LanguageListPref = NULL;
+
+ switch(PropType){
+ case PROPERTY_NONE:
+ LanguageList = &GeneralLanguageList;
+ LanguageListType = &GeneralLanguageListType;
+ LanguageListAltID = &GeneralLanguageListAltID;
+ LanguageListPID = &GeneralLanguageListPID;
+ LanguageListTokens = &GeneralLanguageListTokens;
+ LanguageListPref = &GeneralLanguageListPref;
+ break;
+ case PROPERTY_HOME:
+ LanguageList = &HomeLanguageList;
+ LanguageListType = &HomeLanguageListType;
+ LanguageListAltID = &HomeLanguageListAltID;
+ LanguageListPID = &HomeLanguageListPID;
+ LanguageListTokens = &HomeLanguageListTokens;
+ LanguageListPref = &HomeLanguageListPref;
+ break;
+ case PROPERTY_WORK:
+ LanguageList = &BusinessLanguageList;
+ LanguageListType = &BusinessLanguageListType;
+ LanguageListAltID = &BusinessLanguageListAltID;
+ LanguageListPID = &BusinessLanguageListPID;
+ LanguageListTokens = &BusinessLanguageListTokens;
+ LanguageListPref = &BusinessLanguageListPref;
+ break;
+ }
+
+ intPrevValue = 5;
+
+ std::map<int,int>::iterator SLiter;
+ wxString PropertyData;
+ wxString PropertyName;
+ wxString PropertyValue;
+ wxString PropertyTokens;
+ bool FirstToken = TRUE;
+
+ for (std::map<int, int>::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);
+
+ // Process properties.
+
+ if (PropertyName == wxT("ALTID")){
+
+ LanguageListAltID->erase(*LanguageCount);
+ LanguageListAltID->insert(std::make_pair(*LanguageCount, PropertyValue));
+
+ } else if (PropertyName == wxT("PID")){
+
+ LanguageListPID->erase(*LanguageCount);
+ LanguageListPID->insert(std::make_pair(*LanguageCount, PropertyValue));
+
+ } else if (PropertyName == wxT("PREF")){
+
+ int PriorityNumber = 0;
+ bool ValidNumber = TRUE;
+
+ try{
+ PriorityNumber = std::stoi(PropertyValue.ToStdString());
+ }
+
+ catch(std::invalid_argument &e){
+ ValidNumber = FALSE;
+ }
+
+ if (ValidNumber == TRUE){
+
+ LanguageListPref->erase(*LanguageCount);
+ LanguageListPref->insert(std::make_pair(*LanguageCount, PriorityNumber));
+
+ }
+
+ } else {
+
+ if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
+
+ if (FirstToken == TRUE){
+
+ PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
+ FirstToken = FALSE;
+
+ } else {
+
+ PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
+
+ }
+
+ }
+
+ }
+
+ }
+
+ LanguageList->insert(std::make_pair(*LanguageCount, PropertySeg2));
+
+ // Add the name token data.
+
+ if (!PropertyTokens.IsEmpty()){
+
+ LanguageListTokens->insert(std::make_pair(*LanguageCount, PropertyTokens));
+
+ }
+
+}
+
void SplitValues(wxString *PropertyLine,
std::map<int,int> *SplitPoints,
std::map<int,int> *SplitLength,
void ProcessEmail(wxString PropertySeg1, wxString PropertySeg2, int *EmailCount);
void ProcessIM(wxString PropertySeg1, wxString PropertySeg2, int *IMCount);
void ProcessTelephone(wxString PropertySeg1, wxString PropertySeg2, int *TelephoneCount);
+ void ProcessLanguage(wxString PropertySeg1, wxString PropertySeg2, int *LanguageCount);
};
TEL;ALTID=10;PID=20;PREF=40;WONDERFUL=Colour;TYPE="fax,cell":tel:00000000
TEL;TYPE="home,fax";ALTID=10;PID=20;PREF=40;BUSINESS=Money:tel:00001111
TEL;TYPE="work,voice";ALTID=25;PID=50;PREF=75;BEEP=Boop:tel:22221111
+LANG;ALTID=20;PID=40;PREF=80;GELFORN=Great:kw
+LANG;TYPE=home;ALTID=22;PID=45;PREF=90;LANGUAGE=yes:en
+LANG;TYPE=work;ALTID=10;PID=15;PREF=20;FFENSTRI=ie:cy
END:VCARD
}
-TEST(ContactLoad, TelephoneTests){
+TEST(ContactLoad, LanguageTests){
+
+ ContactDataObject TestFile;
+
+ // Check that the vCard 4.0 file loads OK.
+
+ ASSERT_EQ(CONTACTLOAD_OK, TestFile.LoadFile("LoadCheck-Load4.vcf"));
+
+ std::map<int,wxString>::iterator TestFileIter;
+ std::map<int,int>::iterator TestFileIntIter;
+
+ // Start with the general language.
+
+ TestFileIter = TestFile.GeneralLanguageList.find(0);
+ ASSERT_NE(TestFile.GeneralLanguageList.end(), TestFileIter);
+ ASSERT_EQ("kw", TestFileIter->second);
+
+ // Check the ALTID section.
+
+ TestFileIter = TestFile.GeneralLanguageListAltID.find(0);
+ ASSERT_NE(TestFile.GeneralLanguageListAltID.end(), TestFileIter);
+ ASSERT_EQ("20", TestFileIter->second);
+
+ // Check the PID section.
+
+ TestFileIter = TestFile.GeneralLanguageListPID.find(0);
+ ASSERT_NE(TestFile.GeneralLanguageListPID.end(), TestFileIter);
+ ASSERT_EQ("40", TestFileIter->second);
+
+ // Check the PREF section.
+
+ TestFileIntIter = TestFile.GeneralLanguageListPref.find(0);
+ ASSERT_NE(TestFile.GeneralLanguageListPref.end(), TestFileIntIter);
+ ASSERT_EQ(80, TestFileIntIter->second);
+
+ // Check the extra tokens.
+
+ TestFileIter = TestFile.GeneralLanguageListTokens.find(0);
+ ASSERT_NE(TestFile.GeneralLanguageListTokens.end(), TestFileIter);
+ ASSERT_EQ("GELFORN=Great", TestFileIter->second);
+
+ // Start with the home language.
+
+ TestFileIter = TestFile.HomeLanguageList.find(1);
+ ASSERT_NE(TestFile.HomeLanguageList.end(), TestFileIter);
+ ASSERT_EQ("en", TestFileIter->second);
+
+ // Check the ALTID section.
+
+ TestFileIter = TestFile.HomeLanguageListAltID.find(1);
+ ASSERT_NE(TestFile.HomeLanguageListAltID.end(), TestFileIter);
+ ASSERT_EQ("22", TestFileIter->second);
+
+ // Check the PID section.
+
+ TestFileIter = TestFile.HomeLanguageListPID.find(1);
+ ASSERT_NE(TestFile.HomeLanguageListPID.end(), TestFileIter);
+ ASSERT_EQ("45", TestFileIter->second);
+
+ // Check the PREF section.
+
+ TestFileIntIter = TestFile.HomeLanguageListPref.find(1);
+ ASSERT_NE(TestFile.HomeLanguageListPref.end(), TestFileIntIter);
+ ASSERT_EQ(90, TestFileIntIter->second);
+
+ // Check the extra tokens.
+
+ TestFileIter = TestFile.HomeLanguageListTokens.find(1);
+ ASSERT_NE(TestFile.HomeLanguageListTokens.end(), TestFileIter);
+ ASSERT_EQ("LANGUAGE=yes", TestFileIter->second);
+
+ // Start with the business language.
+
+ TestFileIter = TestFile.BusinessLanguageList.find(2);
+ ASSERT_NE(TestFile.BusinessLanguageList.end(), TestFileIter);
+ ASSERT_EQ("cy", TestFileIter->second);
+
+ // Check the ALTID section.
+
+ TestFileIter = TestFile.BusinessLanguageListAltID.find(2);
+ ASSERT_NE(TestFile.BusinessLanguageListAltID.end(), TestFileIter);
+ ASSERT_EQ("10", TestFileIter->second);
+
+ // Check the PID section.
+
+ TestFileIter = TestFile.BusinessLanguageListPID.find(2);
+ ASSERT_NE(TestFile.BusinessLanguageListPID.end(), TestFileIter);
+ ASSERT_EQ("15", TestFileIter->second);
+
+ // Check the PREF section.
+
+ TestFileIntIter = TestFile.BusinessLanguageListPref.find(2);
+ ASSERT_NE(TestFile.BusinessLanguageListPref.end(), TestFileIntIter);
+ ASSERT_EQ(20, TestFileIntIter->second);
+
+ // Check the extra tokens.
+
+ TestFileIter = TestFile.BusinessLanguageListTokens.find(2);
+ ASSERT_NE(TestFile.BusinessLanguageListTokens.end(), TestFileIter);
+ ASSERT_EQ("FFENSTRI=ie", TestFileIter->second);
}