From: Li Peng Date: Tue, 3 May 2016 06:14:52 +0000 (+0800) Subject: cleanup: use boost::algorithm::starts_with to replace our own implementations X-Git-Tag: v11.0.0~533^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0482895ad7a227d3dea0a6580ee4065190a8acd0;p=ceph.git cleanup: use boost::algorithm::starts_with to replace our own implementations Don't reinvent the wheel. Signed-off-by: Li Peng --- diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index d597339a7e7..cd6d752279e 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -2,6 +2,7 @@ // vim: ts=8 sw=2 smarttab #include +#include #include "json_spirit/json_spirit.h" #include "common/ceph_json.h" @@ -97,18 +98,6 @@ is_err() const return !(http_ret >= 200 && http_ret <= 399); } -static bool starts_with(const string& s, const string& prefix) { - if (s.size() < prefix.size()) { - return false; - } - for (unsigned int i = 0; i < prefix.size(); ++i) { - if (prefix[i] != s[i]) { - return false; - } - } - return true; -} - // The requestURI transferred from the frontend can be abs_path or absoluteURI // If it is absoluteURI, we should adjust it to abs_path for the following // S3 authorization and some other processes depending on the requestURI @@ -117,7 +106,7 @@ static string get_abs_path(const string& request_uri) { const static string ABS_PREFIXS[] = {"http://", "https://", "ws://", "wss://"}; bool isAbs = false; for (int i = 0; i < 4; ++i) { - if (starts_with(request_uri, ABS_PREFIXS[i])) { + if (boost::algorithm::starts_with(request_uri, ABS_PREFIXS[i])) { isAbs = true; break; } diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 39e0d4acd3f..a0c44b24fa2 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1738,11 +1738,6 @@ inline ostream& operator<<(ostream& out, const rgw_obj &o) { return out << o.bucket.name << ":" << o.get_object(); } -static inline bool str_startswith(const string& str, const string& prefix) -{ - return (str.compare(0, prefix.size(), prefix) == 0); -} - static inline void buf_to_hex(const unsigned char *buf, int len, char *str) { int i; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 6b4ece733c9..b1408e6fd88 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include "common/ceph_json.h" #include "common/utf8.h" @@ -9838,7 +9839,7 @@ static void filter_attrset(map& unfiltered_attrset, const st map::iterator iter; for (iter = unfiltered_attrset.lower_bound(check_prefix); iter != unfiltered_attrset.end(); ++iter) { - if (!str_startswith(iter->first, check_prefix)) + if (!boost::algorithm::starts_with(iter->first, check_prefix)) break; (*attrset)[iter->first] = iter->second; }