Writes a value without checking the buffer length with regards to the required number of digits to encode the value.
More...
Writes a value without checking the buffer length with regards to the required number of digits to encode the value.
It is the responsibility of the caller to ensure that the provided number of digits is enough to write the given value. Notwithstanding the name, assertions are liberally performed, so this code is safe.
◆ write_dec_unchecked()
template<class T>
| void c4::write_dec_unchecked |
( |
substr | buf, |
|
|
T | v, |
|
|
unsigned | digits_v ) |
|
inlinenoexcept |
Definition at line 615 of file charconv.hpp.
616{
617 C4_STATIC_ASSERT(std::is_integral<T>::value);
618 C4_ASSERT(v >= 0);
619 C4_ASSERT(buf.
len >= digits_v);
621
622 while(v >= T(100))
623 {
624 T quo = v;
625 quo /= T(100);
626 const auto num = (v - quo * T(100)) << 1u;
627 v = quo;
628 buf.
str[--digits_v] = detail::digits0099[num + 1];
629 buf.
str[--digits_v] = detail::digits0099[num];
630 }
631 if(v >= T(10))
632 {
633 C4_ASSERT(digits_v == 2);
634 const auto num = v << 1u;
635 buf.
str[1] = detail::digits0099[num + 1];
636 buf.
str[0] = detail::digits0099[num];
637 }
638 else
639 {
640 C4_ASSERT(digits_v == 1);
641 buf.
str[0] = (char)(
'0' + v);
642 }
643}
auto digits_dec(T v) noexcept -> typename std::enable_if< sizeof(T)==1u, unsigned >::type
decimal digits for 8 bit integers
size_t len
the length of the substring
C * str
a restricted pointer to the first character of the substring
◆ write_hex_unchecked()
template<class T>
| void c4::write_hex_unchecked |
( |
substr | buf, |
|
|
T | v, |
|
|
unsigned | digits_v ) |
|
inlinenoexcept |
Definition at line 648 of file charconv.hpp.
649{
650 C4_STATIC_ASSERT(std::is_integral<T>::value);
651 C4_ASSERT(v >= 0);
652 C4_ASSERT(buf.
len >= digits_v);
654 do {
655 buf.
str[--digits_v] = detail::hexchars[v & T(15)];
656 v >>= 4;
657 } while(v);
658 C4_ASSERT(digits_v == 0);
659}
unsigned digits_hex(T v) noexcept
return the number of digits required to encode an hexadecimal number.
◆ write_oct_unchecked()
template<class T>
| void c4::write_oct_unchecked |
( |
substr | buf, |
|
|
T | v, |
|
|
unsigned | digits_v ) |
|
inlinenoexcept |
Definition at line 664 of file charconv.hpp.
665{
666 C4_STATIC_ASSERT(std::is_integral<T>::value);
667 C4_ASSERT(v >= 0);
668 C4_ASSERT(buf.
len >= digits_v);
670 do {
671 buf.
str[--digits_v] = (char)(
'0' + (v & T(7)));
672 v >>= 3;
673 } while(v);
674 C4_ASSERT(digits_v == 0);
675}
unsigned digits_oct(T v_) noexcept
return the number of digits required to encode an octal number.
◆ write_bin_unchecked()
template<class T>
| void c4::write_bin_unchecked |
( |
substr | buf, |
|
|
T | v, |
|
|
unsigned | digits_v ) |
|
inlinenoexcept |
Definition at line 680 of file charconv.hpp.
681{
682 C4_STATIC_ASSERT(std::is_integral<T>::value);
683 C4_ASSERT(v >= 0);
684 C4_ASSERT(buf.
len >= digits_v);
686 do {
687 buf.
str[--digits_v] = (char)(
'0' + (v & T(1)));
688 v >>= 1;
689 } while(v);
690 C4_ASSERT(digits_v == 0);
691}
unsigned digits_bin(T v) noexcept
return the number of digits required to encode a binary number.