summaryrefslogtreecommitdiffstats
path: root/utility/Utility.cpp
diff options
context:
space:
mode:
authorFrederic Boisnard <fredericx.boisnard@intel.com>2013-05-23 15:28:31 +0200
committerDavid Wagner <david.wagner@intel.com>2014-02-12 17:04:04 +0100
commit390b36d8129d3ece769c8542d9d3d3895ab13fbb (patch)
tree693f1bbc58ef05d0cbd6182b23be3cf6b413dbc2 /utility/Utility.cpp
parent55f41bcc3edf282f236539bb26bd6dc8638f235e (diff)
downloadexternal_parameter-framework-390b36d8129d3ece769c8542d9d3d3895ab13fbb.zip
external_parameter-framework-390b36d8129d3ece769c8542d9d3d3895ab13fbb.tar.gz
external_parameter-framework-390b36d8129d3ece769c8542d9d3d3895ab13fbb.tar.bz2
[PFW] Add getFormattedMapping for InstanceConfigurableElements
BZ: 99822 The mapping data need to be printed, however helper methods are missing to achieve this easily. This patch aims to add a new method "getFormattedMapping()" for CMappingData, allowing to format the mapping data as a string. Change-Id: Ia030c6b88905fcb7591ad45339712051eb88d1c1 Signed-off-by: Frederic Boisnard <fredericx.boisnard@intel.com> Reviewed-on: http://android.intel.com:8080/109301 Reviewed-by: Benavoli, Patrick <patrick.benavoli@intel.com> Reviewed-by: De Chivre, Renaud <renaud.de.chivre@intel.com> Reviewed-by: Rocard, KevinX <kevinx.rocard@intel.com> Reviewed-by: Denneulin, Guillaume <guillaume.denneulin@intel.com> Tested-by: Barthes, FabienX <fabienx.barthes@intel.com> Reviewed-by: buildbot <buildbot@intel.com> Tested-by: buildbot <buildbot@intel.com>
Diffstat (limited to 'utility/Utility.cpp')
-rw-r--r--utility/Utility.cpp48
1 files changed, 34 insertions, 14 deletions
diff --git a/utility/Utility.cpp b/utility/Utility.cpp
index afedc07..ccf3bc6 100644
--- a/utility/Utility.cpp
+++ b/utility/Utility.cpp
@@ -24,23 +24,43 @@
#include "Utility.h"
-// Concatenate string list
-void CUtility::concatenate(const std::list<std::string>& lstr, std::string& strOutput, const std::string& strSeparator)
+#include <sstream>
+#include <iterator>
+
+// Format string list
+void CUtility::asString(const std::list<std::string>& lstr,
+ std::string& strOutput,
+ const std::string& strSeparator)
{
- bool bStart = true;
+ std::ostringstream ostrFormatedList;
+
+ std::copy(lstr.begin(), lstr.end(),
+ std::ostream_iterator<std::string>(ostrFormatedList, strSeparator.c_str()));
- std::list<std::string>::const_iterator iterator(lstr.begin());
- std::list<std::string>::const_iterator end(lstr.end());
+ strOutput = ostrFormatedList.str();
- while (iterator != end) {
+ // Remove last separator
+ if (strOutput.size() > strSeparator.size()) {
- if (bStart) {
- // Do not add a separator before first element
- bStart = false;
- } else {
- // Add the separator bettween each element
- strOutput += strSeparator;
- }
- strOutput += *iterator++;
+ strOutput.erase(strOutput.size() - strSeparator.size());
}
}
+
+// Format string map
+void CUtility::asString(const std::map<std::string, std::string>& mapStr,
+ std::string& strOutput,
+ const std::string& strItemSeparator,
+ const std::string& strKeyValueSeparator)
+{
+ std::list<std::string> listKeysValues;
+
+ std::map<std::string, std::string>::const_iterator iter;
+
+ for(iter = mapStr.begin(); iter != mapStr.end(); ++iter) {
+
+ listKeysValues.push_back(iter->first + strKeyValueSeparator + iter->second);
+ }
+
+ CUtility::asString(listKeysValues, strOutput, strItemSeparator);
+}
+