Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added SplitValues and SplitNameValues in common/text.{cpp,h}
[xestiacalendar/.git] / source / common / text.cpp
index ac9def1..8237440 100644 (file)
@@ -74,4 +74,104 @@ multimap<string, string> ProcessTextVectors(vector<string> *TextProperties,
                
        return ProcessResult;
                
+}
+
+map<string, string> SplitValues(string InputData){
+       
+       map<string,string> FinalSplitValues;
+       map<int,int> SplitPoints;
+       map<int,int> SplitLength;
+       size_t intPropertyLen = InputData.size();
+       int intSplitsFound = 0;
+       int intSplitSize = 0;
+       int intSplitSeek = 0;
+       int intPrevSplitFound = 0;
+       
+       // Get the split points.
+       
+       for (int i = 0; i <= intPropertyLen; i++){
+
+               intSplitSize++;
+       
+               InputData.substr(intPrevSplitFound, intSplitSize);
+               
+               if (InputData.substr(i, 1) == ";" &&
+                   InputData.substr((i - 1), 1) != "\\"){
+
+                       if (intSplitsFound > 0){
+                               
+                               // Split the value into two.
+                               
+                               PropertyNameValue NVData = SplitNameValue(InputData.substr(intPrevSplitFound, (intSplitSize - 1)));
+                               
+                               if (FinalSplitValues.find(NVData.Name) != FinalSplitValues.end()){
+                                       FinalSplitValues.insert(make_pair(NVData.Name, NVData.Value));
+                               } else {
+                                       FinalSplitValues[NVData.Name] = NVData.Value;
+                               }
+                               
+                       }
+                       
+                       intPrevSplitFound = i + 1;
+                       intSplitSize = 0;
+                       intSplitsFound++;
+           
+               }
+
+       }
+
+       if (intSplitsFound > 0){
+               
+               PropertyNameValue NVData = SplitNameValue(InputData.substr(intPrevSplitFound, (intSplitSize - 1)));
+                               
+               if (FinalSplitValues.find(NVData.Name) != FinalSplitValues.end()){
+                       FinalSplitValues.insert(make_pair(NVData.Name, NVData.Value));
+               } else {
+                       FinalSplitValues[NVData.Name] = NVData.Value;
+               }
+               
+       }
+       
+       return FinalSplitValues;
+
+}
+
+PropertyNameValue SplitNameValue(string InputData){
+       
+       PropertyNameValue FinalNameValue;
+       int InputDataLength = InputData.size();
+       int SeekCount = 0;
+       bool QuoteMode = false;
+       bool DataFound = false;
+       
+       while (SeekCount < InputDataLength){
+               
+               if (InputData[SeekCount] == '='){
+
+                       FinalNameValue.Name = InputData.substr(0, SeekCount);
+                       
+                       try{
+                               FinalNameValue.Value = InputData.substr((SeekCount + 1));
+                       }
+                       
+                       catch (const out_of_range &oor){
+                               // Do nothing. Have an empty final value.
+                       }
+                       
+                       DataFound = true;
+                       break;
+               }
+               
+               SeekCount++;
+               
+       }
+       
+       if (DataFound == false){
+               
+               FinalNameValue.Name = InputData;
+               
+       }
+       
+       return FinalNameValue;
+       
 }
\ No newline at end of file
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