]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
std::stol() to ceph::parse()
authorJesse F. Williamson <jfw@ibm.com>
Wed, 26 Feb 2025 20:15:32 +0000 (12:15 -0800)
committerJesse F. Williamson <jfw@ibm.com>
Mon, 17 Mar 2025 17:41:28 +0000 (10:41 -0700)
Signed-off-by: Jesse F. Williamson <jfw@ibm.com>
src/common/ceph_json.h

index 00d015fa555e2ce3371efbc56b7b70bbfc6827b2..ba4f07e620b118a452854fe2bef6e116885be790 100644 (file)
@@ -32,6 +32,7 @@
 #include <include/types.h>
 #include <include/ceph_fs.h>
 
+#include "common/strtol.h"
 #include "common/ceph_time.h"
 
 #include <fmt/format.h>
@@ -63,7 +64,6 @@ concept json_integer = requires
 {
  requires std::is_integral_v<T>;
  requires !std::is_same_v<T, bool>;
-
  requires !is_any_of<T, char, char8_t, char16_t, char32_t, wchar_t>();
 };
 
@@ -318,24 +318,15 @@ public:
 };
 
 template <typename IntegerT>
-requires ceph_json::detail::json_signed_integer<IntegerT> ||
-         ceph_json::detail::json_unsigned_integer<IntegerT>
+requires ceph_json::detail::json_integer<IntegerT> ||
 void decode_json_obj(IntegerT& val, JSONObj *obj)
-try
 {
- if constexpr (ceph_json::detail::json_signed_integer<IntegerT>)
-  val = stol(obj->get_data());
+ auto r = ceph::parse<IntegerT>(obj->get_data());
 
- if constexpr (ceph_json::detail::json_unsigned_integer<IntegerT>)
-  val = stoul(obj->get_data());
-}
-catch(const std::out_of_range& e)
-{
- throw JSONDecoder::err(fmt::format("failed to parse number: {}", e.what()));
-}
-catch(const std::invalid_argument& e)
-{
- throw JSONDecoder::err(fmt::format("failed to parse number: {}", e.what()));
+ if(std::errc() != r)
+  throw JSONDecoder::err(fmt::format("failed to parse number from JSON"));
+
+ val = *r;
 }
 
 template<class T>