MCPcopy Create free account
hub / github.com/ablab/spades / write_int

Method write_int

ext/include/cppformat/format.h:1753–1831  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1751template <typename Char>
1752template <typename T, typename Spec>
1753void BasicWriter<Char>::write_int(T value, Spec spec) {
1754 unsigned prefix_size = 0;
1755 typedef typename internal::IntTraits<T>::MainType UnsignedType;
1756 UnsignedType abs_value = value;
1757 char prefix[4] = "";
1758 if (internal::is_negative(value)) {
1759 prefix[0] = '-';
1760 ++prefix_size;
1761 abs_value = 0 - abs_value;
1762 } else if (spec.flag(SIGN_FLAG)) {
1763 prefix[0] = spec.flag(PLUS_FLAG) ? '+' : ' ';
1764 ++prefix_size;
1765 }
1766 switch (spec.type()) {
1767 case 0: case 'd': {
1768 unsigned num_digits = internal::count_digits(abs_value);
1769 CharPtr p = prepare_int_buffer(
1770 num_digits, spec, prefix, prefix_size) + 1 - num_digits;
1771 internal::format_decimal(get(p), abs_value, num_digits);
1772 break;
1773 }
1774 case 'x': case 'X': {
1775 UnsignedType n = abs_value;
1776 if (spec.flag(HASH_FLAG)) {
1777 prefix[prefix_size++] = '0';
1778 prefix[prefix_size++] = spec.type();
1779 }
1780 unsigned num_digits = 0;
1781 do {
1782 ++num_digits;
1783 } while ((n >>= 4) != 0);
1784 Char *p = get(prepare_int_buffer(
1785 num_digits, spec, prefix, prefix_size));
1786 n = abs_value;
1787 const char *digits = spec.type() == 'x' ?
1788 "0123456789abcdef" : "0123456789ABCDEF";
1789 do {
1790 *p-- = digits[n & 0xf];
1791 } while ((n >>= 4) != 0);
1792 break;
1793 }
1794 case 'b': case 'B': {
1795 UnsignedType n = abs_value;
1796 if (spec.flag(HASH_FLAG)) {
1797 prefix[prefix_size++] = '0';
1798 prefix[prefix_size++] = spec.type();
1799 }
1800 unsigned num_digits = 0;
1801 do {
1802 ++num_digits;
1803 } while ((n >>= 1) != 0);
1804 Char *p = get(prepare_int_buffer(num_digits, spec, prefix, prefix_size));
1805 n = abs_value;
1806 do {
1807 *p-- = '0' + (n & 1);
1808 } while ((n >>= 1) != 0);
1809 break;
1810 }

Callers 4

visit_any_intMethod · 0.80
visit_charMethod · 0.80
visit_pointerMethod · 0.80
formatMethod · 0.80

Calls 6

count_digitsFunction · 0.85
is_negativeFunction · 0.70
format_decimalFunction · 0.70
getFunction · 0.50
flagMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected