mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Remove limits dependency
This commit is contained in:
@ -11,7 +11,7 @@
|
|||||||
#include <cstddef> // std::byte
|
#include <cstddef> // std::byte
|
||||||
#include <cstdio> // std::FILE
|
#include <cstdio> // std::FILE
|
||||||
#include <cstring> // std::strlen
|
#include <cstring> // std::strlen
|
||||||
#include <limits> // std::numeric_limits
|
#include <limits.h> // CHAR_BIT
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
#include <type_traits> // std::enable_if
|
#include <type_traits> // std::enable_if
|
||||||
|
|
||||||
@ -2166,11 +2166,11 @@ FMT_CONSTEXPR auto parse_nonnegative_int(const Char*& begin, const Char* end,
|
|||||||
} while (p != end && '0' <= *p && *p <= '9');
|
} while (p != end && '0' <= *p && *p <= '9');
|
||||||
auto num_digits = p - begin;
|
auto num_digits = p - begin;
|
||||||
begin = p;
|
begin = p;
|
||||||
if (num_digits <= std::numeric_limits<int>::digits10)
|
int digits10 = static_cast<int>(sizeof(int) * CHAR_BIT * 3 / 10);
|
||||||
return static_cast<int>(value);
|
if (num_digits <= digits10) return static_cast<int>(value);
|
||||||
// Check for overflow.
|
// Check for overflow.
|
||||||
const unsigned max = to_unsigned((std::numeric_limits<int>::max)());
|
unsigned max = INT_MAX;
|
||||||
return num_digits == std::numeric_limits<int>::digits10 + 1 &&
|
return num_digits == digits10 + 1 &&
|
||||||
prev * 10ull + unsigned(p[-1] - '0') <= max
|
prev * 10ull + unsigned(p[-1] - '0') <= max
|
||||||
? static_cast<int>(value)
|
? static_cast<int>(value)
|
||||||
: error_value;
|
: error_value;
|
||||||
@ -2198,9 +2198,8 @@ FMT_CONSTEXPR auto do_parse_arg_id(const Char* begin, const Char* end,
|
|||||||
Char c = *begin;
|
Char c = *begin;
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
constexpr int max = (std::numeric_limits<int>::max)();
|
|
||||||
if (c != '0')
|
if (c != '0')
|
||||||
index = parse_nonnegative_int(begin, end, max);
|
index = parse_nonnegative_int(begin, end, INT_MAX);
|
||||||
else
|
else
|
||||||
++begin;
|
++begin;
|
||||||
if (begin == end || (*begin != '}' && *begin != ':'))
|
if (begin == end || (*begin != '}' && *begin != ':'))
|
||||||
|
Reference in New Issue
Block a user