From: Kefu Chai Date: Mon, 26 Jul 2021 06:50:47 +0000 (+0800) Subject: common/strtol: expose strict_si_cast(std::string_view, ..) X-Git-Tag: v17.1.0~1287^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b6f29f4c1b9fac9e46e6be049642d83f6f4c5f9a;p=ceph.git common/strtol: expose strict_si_cast(std::string_view, ..) this variant is better than strict_si_cast(const char*), because: * we can just pass std::string to it, as std::string_view can be constructed from a std::string implicitly * strict_si_cast(std::string_view, ..) is the underlying implementation of strict_si_cast(const char*,..), so less indirection helps with the readability. Signed-off-by: Kefu Chai --- diff --git a/src/common/options/rbd.yaml.in b/src/common/options/rbd.yaml.in index e99cab3d2cf2..e8f5d0d2555a 100644 --- a/src/common/options/rbd.yaml.in +++ b/src/common/options/rbd.yaml.in @@ -310,7 +310,7 @@ options: max: 32_M validator: | [](std::string *value, std::string *error_message) { - uint64_t f = strict_si_cast(value->c_str(), error_message); + uint64_t f = strict_si_cast(*value, error_message); if (!error_message->empty()) { return -EINVAL; } else if (!isp2(f)) { diff --git a/src/common/strtol.cc b/src/common/strtol.cc index ad011b2097dc..bba31f2a5876 100644 --- a/src/common/strtol.cc +++ b/src/common/strtol.cc @@ -307,15 +307,3 @@ uint64_t strict_sistrtoll(const char *str, std::string *err) { return strict_si_cast(str, err); } - -template -T strict_si_cast(const char *str, std::string *err) -{ - return strict_si_cast(std::string_view(str), err); -} - -template int strict_si_cast(const char *str, std::string *err); -template long strict_si_cast(const char *str, std::string *err); -template long long strict_si_cast(const char *str, std::string *err); -template uint64_t strict_si_cast(const char *str, std::string *err); -template uint32_t strict_si_cast(const char *str, std::string *err); diff --git a/src/common/strtol.h b/src/common/strtol.h index 6af506a6ddcd..91d2fac9f075 100644 --- a/src/common/strtol.h +++ b/src/common/strtol.h @@ -89,7 +89,7 @@ T strict_iec_cast(std::string_view str, std::string *err); uint64_t strict_sistrtoll(const char *str, std::string *err); template -T strict_si_cast(const char *str, std::string *err); +T strict_si_cast(std::string_view str, std::string *err); /* On enter buf points to the end of the buffer, e.g. where the least * significant digit of the input number will be printed. Returns pointer to