mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
fix: fix ld for num converting (#2902)
This commit is contained in:
parent
2b6a5e5039
commit
55447e28ff
2 changed files with 26 additions and 37 deletions
|
@ -6,7 +6,6 @@
|
|||
|
||||
#include <absl/strings/ascii.h>
|
||||
#include <absl/strings/match.h>
|
||||
#include <absl/strings/numbers.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "facade/error.h"
|
||||
|
@ -47,41 +46,6 @@ void CmdArgParser::ExpectTag(std::string_view tag) {
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T> T CmdArgParser::Num(size_t idx) {
|
||||
auto arg = SafeSV(idx);
|
||||
T out;
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
if (absl::SimpleAtof(arg, &out))
|
||||
return out;
|
||||
} else if constexpr (std::is_same_v<T, double>) {
|
||||
if (absl::SimpleAtod(arg, &out))
|
||||
return out;
|
||||
} else if constexpr (std::is_integral_v<T> && sizeof(T) >= sizeof(int32_t)) {
|
||||
if (absl::SimpleAtoi(arg, &out))
|
||||
return out;
|
||||
} else if constexpr (std::is_integral_v<T> && sizeof(T) < sizeof(int32_t)) {
|
||||
int32_t tmp;
|
||||
if (absl::SimpleAtoi(arg, &tmp)) {
|
||||
out = tmp; // out can not store the whole tmp
|
||||
if (tmp == out)
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
Report(INVALID_INT, idx);
|
||||
return {};
|
||||
}
|
||||
|
||||
template float CmdArgParser::Num<float>(size_t);
|
||||
template double CmdArgParser::Num<double>(size_t);
|
||||
template unsigned long CmdArgParser::Num<unsigned long>(size_t);
|
||||
template unsigned long long CmdArgParser::Num<unsigned long long>(size_t);
|
||||
template int64_t CmdArgParser::Num<int64_t>(size_t);
|
||||
template uint32_t CmdArgParser::Num<uint32_t>(size_t);
|
||||
template int32_t CmdArgParser::Num<int32_t>(size_t);
|
||||
template uint16_t CmdArgParser::Num<uint16_t>(size_t);
|
||||
template int16_t CmdArgParser::Num<int16_t>(size_t);
|
||||
|
||||
ErrorReply CmdArgParser::ErrorInfo::MakeReply() const {
|
||||
switch (type) {
|
||||
case INVALID_INT:
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <absl/strings/numbers.h>
|
||||
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
|
@ -186,7 +188,30 @@ struct CmdArgParser {
|
|||
error_ = {type, idx};
|
||||
}
|
||||
|
||||
template <typename T> T Num(size_t idx);
|
||||
template <typename T> T Num(size_t idx) {
|
||||
auto arg = SafeSV(idx);
|
||||
T out;
|
||||
if constexpr (std::is_same_v<T, float>) {
|
||||
if (absl::SimpleAtof(arg, &out))
|
||||
return out;
|
||||
} else if constexpr (std::is_same_v<T, double>) {
|
||||
if (absl::SimpleAtod(arg, &out))
|
||||
return out;
|
||||
} else if constexpr (std::is_integral_v<T> && sizeof(T) >= sizeof(int32_t)) {
|
||||
if (absl::SimpleAtoi(arg, &out))
|
||||
return out;
|
||||
} else if constexpr (std::is_integral_v<T> && sizeof(T) < sizeof(int32_t)) {
|
||||
int32_t tmp;
|
||||
if (absl::SimpleAtoi(arg, &tmp)) {
|
||||
out = tmp; // out can not store the whole tmp
|
||||
if (tmp == out)
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
Report(INVALID_INT, idx);
|
||||
return {};
|
||||
}
|
||||
|
||||
void ToUpper(size_t i);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue