[SystemInfo] Minor fix to avoid using assign() of std::string
authorfyraimar <fyraimar@gmail.com>
Thu, 15 Aug 2013 01:26:18 +0000 (09:26 +0800)
committerHalton Huo <halton.huo@intel.com>
Fri, 16 Aug 2013 03:27:15 +0000 (11:27 +0800)
system_info/system_info_build_desktop.cc
system_info/system_info_build_mobile.cc
system_info/system_info_locale_desktop.cc
system_info/system_info_locale_mobile.cc

index 7d334ec..d9a5c18 100644 (file)
@@ -57,7 +57,7 @@ bool SysInfoBuild::UpdateHardware() {
 
   do {
     getline(&cinfo, &length, fp);
-    info.assign(cinfo);
+    info = cinfo;
     dmipos = info.find("] DMI: ", 0);
   } while (dmipos == std::string::npos);
   info.erase(0, dmipos + 7);
@@ -74,7 +74,7 @@ bool SysInfoBuild::UpdateHardware() {
   if (str.empty()) {
     return false;
   } else {
-    manufacturer_.assign(str);
+    manufacturer_ = str;
   }
 
   // model
@@ -84,7 +84,7 @@ bool SysInfoBuild::UpdateHardware() {
   if (str.empty()) {
     return false;
   } else {
-    model_.assign(str);
+    model_ = str;
   }
 
   return true;
index 800afc6..0c5a704 100644 (file)
@@ -4,7 +4,7 @@
 
 #include "system_info/system_info_build.h"
 
-#include <string>
+#include <stdlib.h>
 #if defined(TIZEN_MOBILE)
 #include <system_info.h>
 #endif
@@ -46,46 +46,36 @@ void SysInfoBuild::Get(picojson::value& error,
 }
 
 bool SysInfoBuild::UpdateHardware() {
-  char* cptr = NULL;
-  std::string hardware_info;
+  char* hardware_info = NULL;
 
-  system_info_key_e key = SYSTEM_INFO_KEY_MODEL;
-  system_info_get_value_string(key, &cptr);
-
-  hardware_info.assign(cptr);
-  if (hardware_info.empty()) {
+  if (system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &hardware_info)
+      != SYSTEM_INFO_ERROR_NONE)
     return false;
-  } else {
-    model_.assign(hardware_info);
-  }
 
-  cptr = NULL;
-  key = SYSTEM_INFO_KEY_MANUFACTURER;
-  system_info_get_value_string(key, &cptr);
+  model_ = hardware_info;
+  free(hardware_info);
 
-  hardware_info.assign(cptr);
-  if (hardware_info.empty()) {
+  if (system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &hardware_info)
+      != SYSTEM_INFO_ERROR_NONE)
     return false;
-  } else {
-    manufacturer_.assign(hardware_info);
-  }
+
+  manufacturer_ = hardware_info;
+  free(hardware_info);
+
   return true;
 }
 
 bool SysInfoBuild::UpdateOSBuild() {
-  char* cptr = NULL;
-  std::string build_info;
+  char* build_info = NULL;
 
-  system_info_key_e key = SYSTEM_INFO_KEY_BUILD_STRING;
-  system_info_get_value_string(key, &cptr);
-
-  build_info.assign(cptr);
-  if (build_info.empty()) {
+  if (system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &build_info)
+      != SYSTEM_INFO_ERROR_NONE)
     return false;
-  } else {
-    buildversion_.assign(build_info);
-    return true;
-  }
+
+  buildversion_ = build_info;
+  free(build_info);
+
+  return true;
 }
 
 gboolean SysInfoBuild::OnUpdateTimeout(gpointer user_data) {
index 07094e5..476ffc0 100644 (file)
@@ -58,7 +58,7 @@ bool SysInfoLocale::UpdateLanguage() {
   if (str.empty()) {
     return false;
   } else {
-    language_.assign(str);
+    language_ = str;
     return true;
   }
 }
@@ -72,7 +72,7 @@ bool SysInfoLocale::UpdateCountry() {
   size_t length = 100;
 
   getline(&cinfo, &length, fp);
-  info.assign(cinfo);
+  info = cinfo;
   free(cinfo);
   fclose(fp);
 
@@ -83,7 +83,7 @@ bool SysInfoLocale::UpdateCountry() {
   if (str.empty()) {
     return false;
   } else {
-    country_.assign(str);
+    country_ = str;
     return true;
   }
 }
index e223709..d15320f 100644 (file)
@@ -4,10 +4,10 @@
 
 #include "system_info/system_info_locale.h"
 
+#include <stdlib.h>
 #if defined(TIZEN_MOBILE)
 #include <runtime_info.h>
 #endif
-#include <string>
 
 #include "common/picojson.h"
 #include "system_info/system_info_utils.h"
@@ -45,35 +45,29 @@ void SysInfoLocale::Get(picojson::value& error,
 }
 
 bool SysInfoLocale::UpdateLanguage() {
-  char* cptr = NULL;
-  std::string language_info;
+  char* language_info = NULL;
 
-  runtime_info_key_e key = RUNTIME_INFO_KEY_LANGUAGE;
-  runtime_info_get_value_string(key, &cptr);
-
-  language_info = cptr;
-  if (language_info.empty()) {
+  if (runtime_info_get_value_string(RUNTIME_INFO_KEY_LANGUAGE, &language_info)
+      != RUNTIME_INFO_ERROR_NONE)
     return false;
-  } else {
-    language_.assign(language_info);
-    return true;
-  }
+
+  language_ = language_info;
+  free(language_info);
+
+  return true;
 }
 
 bool SysInfoLocale::UpdateCountry() {
-  char* cptr = NULL;
-  std::string country_info;
+  char* country_info = NULL;
 
-  runtime_info_key_e key = RUNTIME_INFO_KEY_REGION;
-  runtime_info_get_value_string(key, &cptr);
-
-  country_info = cptr;
-  if (country_info.empty()) {
+  if (runtime_info_get_value_string(RUNTIME_INFO_KEY_REGION, &country_info)
+      != RUNTIME_INFO_ERROR_NONE)
     return false;
-  } else {
-    country_.assign(country_info);
-    return true;
-  }
+
+  country_  = country_info;
+  free(country_info);
+
+  return true;
 }
 
 gboolean SysInfoLocale::OnUpdateTimeout(gpointer user_data) {