Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jun 4, 2020
1 parent 88c8d53 commit 21409cf
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,22 @@ OutputIt write_int(OutputIt out, int num_digits, string_view prefix,
});
}

template <typename StrChar, typename Char, typename OutputIt>
OutputIt write(OutputIt out, basic_string_view<StrChar> s,
const basic_format_specs<Char>& specs = {}) {
auto data = s.data();
auto size = s.size();
if (specs.precision >= 0 && to_unsigned(specs.precision) < size)
size = code_point_index(s, to_unsigned(specs.precision));
auto width = specs.width != 0
? count_code_points(basic_string_view<StrChar>(data, size))
: 0;
using iterator = remove_reference_t<decltype(reserve(out, 0))>;
return write_padded(out, specs, size, width, [=](iterator it) {
return copy_str<Char>(data, data + size, it);
});
}

// The handle_int_type_spec handler that writes an integer.
template <typename OutputIt, typename Char, typename UInt> struct int_writer {
OutputIt out;
Expand Down Expand Up @@ -1529,15 +1545,15 @@ template <typename OutputIt, typename Char, typename UInt> struct int_writer {
if (group == groups.cend()) size += sep_size * ((n - 1) / groups.back());
char digits[40];
format_decimal(digits, abs_value, num_digits);
memory_buffer buffer;
basic_memory_buffer<Char> buffer;
buffer.resize(size);
basic_string_view<Char> s(&sep, sep_size);
// Index of a decimal digit with the least significant digit having index 0.
int digit_index = 0;
group = groups.cbegin();
auto p = buffer.data() + size;
for (int i = num_digits - 1; i >= 0; --i) {
*--p = digits[i];
*--p = static_cast<Char>(digits[i]);
if (*group <= 0 || ++digit_index % *group != 0 ||
*group == max_value<char>())
continue;
Expand All @@ -1546,9 +1562,10 @@ template <typename OutputIt, typename Char, typename UInt> struct int_writer {
++group;
}
p -= s.size();
std::uninitialized_copy(s.data(), s.data() + s.size(), p);
std::uninitialized_copy(s.data(), s.data() + s.size(),
make_checked(p, s.size()));
}
write_bytes(out, {buffer.data(), buffer.size()}, specs);
write(out, basic_string_view<Char>(buffer.data(), buffer.size()), specs);
}

void on_chr() { *out++ = static_cast<Char>(abs_value); }
Expand Down Expand Up @@ -1633,22 +1650,6 @@ OutputIt write_char(OutputIt out, Char value,
});
}

template <typename StrChar, typename Char, typename OutputIt>
OutputIt write(OutputIt out, basic_string_view<StrChar> s,
const basic_format_specs<Char>& specs = {}) {
auto data = s.data();
auto size = s.size();
if (specs.precision >= 0 && to_unsigned(specs.precision) < size)
size = code_point_index(s, to_unsigned(specs.precision));
auto width = specs.width != 0
? count_code_points(basic_string_view<StrChar>(data, size))
: 0;
using iterator = remove_reference_t<decltype(reserve(out, 0))>;
return write_padded(out, specs, size, width, [=](iterator it) {
return copy_str<Char>(data, data + size, it);
});
}

template <typename Char, typename OutputIt, typename UIntPtr>
OutputIt write_ptr(OutputIt out, UIntPtr value,
const basic_format_specs<Char>* specs) {
Expand Down

0 comments on commit 21409cf

Please sign in to comment.