Clean-up sign-conversion warnings (5 of n)
This commit is contained in:
parent
043c5da51c
commit
cd7c1e647e
14
test/scan.h
14
test/scan.h
@ -6,6 +6,7 @@
|
|||||||
// For the license information refer to format.h.
|
// For the license information refer to format.h.
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
#include "fmt/format.h"
|
#include "fmt/format.h"
|
||||||
|
|
||||||
@ -135,21 +136,20 @@ struct scan_handler : error_handler {
|
|||||||
char c = *it++;
|
char c = *it++;
|
||||||
if (c < '0' || c > '9') on_error("invalid input");
|
if (c < '0' || c > '9') on_error("invalid input");
|
||||||
// TODO: check overflow
|
// TODO: check overflow
|
||||||
value = value * 10 + (c - '0');
|
value = value * 10 + static_cast<unsigned>(c - '0');
|
||||||
}
|
}
|
||||||
scan_ctx_.advance_to(it);
|
scan_ctx_.advance_to(it);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T = int> T read_int() {
|
template <typename T = int> T read_int() {
|
||||||
T value = 0;
|
|
||||||
auto it = scan_ctx_.begin(), end = scan_ctx_.end();
|
auto it = scan_ctx_.begin(), end = scan_ctx_.end();
|
||||||
bool negative = it != end && *it == '-';
|
bool negative = it != end && *it == '-';
|
||||||
if (negative) ++it;
|
if (negative) ++it;
|
||||||
scan_ctx_.advance_to(it);
|
scan_ctx_.advance_to(it);
|
||||||
value = read_uint<typename std::make_unsigned<T>::type>();
|
const auto value = read_uint<typename std::make_unsigned<T>::type>();
|
||||||
if (negative) value = -value;
|
if (negative) return -static_cast<T>(value);
|
||||||
return value;
|
return static_cast<T>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -159,7 +159,7 @@ struct scan_handler : error_handler {
|
|||||||
const char* pos() const { return scan_ctx_.begin(); }
|
const char* pos() const { return scan_ctx_.begin(); }
|
||||||
|
|
||||||
void on_text(const char* begin, const char* end) {
|
void on_text(const char* begin, const char* end) {
|
||||||
auto size = end - begin;
|
auto size = static_cast<size_t>(end - begin);
|
||||||
auto it = scan_ctx_.begin();
|
auto it = scan_ctx_.begin();
|
||||||
if (it + size > scan_ctx_.end() ||
|
if (it + size > scan_ctx_.end() ||
|
||||||
!std::equal(begin, end, make_checked(it, size))) {
|
!std::equal(begin, end, make_checked(it, size))) {
|
||||||
@ -197,7 +197,7 @@ struct scan_handler : error_handler {
|
|||||||
case scan_type::string_view_type: {
|
case scan_type::string_view_type: {
|
||||||
auto s = it;
|
auto s = it;
|
||||||
while (it != end && *it != ' ') ++it;
|
while (it != end && *it != ' ') ++it;
|
||||||
*arg_.string_view = fmt::string_view(s, it - s);
|
*arg_.string_view = fmt::string_view(s, static_cast<size_t>(it - s));
|
||||||
scan_ctx_.advance_to(it);
|
scan_ctx_.advance_to(it);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user