Use starts_with method instead of compare method 16/317716/1
authorpjh9216 <jh9216.park@samsung.com>
Tue, 7 Jan 2025 04:26:59 +0000 (13:26 +0900)
committerpjh9216 <jh9216.park@samsung.com>
Tue, 7 Jan 2025 04:26:59 +0000 (13:26 +0900)
- Now that tizen supports c++20, we can use the new method 'starts_with' in std::string.
- It is fast(constexpr method) and simple.

Change-Id: I9b7b8ad91655d0cc268dff333d7f1b7e3af35440
Signed-off-by: pjh9216 <jh9216.park@samsung.com>
src/aul/app_control/resolve_info.cc
src/aul/aul_rpc_port.cc
src/aul/res_info/res_pkg_info.cc

index c384f05926e8d20004e8a59d5d2aec971a97a47a..d6885193e292711a407af06cf5d98ab3b58c5a67 100644 (file)
@@ -104,17 +104,17 @@ void ResolveInfo::Manager::GetMime(std::string& uri, std::string& mime) {
 
   bool need_check = false;
   int index;
-  if (uri.compare(0, 1, "/") == 0) {
+  if (uri.starts_with("/")) {
     if (mime.empty()) {
       need_check = true;
       index = 0;
     }
-  } else if (uri.compare(0, 8, "file:///") == 0) {
+  } else if (uri.starts_with("file:///")) {
     if (mime.empty()) {
       need_check = true;
       index = 7;
     }
-  } else if (uri.compare(0, 6, "file:/") == 0) {
+  } else if (uri.starts_with("file:/")) {
     if (mime.empty()) {
       need_check = true;
       index = 5;
index 7d381a042178d6c4c36f72dff95ac9915a089780..8705275c3d9d0ec5a12a5882c6b9c4aca68eff1a 100644 (file)
@@ -121,10 +121,10 @@ class WatchInfo {
 
 std::string GetInterfaceName(const std::string& app_id,
     const std::string& port_name, uid_t uid) {
-  if (app_id.compare(0, strlen(kDPrefix), kDPrefix) == 0)
+  if (app_id.starts_with(kDPrefix))
     return app_id + "::" + port_name;
 
-  if (app_id.compare(0, strlen(kUdPrefix), kUdPrefix) == 0)
+  if (app_id.starts_with(kUdPrefix))
     return std::to_string(uid) + "::" + app_id + "::" + port_name;
 
   std::string name = kInterfacePrefix + app_id + "_" + port_name;
index 5ed7f9056c25a634e155c53cfd0d610ad4f0cbf2..18ba77242ac9330db4a07f0329a62c032b2abf0d 100644 (file)
@@ -154,7 +154,7 @@ bool ResPkgInfo::IsLib() const { return is_lib_; }
 
 bool ResPkgInfo::IsGadget() const {
   return (res_type_.length() > strlen(kGadgetPrefix) &&
-          !res_type_.compare(0, strlen(kGadgetPrefix), kGadgetPrefix));
+          res_type_.starts_with(kGadgetPrefix));
 }
 
 bool ResPkgInfo::CheckAllowedPackage(