From 0be3bf5e2032af68130b2ea3ad4437f9dc570b3d Mon Sep 17 00:00:00 2001 From: Sho Amano Date: Tue, 26 Jun 2018 17:52:02 +0900 Subject: Update Profile based on review comments - Use std::accumulate() to generate comma-separated list - Rewrite ReadValue() using ReadValueEmpty() --- src/components/config_profile/src/profile.cc | 48 +++++++++++----------------- 1 file changed, 18 insertions(+), 30 deletions(-) (limited to 'src/components/config_profile/src') 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 +#include #include #include #include @@ -2003,16 +2004,14 @@ void Profile::UpdateValues() { transport_required_for_resumption_map_[entry->map_key_name] = transport_list; - std::stringstream ss; - for (std::vector::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::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, -- cgit v1.2.1