/*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// The code in this file that uses tolower() really only cares about
// 7-bit ASCII characters, so we can take a nice shortcut here.
inline char tolower_ascii(char in) {
- return IsAscii::value ? in | 0x20 : std::tolower(in);
+ return IsAscii::value ? in | 0x20 : char(std::tolower(in));
}
inline bool bool_str_cmp(const char** b, size_t len, const char* value) {
}
bool result;
- size_t len = e - b;
+ size_t len = size_t(e - b);
switch (*b) {
case '0':
case '1': {
// want to raise an error; length will point past the last character
// that was processed, so we need to check if that character was
// whitespace or not.
- if (length == 0 || (result == 0.0 && std::isspace((*src)[length - 1]))) {
+ if (length == 0 ||
+ (result == 0.0 && std::isspace((*src)[size_t(length) - 1]))) {
return makeUnexpected(ConversionCode::EMPTY_INPUT_STRING);
}
- src->advance(length);
- return result;
+ src->advance(size_t(length));
+ return Tgt(result);
}
auto* e = src->end();
// There must be non-whitespace, otherwise we would have caught this above
assert(b < e);
- size_t size = e - b;
+ size_t size = size_t(e - b);
bool negative = false;
if (*b == '-') {
src->assign(b, e);
- return result;
+ return Tgt(result);
}
template Expected<float, ConversionCode> str_to_floating<float>(
Expected<T, ConversionCode> finalize(U value) {
T rv;
if (negative_) {
- rv = -value;
+ rv = T(-value);
if (UNLIKELY(rv > 0)) {
return makeUnexpected(ConversionCode::NEGATIVE_OVERFLOW);
}
} else {
- rv = value;
+ rv = T(value);
if (UNLIKELY(rv < 0)) {
return makeUnexpected(ConversionCode::POSITIVE_OVERFLOW);
}
return makeUnexpected(err);
}
- size_t size = e - b;
+ size_t size = size_t(e - b);
/* Although the string is entirely made of digits, we still need to
* check for overflow.
return Tgt(0); // just zeros, e.g. "0000"
}
if (*b != '0') {
- size = e - b;
+ size = size_t(e - b);
break;
}
}
UT result = 0;
for (; e - b >= 4; b += 4) {
- result *= 10000;
+ result *= static_cast<UT>(10000);
const int32_t r0 = shift1000[static_cast<size_t>(b[0])];
const int32_t r1 = shift100[static_cast<size_t>(b[1])];
const int32_t r2 = shift10[static_cast<size_t>(b[2])];
if (sum >= OOR) {
goto outOfRange;
}
- result += sum;
+ result += UT(sum);
}
switch (e - b) {
if (sum >= OOR) {
goto outOfRange;
}
- result = 1000 * result + sum;
+ result = UT(1000 * result + sum);
break;
}
case 2: {
if (sum >= OOR) {
goto outOfRange;
}
- result = 100 * result + sum;
+ result = UT(100 * result + sum);
break;
}
case 1: {
if (sum >= OOR) {
goto outOfRange;
}
- result = 10 * result + sum;
+ result = UT(10 * result + sum);
break;
}
default:
template Expected<long, ConversionCode> digits_to<long>(
const char*,
- const char*);
+ const char*) noexcept;
template Expected<unsigned long, ConversionCode> digits_to<unsigned long>(
const char*,
const char*) noexcept;
auto res = sgn.finalize(tmp.value());
if (res.hasValue()) {
- src->advance(m - src->data());
+ src->advance(size_t(m - src->data()));
}
return res;