diff options
author | Sho Amano <samano@xevo.com> | 2018-06-26 17:52:02 +0900 |
---|---|---|
committer | Sho Amano <samano@xevo.com> | 2018-06-26 18:45:41 +0900 |
commit | 0be3bf5e2032af68130b2ea3ad4437f9dc570b3d (patch) | |
tree | 9cb5bb48d9515b99e58b6101e0340a9970930b72 /src/components/config_profile/src | |
parent | d34665c35bc4d959296511dd27e77ba2d5f709d5 (diff) | |
download | sdl_core-0be3bf5e2032af68130b2ea3ad4437f9dc570b3d.tar.gz |
Update Profile based on review comments
- Use std::accumulate() to generate comma-separated list
- Rewrite ReadValue() using ReadValueEmpty()
Diffstat (limited to 'src/components/config_profile/src')
-rw-r--r-- | src/components/config_profile/src/profile.cc | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/src/components/config_profile/src/profile.cc b/src/components/config_profile/src/profile.cc index 19f75203e5..3f3ec7eb63 100644 --- a/src/components/config_profile/src/profile.cc +++ b/src/components/config_profile/src/profile.cc @@ -33,6 +33,7 @@ #include "config_profile/profile.h" #include <errno.h> +#include <numeric> #include <string.h> #include <stdlib.h> #include <sstream> @@ -2003,16 +2004,14 @@ void Profile::UpdateValues() { transport_required_for_resumption_map_[entry->map_key_name] = transport_list; - std::stringstream ss; - for (std::vector<std::string>::iterator it = transport_list.begin(); - it != transport_list.end(); - ++it) { - if (it != transport_list.begin()) { - ss << ", "; - } - ss << *it; - } - LOG_UPDATED_VALUE(ss.str(), + const std::string list_with_comma = std::accumulate( + transport_list.begin(), + transport_list.end(), + std::string(""), + [](std::string& first, std::string& second) { + return first.empty() ? second : first + ", " + second; + }); + LOG_UPDATED_VALUE(list_with_comma, entry->ini_key_name, kTransportRequiredForResumptionSection); } @@ -2164,17 +2163,15 @@ void Profile::UpdateValues() { if (exist) { *entry->ini_vector = profile_entry; - std::stringstream ss; - for (std::vector<std::string>::iterator it = profile_entry.begin(); - it != profile_entry.end(); - ++it) { - if (it != profile_entry.begin()) { - ss << ", "; - } - ss << *it; - } + const std::string list_with_comma = std::accumulate( + profile_entry.begin(), + profile_entry.end(), + std::string(""), + [](std::string& first, std::string& second) { + return first.empty() ? second : first + ", " + second; + }); LOG_UPDATED_VALUE( - ss.str(), entry->ini_key_name, entry->ini_section_name); + list_with_comma, entry->ini_key_name, entry->ini_section_name); } entry++; } @@ -2206,16 +2203,7 @@ bool Profile::ReadValue(std::string* value, const char* const pSection, const char* const pKey) const { DCHECK(value); - bool ret = false; - - char buf[INI_LINE_LEN + 1]; - *buf = '\0'; - if ((0 != ini_read_value(config_file_name_.c_str(), pSection, pKey, buf)) && - ('\0' != *buf)) { - *value = buf; - ret = true; - } - return ret; + return ReadValueEmpty(value, pSection, pKey) && "\0" != *value; } bool Profile::ReadValueEmpty(std::string* value, |