From ce0d1d07ea89abafb4debeb31e23f1b598fd9951 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sat, 23 Jan 2016 20:51:14 +0000 Subject: [PATCH] Added SplitValues and SplitNameValues in common/text.{cpp,h} --- source/common/text.cpp | 100 +++++++++++++++++++++++++++++++++++++++++ source/common/text.h | 14 +++++- 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/source/common/text.cpp b/source/common/text.cpp index ac9def1..8237440 100644 --- a/source/common/text.cpp +++ b/source/common/text.cpp @@ -74,4 +74,104 @@ multimap ProcessTextVectors(vector *TextProperties, return ProcessResult; +} + +map SplitValues(string InputData){ + + map FinalSplitValues; + map SplitPoints; + map 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 diff --git a/source/common/text.h b/source/common/text.h index d730aae..c4813e1 100644 --- a/source/common/text.h +++ b/source/common/text.h @@ -3,7 +3,19 @@ #include #include +#ifndef __COMMON_TEXT_H__ +#define __COMMON_TEXT_H__ + +struct PropertyNameValue{ + std::string Name; + std::string Value; +}; + std::multimap ProcessTextVectors(std::vector *TextProperties, std::vector *TextValues, bool SearchMultiple, - std::string Property); \ No newline at end of file + std::string Property); +std::map SplitValues(std::string InputData); +PropertyNameValue SplitNameValue(std::string InputData); + +#endif \ No newline at end of file -- 2.39.5