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 614 of file charconv.hpp.
615{
616 C4_STATIC_ASSERT(std::is_integral<T>::value);
617 C4_ASSERT(v >= 0);
618 C4_ASSERT(buf.
len >= digits_v);
620
621 while(v >= T(100))
622 {
623 T quo = v;
624 quo /= T(100);
625 const auto num = (v - quo * T(100)) << 1u;
626 v = quo;
627 buf.
str[--digits_v] = detail::digits0099[num + 1];
628 buf.
str[--digits_v] = detail::digits0099[num];
629 }
630 if(v >= T(10))
631 {
632 C4_ASSERT(digits_v == 2);
633 const auto num = v << 1u;
634 buf.
str[1] = detail::digits0099[num + 1];
635 buf.
str[0] = detail::digits0099[num];
636 }
637 else
638 {
639 C4_ASSERT(digits_v == 1);
640 buf.
str[0] = (char)(
'0' + v);
641 }
642}
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
Referenced by itoa(), itoa(), utoa(), and write_dec().
◆ write_hex_unchecked()
template<class T>
| void c4::write_hex_unchecked |
( |
substr | buf, |
|
|
T | v, |
|
|
unsigned | digits_v ) |
|
inlinenoexcept |
Definition at line 647 of file charconv.hpp.
648{
649 C4_STATIC_ASSERT(std::is_integral<T>::value);
650 C4_ASSERT(v >= 0);
651 C4_ASSERT(buf.
len >= digits_v);
653 do {
654 buf.
str[--digits_v] = detail::hexchars[v & T(15)];
655 v >>= 4;
656 } while(v);
657 C4_ASSERT(digits_v == 0);
658}
unsigned digits_hex(T v) noexcept
return the number of digits required to encode an hexadecimal number.
Referenced by itoa(), utoa(), and write_hex().
◆ write_oct_unchecked()
template<class T>
| void c4::write_oct_unchecked |
( |
substr | buf, |
|
|
T | v, |
|
|
unsigned | digits_v ) |
|
inlinenoexcept |
Definition at line 663 of file charconv.hpp.
664{
665 C4_STATIC_ASSERT(std::is_integral<T>::value);
666 C4_ASSERT(v >= 0);
667 C4_ASSERT(buf.
len >= digits_v);
669 do {
670 buf.
str[--digits_v] = (char)(
'0' + (v & T(7)));
671 v >>= 3;
672 } while(v);
673 C4_ASSERT(digits_v == 0);
674}
unsigned digits_oct(T v_) noexcept
return the number of digits required to encode an octal number.
Referenced by itoa(), utoa(), and write_oct().
◆ write_bin_unchecked()
template<class T>
| void c4::write_bin_unchecked |
( |
substr | buf, |
|
|
T | v, |
|
|
unsigned | digits_v ) |
|
inlinenoexcept |
Definition at line 679 of file charconv.hpp.
680{
681 C4_STATIC_ASSERT(std::is_integral<T>::value);
682 C4_ASSERT(v >= 0);
683 C4_ASSERT(buf.
len >= digits_v);
685 do {
686 buf.
str[--digits_v] = (char)(
'0' + (v & T(1)));
687 v >>= 1;
688 } while(v);
689 C4_ASSERT(digits_v == 0);
690}
unsigned digits_bin(T v) noexcept
return the number of digits required to encode a binary number.
Referenced by itoa(), utoa(), and write_bin().