Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Replaced string processing in FN with ProcessStringValue.
[xestiaab/.git] / source / contacteditor / ContactDataObject.cpp
index bc45c48..56b2846 100644 (file)
@@ -549,6 +549,7 @@ void ContactDataObject::ProcessSource(wxString PropertySeg1, wxString PropertySe
        wxString PropertyValue;
        wxString PropertyTokens;
        bool FirstToken = TRUE;
+       bool PropertyMatched = FALSE;
        int intSplitsFound = 0;
        int intSplitSize = 0;
        int intPrevValue = 8;
@@ -599,42 +600,28 @@ void ContactDataObject::ProcessSource(wxString PropertySeg1, wxString PropertySe
                
                CaptureString(&PropertyValue, FALSE);
                
-               if (PropertyName == wxT("ALTID")){
-
-                       SourceListAltID.erase(*SourceCount);
-                       SourceListAltID.insert(std::make_pair(*SourceCount, PropertyValue));
+               ProcessStringValue(&PropertyName, "ALTID", &SourceListAltID, &PropertyValue, SourceCount, &PropertyMatched);
+               ProcessStringValue(&PropertyName, "PID", &SourceListPID, &PropertyValue, SourceCount, &PropertyMatched);
+               ProcessStringValue(&PropertyName, "MEDIATYPE", &SourceListMediatype, &PropertyValue, SourceCount, &PropertyMatched);
+               ProcessIntegerValue(&PropertyName, "PREF", &SourceListPref, &PropertyValue, SourceCount, &PropertyMatched);
                
-               } else if (PropertyName == wxT("PID")){
-
-                       SourceListPID.erase(*SourceCount);
-                       SourceListPID.insert(std::make_pair(*SourceCount, PropertyValue));
+               if (PropertyMatched == TRUE){
                
-               } else if (PropertyName == wxT("PREF")){
-                       
-                       ProcessIntegerValue(&SourceListPref, &PropertyValue, SourceCount);
-
-               } else if (PropertyName == wxT("MEDIATYPE")){
+                       PropertyMatched = FALSE;
+                       continue;
                
-                       SourceListMediatype.erase(*SourceCount);
-                       SourceListMediatype.insert(std::make_pair(*SourceCount, PropertyValue));
-
-               } else {
+               }
                
-                       // Something else we don't know about so append
-                       // to the tokens variable.
-                       
-                       if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty() && PropertyName != wxT("TYPE")){
+               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);
+                       if (FirstToken == TRUE){
                                
-                               }
+                               PropertyTokens.Append(PropertyName + wxT("=") + PropertyValue);
+                               FirstToken = FALSE;
+                       
+                       } else {
+                       
+                               PropertyTokens.Append(wxT(";") + PropertyName + wxT("=") + PropertyValue);
                        
                        }
                
@@ -693,6 +680,7 @@ void ContactDataObject::ProcessXML(wxString PropertySeg1, wxString PropertySeg2,
        wxString PropertyTokens;
        std::map<int,int>::iterator SLiter;
        bool FirstToken = TRUE;
+       bool PropertyMatched = FALSE;
        
        for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
        intiter != SplitPoints.end(); ++intiter){
@@ -709,10 +697,12 @@ void ContactDataObject::ProcessXML(wxString PropertySeg1, wxString PropertySeg2,
                
                CaptureString(&PropertyValue, FALSE);
        
-               if (PropertyName == wxT("ALTID")){
-
-                       XMLListAltID.erase(*XMLCount);
-                       XMLListAltID.insert(std::make_pair(*XMLCount, PropertyValue));
+               ProcessStringValue(&PropertyName, "ALTID", &XMLListAltID, &PropertyValue, XMLCount, &PropertyMatched);
+               
+               if (PropertyMatched == TRUE){
+               
+                       PropertyMatched = FALSE;
+                       continue;
                
                }
                
@@ -741,6 +731,7 @@ void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySe
        wxString PropertyTokens;
        std::map<int,int>::iterator SLiter;
        bool FirstToken = TRUE;
+       bool PropertyMatched = FALSE;
        
        for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
        intiter != SplitPoints.end(); ++intiter){
@@ -757,26 +748,19 @@ void ContactDataObject::ProcessMember(wxString PropertySeg1, wxString PropertySe
                
                CaptureString(&PropertyValue, FALSE);
        
-               if (PropertyName == wxT("ALTID")){
-
-                       GroupsListAltID.erase(*GroupCount);
-                       GroupsListAltID.insert(std::make_pair(*GroupCount, PropertyValue));
+               ProcessStringValue(&PropertyName, "ALTID", &GroupsListAltID, &PropertyValue, GroupCount, &PropertyMatched);
+               ProcessStringValue(&PropertyName, "PID", &GroupsListPID, &PropertyValue, GroupCount, &PropertyMatched);
+               ProcessStringValue(&PropertyName, "MEDIATYPE", &GroupsListMediaType, &PropertyValue, GroupCount, &PropertyMatched);
+               ProcessIntegerValue(&PropertyName, "PREF", &GroupsListPref, &PropertyValue, GroupCount, &PropertyMatched);
                
-               } else if (PropertyName == wxT("PID")){
-
-                       GroupsListPID.erase(*GroupCount);
-                       GroupsListPID.insert(std::make_pair(*GroupCount, PropertyValue));
+               if (PropertyMatched == TRUE){
                
-               } else if (PropertyName == wxT("PREF")){
-
-                       ProcessIntegerValue(&GroupsListPref, &PropertyValue, GroupCount);
+                       PropertyMatched = FALSE;
+                       continue;
                
-               } else if (PropertyName == wxT("MEDIATYPE")){
-
-                       GroupsListMediaType.erase(*GroupCount);
-                       GroupsListMediaType.insert(std::make_pair(*GroupCount, PropertyValue));
+               }
                
-               } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
+               if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
                        
                        if (FirstToken == TRUE){
                                
@@ -823,6 +807,7 @@ void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2,
        wxString PropertyTokens;
        std::map<int,int>::iterator SLiter;
        bool FirstToken = TRUE;
+       bool PropertyMatched = FALSE;
        
        for (std::map<int, int>::iterator intiter = SplitPoints.begin(); 
        intiter != SplitPoints.end(); ++intiter){
@@ -848,27 +833,24 @@ void ContactDataObject::ProcessFN(wxString PropertySeg1, wxString PropertySeg2,
                                FullNamesListType.insert(std::make_pair(*FNCount, PropertyValue));
                
                        }
+                       
+                       PropertyMatched = TRUE;
                
-               } else if (PropertyName == wxT("LANGUAGE")){
-
-                       FullNamesListLanguage.erase(*FNCount);
-                       FullNamesListLanguage.insert(std::make_pair(*FNCount, PropertyValue));
+               }
                
-               } else if (PropertyName == wxT("ALTID")){
+               ProcessStringValue(&PropertyName, "ALTID", &FullNamesListAltID, &PropertyValue, FNCount, &PropertyMatched);
+               ProcessStringValue(&PropertyName, "PID", &FullNamesListPID, &PropertyValue, FNCount, &PropertyMatched);
+               ProcessStringValue(&PropertyName, "LANGUAGE", &FullNamesListLanguage, &PropertyValue, FNCount, &PropertyMatched);
+               ProcessIntegerValue(&PropertyName, "PREF", &FullNamesListPref, &PropertyValue, FNCount, &PropertyMatched);
                
-                       FullNamesListAltID.erase(*FNCount);
-                       FullNamesListAltID.insert(std::make_pair(*FNCount, PropertyValue));
+               if (PropertyMatched == TRUE){
                
-               } else if (PropertyName == wxT("PID")){
-
-                       FullNamesListPID.erase(*FNCount);
-                       FullNamesListPID.insert(std::make_pair(*FNCount, PropertyValue));
+                       PropertyMatched = FALSE;
+                       continue;
                
-               } else if (PropertyName == wxT("PREF")){
-
-                       ProcessIntegerValue(&FullNamesListPref, &PropertyValue, FNCount);
+               }
                
-               } else if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
+               if (!PropertyName.IsEmpty() && !PropertyValue.IsEmpty()){
                        
                        if (FirstToken == TRUE){
                                
@@ -5496,15 +5478,50 @@ void ProcessStringValue(wxString *PropertyName,
        wxString PropertyNameMatch,
        std::map<int,wxString> *MapPtr,
        wxString *PropertyValue,
-       int *ItemCount){
-
+       int *ItemCount,
+       bool *PropertyMatched){
+       
        if (*PropertyName == PropertyNameMatch){
                MapPtr->erase(*ItemCount);
                MapPtr->insert(std::make_pair(*ItemCount, *PropertyValue));
+               *PropertyMatched = TRUE;
        }
        
 }
 
+void ProcessIntegerValue(wxString *PropertyName,
+       wxString PropertyNameMatch,
+       std::map<int,int> *PrefPtr, 
+       wxString *PropertyValue, 
+       int *ItemCount,
+       bool *PropertyMatched){
+
+       if (*PropertyName == PropertyNameMatch){
+               *PropertyMatched = TRUE;
+       } else {
+               return;
+       }
+
+       int PriorityNumber = 0; 
+       bool ValidNumber = TRUE;
+                       
+       try{
+               PriorityNumber = std::stoi(PropertyValue->ToStdString());
+       }
+                       
+       catch(std::invalid_argument &e){
+               ValidNumber = FALSE;
+       }
+
+       if (ValidNumber == TRUE){
+
+               PrefPtr->erase(*ItemCount);
+               PrefPtr->insert(std::make_pair(*ItemCount, PriorityNumber));
+
+       }
+
+}
+
 void ProcessIntegerValue(std::map<int,int> *PrefPtr, 
        wxString *PropertyValue, 
        int *ItemCount){
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy