1 // ContactDataObject.cpp - Client Data Object.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include "ContactDataObject.h"
21 ContactLoadStatus ContactDataObject::LoadFile(wxString Filename){
23 if (!wxFileExists(Filename)){
25 return CONTACTLOAD_FILEMISSING;
31 if (!ContactFile.Open(Filename, wxFile::read, wxS_DEFAULT)){
33 return CONTACTLOAD_FILEERROR;
37 // Check that the vCard is a valid vCard 4.0 file.
39 vCard vCard4FormatCheck;
41 vCard4FormatCheck.LoadFile(Filename);
43 if (vCard4FormatCheck.Get("VERSION") != wxT("4.0")){
45 return CONTACTLOAD_FILEINVALIDFORMAT;
49 // Check that the vCard meets the base specification.
51 if (!vCard4FormatCheck.MeetBaseSpecification()){
53 return CONTACTLOAD_FILEBASESPECFAIL;
57 wxStringTokenizer wSTContactFileLines(vCard4FormatCheck.WriteString(), wxT("\r\n"));
59 std::map<int, wxString> ContactFileLines;
61 int ContactLineSeek = 0;
63 while (wSTContactFileLines.HasMoreTokens() == TRUE){
65 wxString ContactLine = wSTContactFileLines.GetNextToken();
66 ContactFileLines.insert(std::make_pair(ContactLineSeek, ContactLine));
71 wxString wxSPropertyNextLine;
73 bool ExtraLineSeek = TRUE;
74 bool QuoteMode = FALSE;
75 bool PropertyFind = TRUE;
76 bool KindProcessed = FALSE;
77 bool NameProcessed = FALSE;
78 bool GenderProcessed = FALSE;
79 bool BirthdayProcessed = FALSE;
80 bool AnniversaryProcessed = FALSE;
81 int ContactLineLen = 0;
82 int QuoteBreakPoint = 0;
85 int NicknameCount = 0;
87 wxString PropertyLine;
88 wxString PropertySeg1;
89 wxString PropertySeg2;
90 wxString PropertyNextLine;
93 for (std::map<int,wxString>::iterator iter = ContactFileLines.begin();
94 iter != ContactFileLines.end(); ++iter){
102 PropertyLine.Clear();
103 PropertySeg1.Clear();
104 PropertySeg2.Clear();
107 ContactLine = iter->second;
109 while (ExtraLineSeek == TRUE){
111 // Check if there is extra data on the next line
112 // (indicated by space or tab at the start) and add data.
116 if (iter == ContactFileLines.end()){
123 PropertyNextLine = iter->second;
125 if (PropertyNextLine.Mid(0, 1) == wxT(" ") || PropertyNextLine.Mid(0, 1) == wxT("\t")){
127 PropertyNextLine.Remove(0, 1);
128 ContactLine.Append(PropertyNextLine);
133 ExtraLineSeek = FALSE;
139 ContactLineLen = ContactLine.Len();
141 // Make sure we are not in quotation mode.
142 // Make sure colon does not have \ or \\ before it.
144 for (int i = 0; i <= ContactLineLen; i++){
146 if ((ContactLine.Mid(i, 1) == wxT(";") || ContactLine.Mid(i, 1) == wxT(":")) && PropertyFind == TRUE){
148 PropertyFind = FALSE;
150 } else if (PropertyFind == TRUE){
152 Property.Append(ContactLine.Mid(i, 1));
156 if (ContactLine.Mid(i, 1) == wxT("\"")){
158 if (QuoteMode == TRUE){
170 if (ContactLine.Mid(i, 1) == wxT(":") && ContactLine.Mid((i - 1), 1) != wxT("\\") && QuoteMode == FALSE){
179 // Split that line at the point into two variables (ignore the colon).
181 PropertySeg1 = ContactLine.Mid(0, QuoteBreakPoint);
182 PropertySeg2 = ContactLine.Mid((QuoteBreakPoint + 1));
184 if (Property == wxT("KIND") && KindProcessed == FALSE){
186 ProcessKind(PropertySeg2);
188 } else if (Property == wxT("MEMBER")){
190 ProcessMember(PropertySeg1, PropertySeg2, &GroupCount);
193 } else if (Property == wxT("FN")){
195 ProcessFN(PropertySeg1, PropertySeg2, &FNCount);
198 } else if (Property == wxT("N") && NameProcessed == FALSE){
200 ProcessN(PropertySeg1, PropertySeg2);
201 NameProcessed = TRUE;
203 } else if (Property == wxT("NICKNAME")){
205 ProcessNickname(PropertySeg1, PropertySeg2, &NicknameCount);
208 } else if (Property == wxT("GENDER") && GenderProcessed == FALSE){
210 ProcessGender(PropertySeg1, PropertySeg2);
211 GenderProcessed = TRUE;
213 } else if (Property == wxT("BDAY") && BirthdayProcessed == FALSE){
215 ProcessBirthday(PropertySeg1, PropertySeg2);
216 BirthdayProcessed = TRUE;
218 } else if (Property == wxT("ANNIVERSARY") && AnniversaryProcessed == FALSE){
220 ProcessAnniversary(PropertySeg1, PropertySeg2);
221 AnniversaryProcessed = TRUE;
227 return CONTACTLOAD_OK;
231 void ContactDataObject::ProcessKind(wxString KindType){
233 if (KindType == wxT("individual")){
235 ContactKind = CONTACTKIND_INDIVIDUAL;
237 } else if (KindType == wxT("group")){
239 ContactKind = CONTACTKIND_GROUP;
241 } else if (KindType == wxT("org")){
243 ContactKind = CONTACTKIND_ORGANISATION;
245 } else if (KindType == wxT("location")){
247 ContactKind = CONTACTKIND_LOCATION;
251 ContactKind = CONTACTKIND_NONE;
256 void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySeg2, int *GroupCount){
258 std::map<int, int> SplitPoints;
259 std::map<int, int> SplitLength;
261 int intPrevValue = 8;
265 SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
269 wxString PropertyName;
270 wxString PropertyValue;
271 wxString PropertyData;
272 wxString PropertyTokens;
273 std::map<int,int>::iterator SLiter;
274 bool FirstToken = TRUE;
276 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
277 intiter != SplitPoints.end(); ++intiter){
279 SLiter = SplitLength.find(intiter->first);
281 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
283 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
284 PropertyName = PropertyElement.GetNextToken();
285 PropertyValue = PropertyElement.GetNextToken();
287 intPrevValue = intiter->second;
289 CaptureString(&PropertyValue, FALSE);
291 if (PropertyName == wxT("ALTID")){
293 GroupsListAltID.erase(*GroupCount);
294 GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
296 } else if (PropertyName == wxT("PID")){
298 GroupsListPID.erase(*GroupCount);
299 GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
301 } else if (PropertyName == wxT("PREF")){
303 int PriorityNumber = 0;
304 bool ValidNumber = TRUE;
307 PriorityNumber = std::stoi(PropertyValue.ToStdString());
310 catch(std::invalid_argument &e){
314 if (ValidNumber == TRUE){
316 GroupsListPref.erase(*GroupCount);
317 GroupsListPref.insert(std::make_pair(*GroupCount, PriorityNumber));
321 } else if (PropertyName == wxT("MEDIATYPE")){
323 GroupsListMediaType.erase(*GroupCount);
324 GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
326 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
328 if (FirstToken == TRUE){
330 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
335 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
343 GroupsList.insert(std::make_pair(*GroupCount, PropertySeg2));
345 if (!PropertyTokens.IsEmpty()){
347 GroupsListTokens.insert(std::make_pair(*GroupCount, PropertyTokens));
354 void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2, int *FNCount){
356 std::map<int, int> SplitPoints;
357 std::map<int, int> SplitLength;
359 int intPrevValue = 4;
363 SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
367 wxString PropertyName;
368 wxString PropertyValue;
369 wxString PropertyData;
370 wxString PropertyTokens;
371 std::map<int,int>::iterator SLiter;
372 bool FirstToken = TRUE;
374 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
375 intiter != SplitPoints.end(); ++intiter){
377 SLiter = SplitLength.find(intiter->first);
379 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
381 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
382 PropertyName = PropertyElement.GetNextToken();
383 PropertyValue = PropertyElement.GetNextToken();
385 intPrevValue = intiter->second;
387 CaptureString(&PropertyValue, FALSE);
389 if (PropertyName == wxT("TYPE")){
391 if (!PropertyValue.IsEmpty() || PropertyValue == wxT("home") ||
392 PropertyValue == wxT("work") ){
394 FullNamesListType.erase(*FNCount);
395 FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
399 } else if (PropertyName == wxT("LANGUAGE")){
401 FullNamesListLanguage.erase(*FNCount);
402 FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
404 } else if (PropertyName == wxT("ALTID")){
406 FullNamesListAltID.erase(*FNCount);
407 FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
409 } else if (PropertyName == wxT("PID")){
411 FullNamesListPID.erase(*FNCount);
412 FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
414 } else if (PropertyName == wxT("PREF")){
416 int PriorityNumber = 0;
417 bool ValidNumber = TRUE;
420 PriorityNumber = std::stoi(PropertyValue.ToStdString());
423 catch(std::invalid_argument &e){
427 if (ValidNumber == TRUE){
429 FullNamesListPref.erase(*FNCount);
430 FullNamesListPref.insert(std::make_pair(*FNCount, PriorityNumber));
434 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
436 if (FirstToken == TRUE){
438 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
443 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
451 FullNamesList.insert(std::make_pair(*FNCount, PropertySeg2));
453 if (!PropertyTokens.IsEmpty()){
455 FullNamesListTokens.insert(std::make_pair(*FNCount, PropertyTokens));
461 void ContactDataObject::ProcessN(wxString PropertySeg1, wxString PropertySeg2){
463 std::map<int, int> SplitPoints;
464 std::map<int, int> SplitLength;
466 int intPrevValue = 3;
470 SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
474 wxString PropertyName;
475 wxString PropertyValue;
476 wxString PropertyData;
477 wxString PropertyTokens;
478 std::map<int,int>::iterator SLiter;
479 bool FirstToken = TRUE;
481 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
482 intiter != SplitPoints.end(); ++intiter){
484 SLiter = SplitLength.find(intiter->first);
486 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
488 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
489 PropertyName = PropertyElement.GetNextToken();
490 PropertyValue = PropertyElement.GetNextToken();
492 intPrevValue = intiter->second;
494 CaptureString(&PropertyValue, FALSE);
496 if (PropertyName == wxT("ALTID")){
498 NameAltID = PropertyValue;
500 } else if (PropertyName == wxT("LANGUAGE")){
502 NameLanguage = PropertyValue;
504 } else if (PropertyName == wxT("SORT-AS")){
506 if (PropertyValue.Left(1) == wxT("\"") && PropertyValue.Right(1) == wxT("\"") &&
507 PropertyValue.Len() >= 3){
508 NameDisplayAs = PropertyValue.Mid(1, (PropertyValue.Len() - 2));
511 } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
513 if (FirstToken == TRUE){
515 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
520 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
528 // Split the name data.
530 int intSplitSeek = 0;
531 int intSplitsFound = 0;
532 int intSplitSize = 0;
533 int intPropertyLen = PropertySeg2.Len();
535 std::map<int,wxString> NameValues;
538 for (int i = 0; i <= intPropertyLen; i++){
540 if (PropertySeg2.Mid(i, 1) == wxT(";") && PropertySeg2.Mid((i - 1), 1) != wxT("\\")){
542 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, intSplitSize)));
547 if (intSplitsFound == 4){
549 NameValues.insert(std::make_pair(++intSplitsFound, PropertySeg2.Mid(intSplitSeek, wxString::npos)));
563 // Split the data into several parts.
565 for (std::map<int, wxString>::iterator iter = NameValues.begin();
566 iter != NameValues.end(); ++iter){
568 if (iter->first == 1){
570 // Deal with family name.
572 NameSurname = iter->second;
574 } else if (iter->first == 2){
576 // Deal with given names.
578 NameForename = iter->second;
580 } else if (iter->first == 3){
582 // Deal with additional names.
584 NameOtherNames = iter->second;
586 } else if (iter->first == 4){
588 // Deal with honorifix prefixes and suffixes.
590 NameTitle = iter->second;
594 if (iter == NameValues.end()){
600 NameSuffix = iter->second;
606 // Add the name token data.
608 if (!PropertyTokens.IsEmpty()){
610 NameTokens = PropertyTokens;
616 void ContactDataObject::ProcessNickname(wxString PropertySeg1, wxString PropertySeg2, int *NicknameCount){
618 std::map<int, int> SplitPoints;
619 std::map<int, int> SplitLength;
621 int intPrevValue = 10;
624 SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
628 PropertyType PropType;
630 // Look for type before continuing.
632 CheckType(&PropertySeg1, &SplitPoints, &SplitLength, &intPrevValue, &PropType);
636 std::map<int, wxString> *NicknamesList = NULL;
637 std::map<int, wxString> *NicknamesListType = NULL;
638 std::map<int, wxString> *NicknamesListLanguage = NULL;
639 std::map<int, wxString> *NicknamesListAltID = NULL;
640 std::map<int, wxString> *NicknamesListPID = NULL;
641 std::map<int, wxString> *NicknamesListTokens = NULL;
642 std::map<int, int> *NicknamesListPref = NULL;
646 NicknamesList = &GeneralNicknamesList;
647 NicknamesListType = &GeneralNicknamesListType;
648 NicknamesListLanguage = &GeneralNicknamesListLanguage;
649 NicknamesListAltID = &GeneralNicknamesListAltID;
650 NicknamesListPID = &GeneralNicknamesListPID;
651 NicknamesListTokens = &GeneralNicknamesListTokens;
652 NicknamesListPref = &GeneralNicknamesListPref;
655 NicknamesList = &HomeNicknamesList;
656 NicknamesListType = &HomeNicknamesListType;
657 NicknamesListLanguage = &HomeNicknamesListLanguage;
658 NicknamesListAltID = &HomeNicknamesListAltID;
659 NicknamesListPID = &HomeNicknamesListPID;
660 NicknamesListTokens = &HomeNicknamesListTokens;
661 NicknamesListPref = &HomeNicknamesListPref;
664 NicknamesList = &BusinessNicknamesList;
665 NicknamesListType = &BusinessNicknamesListType;
666 NicknamesListLanguage = &BusinessNicknamesListLanguage;
667 NicknamesListAltID = &BusinessNicknamesListAltID;
668 NicknamesListPID = &BusinessNicknamesListPID;
669 NicknamesListTokens = &BusinessNicknamesListTokens;
670 NicknamesListPref = &BusinessNicknamesListPref;
674 std::map<int, int>::iterator SLiter;
675 wxString PropertyData;
676 wxString PropertyName;
677 wxString PropertyValue;
678 wxString PropertyTokens;
679 bool FirstToken = TRUE;
681 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
682 intiter != SplitPoints.end(); ++intiter){
684 SLiter = SplitLength.find(intiter->first);
686 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
688 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
689 PropertyName = PropertyElement.GetNextToken();
690 PropertyValue = PropertyElement.GetNextToken();
692 intPrevValue = intiter->second;
694 CaptureString(&PropertyValue, FALSE);
696 if (PropertyName == wxT("ALTID")){
698 NicknamesListAltID->erase(*NicknameCount);
699 NicknamesListAltID->insert(std::make_pair(*NicknameCount, PropertyValue));
701 } else if (PropertyName == wxT("PID")){
703 NicknamesListPID->erase(*NicknameCount);
704 NicknamesListPID->insert(std::make_pair(*NicknameCount, PropertyValue));
706 } else if (PropertyName == wxT("PREF")){
708 int PriorityNumber = 0;
709 bool ValidNumber = TRUE;
712 PriorityNumber = std::stoi(PropertyValue.ToStdString());
715 catch(std::invalid_argument &e){
719 if (ValidNumber == TRUE){
721 NicknamesListPref->erase(*NicknameCount);
722 NicknamesListPref->insert(std::make_pair(*NicknameCount, PriorityNumber));
726 } else if (PropertyName == wxT("LANGUAGE")){
728 NicknamesListLanguage->erase(*NicknameCount);
729 NicknamesListLanguage->insert(std::make_pair(*NicknameCount, PropertyValue));
733 // Something else we don't know about so append
734 // to the tokens variable.
736 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
738 if (FirstToken == TRUE){
740 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
745 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
755 NicknamesList->insert(std::make_pair(*NicknameCount, PropertySeg2));
757 // Add the name token data.
759 if (!PropertyTokens.IsEmpty()){
761 NicknamesListTokens->insert(std::make_pair(*NicknameCount, PropertyTokens));
767 void ContactDataObject::ProcessGender(wxString PropertySeg1, wxString PropertySeg2){
769 std::map<int, int> SplitPoints;
770 std::map<int, int> SplitLength;
771 std::map<int, int>::iterator SLiter;
772 wxString PropertyData;
773 wxString PropertyName;
774 wxString PropertyValue;
775 wxString PropertyTokens;
776 bool FirstToken = TRUE;
777 int intPrevValue = 8;
779 SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
783 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
784 intiter != SplitPoints.end(); ++intiter){
786 SLiter = SplitLength.find(intiter->first);
788 PropertyData = PropertySeg1.Mid(intPrevValue, (SLiter->second));
790 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
791 PropertyName = PropertyElement.GetNextToken();
792 PropertyValue = PropertyElement.GetNextToken();
794 intPrevValue = intiter->second;
796 // Process properties.
798 size_t intPropertyValueLen = PropertyValue.Len();
800 if (PropertyValue.Mid((intPropertyValueLen - 1), 1) == wxT("\"")){
802 PropertyValue.Trim();
803 PropertyValue.RemoveLast();
807 if (PropertyValue.Mid(0, 1) == wxT("\"")){
809 PropertyValue.Remove(0, 1);
813 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
815 if (FirstToken == TRUE){
817 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
822 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
830 wxStringTokenizer GenderData (PropertySeg2, wxT(";"));
832 wxString GenderComponent;
834 if (GenderData.CountTokens() >= 2){
836 Gender = GenderData.GetNextToken();
837 GenderDetails = GenderData.GetString();
839 CaptureString(&GenderDetails, FALSE);
843 Gender = GenderData.GetNextToken();
847 if (!PropertyTokens.IsEmpty()){
849 GenderTokens = PropertyTokens;
855 void ContactDataObject::ProcessBirthday(wxString PropertySeg1, wxString PropertySeg2){
857 // Process date. Preserve the remainder in the string.
859 std::map<int, int> SplitPoints;
860 std::map<int, int> SplitLength;
861 std::map<int, int>::iterator SLiter;
862 wxString PropertyData;
863 wxString PropertyName;
864 wxString PropertyValue;
865 wxString PropertyTokens;
866 bool BirthdayText = FALSE;
867 int intPrevValue = 6;
869 SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
873 // Look for type before continuing.
875 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
876 intiter != SplitPoints.end(); ++intiter){
878 SLiter = SplitLength.find(intiter->first);
880 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
882 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
883 PropertyName = PropertyElement.GetNextToken();
884 PropertyValue = PropertyElement.GetNextToken();
886 intPrevValue = intiter->second;
888 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && BirthdayText == FALSE){
890 CaptureString(&PropertySeg2, FALSE);
891 Birthday = PropertySeg2;
898 // Setup blank lines for later on.
901 bool FirstToken = TRUE;
903 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
904 intiter != SplitPoints.end(); ++intiter){
906 SLiter = SplitLength.find(intiter->first);
908 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
910 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
911 PropertyName = PropertyElement.GetNextToken();
912 PropertyValue = PropertyElement.GetNextToken();
914 intPrevValue = intiter->second;
916 // Process properties.
918 CaptureString(&PropertyValue, FALSE);
920 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
922 PropertyValue.Trim();
923 PropertyValue.RemoveLast();
927 if (PropertyValue.Mid(0, 1) == wxT("\"")){
929 PropertyValue.Remove(0, 1);
933 if (PropertyName == wxT("ALTID")){
935 BirthdayAltID = PropertyValue;
937 } else if (PropertyName == wxT("CALSCALE")){
939 BirthdayCalScale = PropertyValue;
941 } else if (PropertyName != wxT("VALUE")) {
943 // Something else we don't know about so append
944 // to the tokens variable.
946 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
948 if (FirstToken == TRUE){
950 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
955 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
965 // Add the data to the variables and form.
967 if (BirthdayText == FALSE){
969 Birthday = PropertySeg2;
973 if (!PropertyTokens.IsEmpty()){
975 BirthdayTokens = PropertyTokens;
981 void ContactDataObject::ProcessAnniversary(wxString PropertySeg1, wxString PropertySeg2){
983 // Process date. Preserve the remainder in the string.
985 std::map<int, int> SplitPoints;
986 std::map<int, int> SplitLength;
987 std::map<int, int>::iterator SLiter;
988 wxString PropertyData;
989 wxString PropertyName;
990 wxString PropertyValue;
991 wxString PropertyTokens;
992 bool AnniversaryText = FALSE;
993 int intPrevValue = 6;
995 SplitValues(&PropertySeg1, &SplitPoints, &SplitLength, intPrevValue);
999 // Look for type before continuing.
1001 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
1002 intiter != SplitPoints.end(); ++intiter){
1004 SLiter = SplitLength.find(intiter->first);
1006 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1008 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1009 PropertyName = PropertyElement.GetNextToken();
1010 PropertyValue = PropertyElement.GetNextToken();
1012 intPrevValue = intiter->second;
1014 if (PropertyName == wxT("VALUE") && PropertyValue == wxT("text") && AnniversaryText == FALSE){
1016 CaptureString(&PropertySeg2, FALSE);
1017 Anniversary = PropertySeg2;
1018 AnniversaryText = TRUE;
1024 // Setup blank lines for later on.
1027 bool FirstToken = TRUE;
1029 for (std::map<int, int>::iterator intiter = SplitPoints.begin();
1030 intiter != SplitPoints.end(); ++intiter){
1032 SLiter = SplitLength.find(intiter->first);
1034 PropertyData = PropertySeg1.Mid(intPrevValue, SLiter->second);
1036 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1037 PropertyName = PropertyElement.GetNextToken();
1038 PropertyValue = PropertyElement.GetNextToken();
1040 intPrevValue = intiter->second;
1042 // Process properties.
1044 CaptureString(&PropertyValue, FALSE);
1046 if (PropertyValue.Mid((PropertyValue.Len() - 1), 1) == wxT("\"")){
1048 PropertyValue.Trim();
1049 PropertyValue.RemoveLast();
1053 if (PropertyValue.Mid(0, 1) == wxT("\"")){
1055 PropertyValue.Remove(0, 1);
1059 if (PropertyName == wxT("ALTID")){
1061 AnniversaryAltID = PropertyValue;
1063 } else if (PropertyName == wxT("CALSCALE")){
1065 AnniversaryCalScale = PropertyValue;
1067 } else if (PropertyName != wxT("VALUE")) {
1069 // Something else we don't know about so append
1070 // to the tokens variable.
1072 if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
1074 if (FirstToken == TRUE){
1076 PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
1081 PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
1091 // Add the data to the variables and form.
1093 if (AnniversaryText == FALSE){
1095 Anniversary = PropertySeg2;
1099 if (!PropertyTokens.IsEmpty()){
1101 AnniversaryTokens = PropertyTokens;
1107 void SplitValues(wxString *PropertyLine,
1108 std::map<int,int> *SplitPoints,
1109 std::map<int,int> *SplitLength,
1112 size_t intPropertyLen = PropertyLine->Len();
1113 int intSplitsFound = 0;
1114 int intSplitSize = 0;
1115 int intSplitSeek = 0;
1117 for (int i = intSize; i <= intPropertyLen; i++){
1121 if (PropertyLine->Mid(i, 1) == wxT(";") &&
1122 PropertyLine->Mid((i - 1), 1) != wxT("\\")){
1124 if (intSplitsFound == 0){
1126 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize)));
1130 SplitLength->insert(std::make_pair(intSplitsFound, (intSplitSize - 1)));
1134 SplitPoints->insert(std::make_pair(intSplitsFound, (i + 1)));
1144 if (intSplitsFound == 0){
1146 SplitPoints->insert(std::make_pair(intSplitsFound, (8 + 1)));
1147 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1151 SplitPoints->insert(std::make_pair(intSplitsFound, (intSplitSeek + 1)));
1152 SplitLength->insert(std::make_pair(intSplitsFound, intSplitSize));
1158 void CheckType(wxString *PropertySeg1,
1159 std::map<int,int> *SplitPoints,
1160 std::map<int,int> *SplitLength,
1162 PropertyType *PropType){
1164 wxString PropertyData;
1165 wxString PropertyName;
1166 wxString PropertyValue;
1167 std::map<int,int>::iterator SLiter;
1169 for (std::map<int, int>::iterator intiter = SplitPoints->begin();
1170 intiter != SplitPoints->end(); ++intiter){
1172 SLiter = SplitLength->find(intiter->first);
1174 PropertyData = PropertySeg1->Mid(*intPrevValue, (SLiter->second));
1176 wxStringTokenizer PropertyElement (PropertyData, wxT("="));
1177 PropertyName = PropertyElement.GetNextToken();
1178 PropertyValue = PropertyElement.GetNextToken();
1180 *intPrevValue = intiter->second;
1182 if (PropertyName == wxT("TYPE")){
1184 if (PropertyValue == wxT("work")){
1186 *PropType = PROPERTY_WORK;
1188 } else if (PropertyValue == wxT("home")){
1190 *PropType = PROPERTY_HOME;
1194 *PropType = PROPERTY_NONE;