mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-29 21:31:05 +00:00
Fix conversion warnings in Grisu
This commit is contained in:
parent
322b2594e0
commit
b8b06e3e10
@ -545,30 +545,30 @@ struct gen_digits_params {
|
|||||||
|
|
||||||
struct prettify_handler {
|
struct prettify_handler {
|
||||||
char *data;
|
char *data;
|
||||||
size_t size;
|
ptrdiff_t size;
|
||||||
buffer &buf;
|
buffer &buf;
|
||||||
|
|
||||||
explicit prettify_handler(buffer &b, size_t n)
|
explicit prettify_handler(buffer &b, ptrdiff_t n)
|
||||||
: data(b.data()), size(n), buf(b) {}
|
: data(b.data()), size(n), buf(b) {}
|
||||||
~prettify_handler() {
|
~prettify_handler() {
|
||||||
assert(buf.size() >= size);
|
assert(buf.size() >= to_unsigned(size));
|
||||||
buf.resize(size);
|
buf.resize(to_unsigned(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
void insert(size_t pos, size_t n, F f) {
|
void insert(ptrdiff_t pos, ptrdiff_t n, F f) {
|
||||||
std::memmove(data + pos + n, data + pos, size - pos);
|
std::memmove(data + pos + n, data + pos, to_unsigned(size - pos));
|
||||||
f(data + pos);
|
f(data + pos);
|
||||||
size += n;
|
size += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert(size_t pos, char c) {
|
void insert(ptrdiff_t pos, char c) {
|
||||||
std::memmove(data + pos + 1, data + pos, size - pos);
|
std::memmove(data + pos + 1, data + pos, to_unsigned(size - pos));
|
||||||
data[pos] = c;
|
data[pos] = c;
|
||||||
++size;
|
++size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void append(size_t n, char c) {
|
void append(ptrdiff_t n, char c) {
|
||||||
std::uninitialized_fill_n(data + size, n, c);
|
std::uninitialized_fill_n(data + size, n, c);
|
||||||
size += n;
|
size += n;
|
||||||
}
|
}
|
||||||
@ -615,7 +615,7 @@ struct fill {
|
|||||||
// The number is given as v = f * pow(10, exp), where f has size digits.
|
// The number is given as v = f * pow(10, exp), where f has size digits.
|
||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms,
|
FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms,
|
||||||
size_t size, int exp, Handler &&handler) {
|
ptrdiff_t size, int exp, Handler &&handler) {
|
||||||
if (!params.fixed) {
|
if (!params.fixed) {
|
||||||
// Insert a decimal point after the first digit and add an exponent.
|
// Insert a decimal point after the first digit and add an exponent.
|
||||||
handler.insert(1, '.');
|
handler.insert(1, '.');
|
||||||
@ -646,7 +646,7 @@ FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms,
|
|||||||
handler.remove_trailing('0');
|
handler.remove_trailing('0');
|
||||||
} else if (params.num_digits > size) {
|
} else if (params.num_digits > size) {
|
||||||
// Add trailing zeros.
|
// Add trailing zeros.
|
||||||
size_t num_zeros = params.num_digits - size;
|
ptrdiff_t num_zeros = params.num_digits - size;
|
||||||
handler.append(num_zeros, '0');
|
handler.append(num_zeros, '0');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -656,12 +656,12 @@ FMT_FUNC void grisu2_prettify(const gen_digits_params ¶ms,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct char_counter {
|
struct char_counter {
|
||||||
size_t size;
|
ptrdiff_t size;
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
void insert(size_t, size_t n, F) { size += n; }
|
void insert(ptrdiff_t, ptrdiff_t n, F) { size += n; }
|
||||||
void insert(size_t, char) { ++size; }
|
void insert(ptrdiff_t, char) { ++size; }
|
||||||
void append(size_t n, char) { size += n; }
|
void append(ptrdiff_t n, char) { size += n; }
|
||||||
void append(char) { ++size; }
|
void append(char) { ++size; }
|
||||||
void remove_trailing(char) {}
|
void remove_trailing(char) {}
|
||||||
};
|
};
|
||||||
@ -704,9 +704,9 @@ FMT_FUNC gen_digits_params process_specs(const core_format_specs &specs,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
params.num_digits = to_unsigned(num_digits);
|
params.num_digits = to_unsigned(num_digits);
|
||||||
char_counter counter{params.num_digits};
|
char_counter counter{num_digits};
|
||||||
grisu2_prettify(params, params.num_digits, exp - num_digits, counter);
|
grisu2_prettify(params, params.num_digits, exp - num_digits, counter);
|
||||||
buf.resize(counter.size);
|
buf.resize(to_unsigned(counter.size));
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user