Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added SplitValues and SplitNameValues in common/text.{cpp,h}
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sat, 23 Jan 2016 20:51:14 +0000 (20:51 +0000)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sat, 23 Jan 2016 20:51:14 +0000 (20:51 +0000)
source/common/text.cpp
source/common/text.h

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
index d730aae..c4813e1 100644 (file)
@@ -3,7 +3,19 @@
 #include <map>
 #include <iostream>
 
+#ifndef __COMMON_TEXT_H__
+#define __COMMON_TEXT_H__
+
+struct PropertyNameValue{
+       std::string Name;
+       std::string Value;
+};
+
 std::multimap<std::string, std::string> ProcessTextVectors(std::vector<std::string> *TextProperties,
        std::vector<std::string> *TextValues,
        bool SearchMultiple,
-       std::string Property);
\ No newline at end of file
+       std::string Property);
+std::map<std::string, std::string> SplitValues(std::string InputData);
+PropertyNameValue SplitNameValue(std::string InputData);
+
+#endif
\ 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