From b22d89925df6f435578ae08c37f91d73ee2bdda7 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Mon, 28 Dec 2015 03:46:36 +0000 Subject: [PATCH] Replaced string processing in SOURCE with ProcessStringValue. --- source/contacteditor/ContactDataObject.cpp | 86 ++++++++++++++-------- source/contacteditor/ContactDataObject.h | 10 ++- 2 files changed, 63 insertions(+), 33 deletions(-) diff --git a/source/contacteditor/ContactDataObject.cpp b/source/contacteditor/ContactDataObject.cpp index bc45c48..4c2cbc6 100644 --- a/source/contacteditor/ContactDataObject.cpp +++ b/source/contacteditor/ContactDataObject.cpp @@ -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); } @@ -5496,15 +5483,50 @@ void ProcessStringValue(wxString *PropertyName, wxString PropertyNameMatch, std::map *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 *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 *PrefPtr, wxString *PropertyValue, int *ItemCount){ diff --git a/source/contacteditor/ContactDataObject.h b/source/contacteditor/ContactDataObject.h index a6e9761..a5c1fbb 100644 --- a/source/contacteditor/ContactDataObject.h +++ b/source/contacteditor/ContactDataObject.h @@ -618,6 +618,13 @@ void CheckType(wxString *PropertySeg1, int *intPrevValue, PropertyType *intType); +void ProcessIntegerValue(wxString *PropertyName, + wxString PropertyNameMatch, + std::map *PrefPtr, + wxString *PropertyValue, + int *ItemCount, + bool *PropertyMatched); + void ProcessIntegerValue(std::map *PrefPtr, wxString *PropertyValue, int *ItemCount); @@ -626,6 +633,7 @@ void ProcessStringValue(wxString *PropertyName, wxString PropertyNameMatch, std::map *MapPtr, wxString *PropertyValue, - int *ItemCount); + int *ItemCount, + bool *PropertyMatched); #endif \ No newline at end of file -- 2.39.5