]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
common/strtol: expose strict_si_cast(std::string_view, ..)
authorKefu Chai <kchai@redhat.com>
Mon, 26 Jul 2021 06:50:47 +0000 (14:50 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 26 Jul 2021 12:12:17 +0000 (20:12 +0800)
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 <kchai@redhat.com>
src/common/options/rbd.yaml.in
src/common/strtol.cc
src/common/strtol.h

index e99cab3d2cf274d4d1f52ca15106ec2132bfeeb2..e8f5d0d2555a6289815a788dd9e513e651b7c2ea 100644 (file)
@@ -310,7 +310,7 @@ options:
   max: 32_M
   validator: |
     [](std::string *value, std::string *error_message) {
-      uint64_t f = strict_si_cast<uint64_t>(value->c_str(), error_message);
+      uint64_t f = strict_si_cast<uint64_t>(*value, error_message);
       if (!error_message->empty()) {
         return -EINVAL;
       } else if (!isp2(f)) {
index ad011b2097dcc2f50b8c6897388bd47767ac67b7..bba31f2a5876750e81546a880e2eaa3cd8766c45 100644 (file)
@@ -307,15 +307,3 @@ uint64_t strict_sistrtoll(const char *str, std::string *err)
 {
   return strict_si_cast<uint64_t>(str, err);
 }
-
-template<typename T>
-T strict_si_cast(const char *str, std::string *err)
-{
-  return strict_si_cast<T>(std::string_view(str), err);
-}
-
-template int strict_si_cast<int>(const char *str, std::string *err);
-template long strict_si_cast<long>(const char *str, std::string *err);
-template long long strict_si_cast<long long>(const char *str, std::string *err);
-template uint64_t strict_si_cast<uint64_t>(const char *str, std::string *err);
-template uint32_t strict_si_cast<uint32_t>(const char *str, std::string *err);
index 6af506a6ddcd14cb46f0e0247aa1dc6f027f36d8..91d2fac9f075faedadcbe18e09f5aee9e8e71cb5 100644 (file)
@@ -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<typename T>
-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