From e293248e5faba88ed23bb5a2ed97d8f37ccc4edc Mon Sep 17 00:00:00 2001 From: "Jesse F. Williamson" Date: Wed, 26 Feb 2025 12:15:32 -0800 Subject: [PATCH] std::stol() to ceph::parse() Signed-off-by: Jesse F. Williamson --- src/common/ceph_json.h | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/common/ceph_json.h b/src/common/ceph_json.h index 00d015fa555e2..ba4f07e620b11 100644 --- a/src/common/ceph_json.h +++ b/src/common/ceph_json.h @@ -32,6 +32,7 @@ #include #include +#include "common/strtol.h" #include "common/ceph_time.h" #include @@ -63,7 +64,6 @@ concept json_integer = requires { requires std::is_integral_v; requires !std::is_same_v; - requires !is_any_of(); }; @@ -318,24 +318,15 @@ public: }; template -requires ceph_json::detail::json_signed_integer || - ceph_json::detail::json_unsigned_integer +requires ceph_json::detail::json_integer || void decode_json_obj(IntegerT& val, JSONObj *obj) -try { - if constexpr (ceph_json::detail::json_signed_integer) - val = stol(obj->get_data()); + auto r = ceph::parse(obj->get_data()); - if constexpr (ceph_json::detail::json_unsigned_integer) - 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 -- 2.39.5