X-Git-Url: http://Server1/repobrowser/?p=xestiacalendar%2F.git;a=blobdiff_plain;f=source%2Fobjects%2Fcalendarobject%2FCalendarObject.cpp;h=8e33eda12f397e2bfbf43a214f1e165375ee0475;hp=5a15e1d593c58c1530c75a28e521b2f9a1d1bbde;hb=d058825f5e9ae3713e7805071a55e2794f0c3b90;hpb=401fd2eee6047f72fdaf811bbcc3924409a4fb9d diff --git a/source/objects/calendarobject/CalendarObject.cpp b/source/objects/calendarobject/CalendarObject.cpp index 5a15e1d..8e33eda 100644 --- a/source/objects/calendarobject/CalendarObject.cpp +++ b/source/objects/calendarobject/CalendarObject.cpp @@ -21,132 +21,132 @@ using namespace std; -CalendarObjectLoadResult CalendarObject::LoadFile(std::string LoadFilename){ +CalendarObjectLoadResult CalendarObject::LoadFile(std::string loadFilename){ // Check if the file exists and return // CALENDAROBJECTLOAD_CANNOTOPEN if not. - if (!FileExists(LoadFilename)){ + if (!FileExists(loadFilename)){ return CALENDAROBJECTLOAD_MISSING; } - ifstream FileStream; - string ReceivedStringData = ""; + ifstream fileStream; + string receivedStringData = ""; - FileStream.open(LoadFilename, ifstream::in); + fileStream.open(loadFilename, ifstream::in); - if (FileStream.rdstate() & ifstream::failbit){ + if (fileStream.rdstate() & ifstream::failbit){ return CALENDAROBJECTLOAD_CANNOTOPEN; } - if (FileStream.rdstate() & ifstream::badbit){ + if (fileStream.rdstate() & ifstream::badbit){ return CALENDAROBJECTLOAD_CANNOTOPEN; } // Read the data into a string. - char *BufferRead = new char[256]; + char *bufferRead = new char[256]; - while (!FileStream.eof()){ + while (!fileStream.eof()){ - FileStream.getline(BufferRead, 256); - ReceivedStringData.append(BufferRead); - ReceivedStringData.append("\n"); + fileStream.getline(bufferRead, 256); + receivedStringData.append(bufferRead); + receivedStringData.append("\n"); } - delete[] BufferRead; + delete[] bufferRead; - CalendarObjectLoadResult StringProcResult = CALENDAROBJECTLOAD_UNITTESTFAIL; + CalendarObjectLoadResult stringProcResult = CALENDAROBJECTLOAD_UNITTESTFAIL; - StringProcResult = LoadString(&ReceivedStringData); + stringProcResult = LoadString(&receivedStringData); - return StringProcResult; + return stringProcResult; } -CalendarObjectLoadResult CalendarObject::LoadString(std::string *LoadStringData){ +CalendarObjectLoadResult CalendarObject::LoadString(std::string *loadStringData){ - bool NewLine = false; - bool SkipMode = false; - bool ColonFound = false; - bool QuoteMode = false; - char BufferChar = 0; - int StringDataSize = LoadStringData->size(); - int SeekCount = 0; - string PropertyName; - string PropertyValue; + bool newLine = false; + bool skipMode = false; + bool colonFound = false; + bool quoteMode = false; + char bufferChar = 0; + int stringDataSize = LoadStringData->size(); + int seekCount = 0; + string propertyName; + string propertyValue; - while (SeekCount < StringDataSize){ + while (seekCount < stringDataSize){ // Check if character is blank or a tab and is the first character // on a new line. - if (((*LoadStringData)[SeekCount] == ' ' || - (*LoadStringData)[SeekCount] == '\t') - && NewLine == true){ + if (((*loadStringData)[seekCount] == ' ' || + (*loadStringData)[seekCount] == '\t') + && newLine == true){ // Character is on a new line and it is a space or // tab. Ignore this character as it is not part // of the value. - NewLine = false; + newLine = false; - } else if ((*LoadStringData)[SeekCount] == '\"'){ + } else if ((*loadStringData)[seekCount] == '\"'){ - if (QuoteMode == false){ - QuoteMode = true; + if (quoteMode == false){ + quoteMode = true; } else { - QuoteMode = false; + quoteMode = false; } - BufferChar = (*LoadStringData)[SeekCount]; + bufferChar = (*loadStringData)[seekCount]; - if (ColonFound == false){ - PropertyName += BufferChar; + if (colonFound == false){ + propertyName += bufferChar; } else { - PropertyValue += BufferChar; + propertyValue += bufferChar; } - } else if (NewLine == true){ + } else if (newLine == true){ // Character is on a new line but not a space or // tab so check if the colon has been found // and add the property name and value to // the lists. - if (ColonFound == true){ - ObjectName.push_back(PropertyName); - ObjectData.push_back(PropertyValue); + if (colonFound == true){ + objectName.push_back(propertyName); + objectData.push_back(propertyValue); } - ColonFound = false; - NewLine = false; - PropertyName.clear(); - PropertyValue.clear(); + colonFound = false; + newLine = false; + propertyName.clear(); + propertyValue.clear(); - BufferChar = (*LoadStringData)[SeekCount]; - PropertyName += BufferChar; + bufferChar = (*loadStringData)[seekCount]; + propertyName += bufferChar; - } else if ((*LoadStringData)[SeekCount] == '\n'){ + } else if ((*loadStringData)[seekCount] == '\n'){ // Character is the new line character so mark // the NewLine boolean as true. - NewLine = true; + newLine = true; - } else if ((*LoadStringData)[SeekCount] == ':' && - QuoteMode == false){ + } else if ((*loadStringData)[seekCount] == ':' && + quoteMode == false){ // Character is the colon. Set the colon // found boolen to true. - BufferChar = (*LoadStringData)[SeekCount]; + bufferChar = (*loadStringData)[seekCount]; - if (ColonFound == true){ - PropertyValue += BufferChar; + if (colonFound == true){ + propertyValue += bufferChar; } else { - ColonFound = true; + colonFound = true; } } else { @@ -154,99 +154,99 @@ CalendarObjectLoadResult CalendarObject::LoadString(std::string *LoadStringData) // Character is not part of a new line and is not // the new line character itself. - BufferChar = (*LoadStringData)[SeekCount]; + bufferChar = (*loadStringData)[seekCount]; - if (ColonFound == false){ - PropertyName += BufferChar; + if (colonFound == false){ + propertyName += bufferChar; } else { - PropertyValue += BufferChar; + propertyValue += bufferChar; } } - SeekCount++; + seekCount++; } // Finish off processing any data that wasn't processed // when the end of the string was reached. - if (ColonFound == true && - PropertyName.size() > 0 && - PropertyValue.size() > 0){ + if (colonFound == true && + propertyName.size() > 0 && + propertyValue.size() > 0){ - ObjectName.push_back(PropertyName); - ObjectData.push_back(PropertyValue); + objectName.push_back(propertyName); + objectData.push_back(propertyValue); } // Check that the object contains valid data. - CalendarObjectLoadResult StringProcResult = CALENDAROBJECTLOAD_UNITTESTFAIL; - CalendarObjectValidResult BaseDataResult = ValidBaseObject(); - CalendarObjectValidResult EventDataResult = ValidObject(); + CalendarObjectLoadResult stringProcResult = CALENDAROBJECTLOAD_UNITTESTFAIL; + CalendarObjectValidResult baseDataResult = ValidBaseObject(); + CalendarObjectValidResult eventDataResult = ValidObject(); - if (BaseDataResult != CALENDAROBJECTVALID_OK || - EventDataResult != CALENDAROBJECTVALID_OK){ + if (baseDataResult != CALENDAROBJECTVALID_OK || + eventDataResult != CALENDAROBJECTVALID_OK){ - StringProcResult = CALENDAROBJECTLOAD_INVALIDFORMAT; + stringProcResult = CALENDAROBJECTLOAD_INVALIDFORMAT; } else { - StringProcResult = CALENDAROBJECTLOAD_OK; + stringProcResult = CALENDAROBJECTLOAD_OK; } - ProcessBaseData(); - ProcessData(); + processBaseData(); + processData(); - return StringProcResult; + return stringProcResult; } CalendarObjectValidResult CalendarObject::ValidBaseObject(){ - bool ValidBegin = false; - bool ValidAlarmBegin = false; - bool ValidVersion = false; - bool ValidEnd = false; - int SeekCount = 0; - vector DeleteLines; - vector AlarmObjectName; - vector AlarmObjectData; + bool validBegin = false; + bool validAlarmBegin = false; + bool validVersion = false; + bool validEnd = false; + int seekCount = 0; + vector deleteLines; + vector alarmObjectName; + vector alarmObjectData; // Check that the first line contains BEGIN:VCALENDAR // and it only appears once. - for (vector::iterator iter = ObjectName.begin(); - iter != ObjectName.end(); iter++){ + for (vector::iterator iter = objectName.begin(); + iter != objectName.end(); iter++){ - if (ObjectName[SeekCount] == "BEGIN" && - ObjectData[SeekCount] == "VCALENDAR"){ + if (objectName[seekCount] == "BEGIN" && + objectData[seekCount] == "VCALENDAR"){ - if (ValidBegin == false){ - ValidBegin = true; + if (validBegin == false){ + validBegin = true; } else { return CALENDAROBJECTVALID_INVALIDFORMAT; } } - if (ObjectName[SeekCount] == "END" && - ObjectData[SeekCount] == "VCALENDAR" && - ValidBegin == false){ + if (objectName[seekCount] == "END" && + objectData[seekCount] == "VCALENDAR" && + validBegin == false){ return CALENDAROBJECTVALID_INVALIDFORMAT; - } else if (ObjectName[SeekCount] == "END" && - ObjectData[SeekCount] == "VALARM" && - ValidAlarmBegin == false){ + } else if (objectName[seekCount] == "END" && + objectData[seekCount] == "VALARM" && + validAlarmBegin == false){ return CALENDAROBJECTVALID_INVALIDFORMAT; - } else if (ObjectName[SeekCount] == "END" && - ObjectData[SeekCount] == "VCALENDAR" && - ValidAlarmBegin == true){ + } else if (objectName[seekCount] == "END" && + objectData[seekCount] == "VCALENDAR" && + validAlarmBegin == true){ return CALENDAROBJECTVALID_INVALIDFORMAT; @@ -254,109 +254,109 @@ CalendarObjectValidResult CalendarObject::ValidBaseObject(){ // Look for any VALARM sections. - if (ValidAlarmBegin == true){ + if (validAlarmBegin == true){ - AlarmObjectName.push_back(ObjectName[SeekCount]); - AlarmObjectData.push_back(ObjectData[SeekCount]); - DeleteLines.push_back(SeekCount); + alarmObjectName.push_back(objectName[seekCount]); + alarmObjectData.push_back(objectData[seekCount]); + deleteLines.push_back(seekCount); } - if (ObjectName[SeekCount] == "END" && - ObjectData[SeekCount] == "VALARM" && - ValidAlarmBegin == true){ + if (objectName[seekCount] == "END" && + objectData[seekCount] == "VALARM" && + validAlarmBegin == true){ - EventAlarmName.push_back(AlarmObjectName); - EventAlarmData.push_back(AlarmObjectData); + eventAlarmName.push_back(AlarmObjectName); + eventAlarmData.push_back(AlarmObjectData); - AlarmObjectName.clear(); - AlarmObjectData.clear(); + alarmObjectName.clear(); + alarmObjectData.clear(); - ValidAlarmBegin = false; + validAlarmBegin = false; } - if (ObjectName[SeekCount] == "BEGIN" && - ObjectData[SeekCount] == "VALARM" && - ValidBegin == true){ + if (objectName[seekCount] == "BEGIN" && + objectData[seekCount] == "VALARM" && + validBegin == true){ - if (ValidAlarmBegin == false){ - ValidAlarmBegin = true; + if (validAlarmBegin == false){ + validAlarmBegin = true; } else { return CALENDAROBJECTVALID_INVALIDFORMAT; } - AlarmObjectName.push_back(ObjectName[SeekCount]); - AlarmObjectData.push_back(ObjectData[SeekCount]); - DeleteLines.push_back(SeekCount); + alarmObjectName.push_back(objectName[seekCount]); + alarmObjectData.push_back(objectData[seekCount]); + deleteLines.push_back(seekCount); } - SeekCount++; + seekCount++; } - SeekCount = 0; + seekCount = 0; // Check that the last line contains END:VCALENDAR // and it only appears once. - for (vector::iterator iter = ObjectName.begin(); - iter != ObjectName.end(); iter++){ + for (vector::iterator iter = objectName.begin(); + iter != objectName.end(); iter++){ - if (ObjectName[SeekCount] == "END" && - ObjectData[SeekCount] == "VCALENDAR"){ + if (objectName[seekCount] == "END" && + objectData[seekCount] == "VCALENDAR"){ - if (ValidEnd == false){ - ValidEnd = true; + if (validEnd == false){ + validEnd = true; } else { return CALENDAROBJECTVALID_INVALIDFORMAT; } } - SeekCount++; + seekCount++; } - SeekCount = 0; + seekCount = 0; // Check that the VERSION value contains 2.0 and that // it only appears once. - for (vector::iterator iter = ObjectName.begin(); - iter != ObjectName.end(); iter++){ + for (vector::iterator iter = objectName.begin(); + iter != objectName.end(); iter++){ - if (ObjectName[SeekCount] == "VERSION" && - ObjectData[SeekCount] == "2.0"){ + if (objectName[seekCount] == "VERSION" && + objectData[seekCount] == "2.0"){ - if (ValidVersion == false){ - ValidVersion = true; + if (validVersion == false){ + validVersion = true; } else { return CALENDAROBJECTVALID_INVALIDFORMAT; } } - SeekCount++; + seekCount++; } // Remove lines that aren't needed as they have // been moved to the EventAlarm section. - for (vector::reverse_iterator deliter = DeleteLines.rbegin(); - deliter != DeleteLines.rend(); deliter++){ + for (vector::reverse_iterator deliter = deleteLines.rbegin(); + deliter != deleteLines.rend(); deliter++){ - ObjectName.erase(ObjectName.begin()+(*deliter)); - ObjectData.erase(ObjectData.begin()+(*deliter)); + objectName.erase(objectName.begin()+(*deliter)); + objectData.erase(objectData.begin()+(*deliter)); } - if (ValidBegin == true && - ValidEnd == true && - ValidVersion == true && - ValidAlarmBegin == false){ + if (validBegin == true && + validEnd == true && + validVersion == true && + validAlarmBegin == false){ return CALENDAROBJECTVALID_OK; @@ -372,41 +372,41 @@ void CalendarObject::ProcessBaseData(){ // Process the base object data. - multimap DataReceived; + multimap dataReceived; // Get the method (METHOD). - DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "METHOD"); + dataReceived = ProcessTextVectors(&objectName, &objectData, false, "METHOD"); - if (DataReceived.begin() != DataReceived.end()){ + if (dataReceived.begin() != dataReceived.end()){ try { - MethodTokens = DataReceived.begin()->first.substr(7); + methodTokens = dataReceived.begin()->first.substr(7); } catch(const out_of_range &oor){ // Do nothing as there is no data. } - MethodData = DataReceived.begin()->second; + methodData = dataReceived.begin()->second; } // Get the calendar scale (CALSCALE). - DataReceived = ProcessTextVectors(&ObjectName, &ObjectData, false, "CALSCALE"); + dataReceived = ProcessTextVectors(&objectName, &objectData, false, "CALSCALE"); - if (DataReceived.begin() != DataReceived.end()){ + if (dataReceived.begin() != dataReceived.end()){ try { - CalendarScaleTokens = DataReceived.begin()->first.substr(9); + calendarScaleTokens = dataReceived.begin()->first.substr(9); } catch(const out_of_range &oor){ // Do nothing as there is no data. } - CalendarScaleData = DataReceived.begin()->second; + calendarScaleData = dataReceived.begin()->second; }