rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
Write a value

Writes a value without checking the buffer length decimal number – but asserting. More...

Functions

template<class T>
size_t c4::write_dec (substr buf, T v) noexcept
 write an integer to a string in decimal format.
template<class T>
size_t c4::write_hex (substr buf, T v) noexcept
 write an integer to a string in hexadecimal format.
template<class T>
size_t c4::write_oct (substr buf, T v) noexcept
 write an integer to a string in octal format.
template<class T>
size_t c4::write_bin (substr buf, T v) noexcept
 write an integer to a string in binary format.
template<class T>
size_t c4::write_dec (substr buf, T val, size_t num_digits) noexcept
 same as c4::write_dec(), but pad with zeroes on the left such that the resulting string is num_digits wide.
template<class T>
size_t c4::write_hex (substr buf, T val, size_t num_digits) noexcept
 same as c4::write_hex(), but pad with zeroes on the left such that the resulting string is num_digits wide.
template<class T>
size_t c4::write_bin (substr buf, T val, size_t num_digits) noexcept
 same as c4::write_bin(), but pad with zeroes on the left such that the resulting string is num_digits wide.
template<class T>
size_t c4::write_oct (substr buf, T val, size_t num_digits) noexcept
 same as c4::write_oct(), but pad with zeroes on the left such that the resulting string is num_digits wide.

Detailed Description

Writes a value without checking the buffer length decimal number – but asserting.

Function Documentation

◆ write_dec() [1/2]

template<class T>
size_t c4::write_dec ( substr buf,
T v )
inlinenoexcept

write an integer to a string in decimal format.

This is the lowest level (and the fastest) function to do this task.

Note
does not accept negative numbers
the resulting string is NOT zero-terminated.
it is ok to call this with an empty or too-small buffer; no writes will occur, and the required size will be returned
Returns
the number of characters required for the buffer.

Definition at line 715 of file charconv.hpp.

716{
717 C4_STATIC_ASSERT(std::is_integral<T>::value);
718 C4_ASSERT(v >= 0);
719 unsigned digits = digits_dec(v);
720 if(C4_LIKELY(buf.len >= digits))
721 write_dec_unchecked(buf, v, digits);
722 return digits;
723}
auto digits_dec(T v) noexcept -> typename std::enable_if< sizeof(T)==1u, unsigned >::type
decimal digits for 8 bit integers
Definition charconv.hpp:433
void write_dec_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition charconv.hpp:615
size_t len
the length of the substring
Definition substr.hpp:218

◆ write_hex() [1/2]

template<class T>
size_t c4::write_hex ( substr buf,
T v )
inlinenoexcept

write an integer to a string in hexadecimal format.

This is the lowest level (and the fastest) function to do this task.

Note
does not accept negative numbers
does not prefix with 0x
the resulting string is NOT zero-terminated.
it is ok to call this with an empty or too-small buffer; no writes will occur, and the required size will be returned
Returns
the number of characters required for the buffer.

Definition at line 734 of file charconv.hpp.

735{
736 C4_STATIC_ASSERT(std::is_integral<T>::value);
737 C4_ASSERT(v >= 0);
738 unsigned digits = digits_hex(v);
739 if(C4_LIKELY(buf.len >= digits))
740 write_hex_unchecked(buf, v, digits);
741 return digits;
742}
unsigned digits_hex(T v) noexcept
return the number of digits required to encode an hexadecimal number.
Definition charconv.hpp:530
void write_hex_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition charconv.hpp:648

◆ write_oct() [1/2]

template<class T>
size_t c4::write_oct ( substr buf,
T v )
inlinenoexcept

write an integer to a string in octal format.

This is the lowest level (and the fastest) function to do this task.

Note
does not accept negative numbers
does not prefix with 0o
the resulting string is NOT zero-terminated.
it is ok to call this with an empty or too-small buffer; no writes will occur, and the required size will be returned
Returns
the number of characters required for the buffer.

Definition at line 753 of file charconv.hpp.

754{
755 C4_STATIC_ASSERT(std::is_integral<T>::value);
756 C4_ASSERT(v >= 0);
757 unsigned digits = digits_oct(v);
758 if(C4_LIKELY(buf.len >= digits))
759 write_oct_unchecked(buf, v, digits);
760 return digits;
761}
unsigned digits_oct(T v_) noexcept
return the number of digits required to encode an octal number.
Definition charconv.hpp:548
void write_oct_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition charconv.hpp:664

◆ write_bin() [1/2]

template<class T>
size_t c4::write_bin ( substr buf,
T v )
inlinenoexcept

write an integer to a string in binary format.

This is the lowest level (and the fastest) function to do this task.

Note
does not accept negative numbers
does not prefix with 0b
the resulting string is NOT zero-terminated.
it is ok to call this with an empty or too-small buffer; no writes will occur, and the required size will be returned
Returns
the number of characters required for the buffer.

Definition at line 772 of file charconv.hpp.

773{
774 C4_STATIC_ASSERT(std::is_integral<T>::value);
775 C4_ASSERT(v >= 0);
776 unsigned digits = digits_bin(v);
777 C4_ASSERT(digits > 0);
778 if(C4_LIKELY(buf.len >= digits))
779 write_bin_unchecked(buf, v, digits);
780 return digits;
781}
unsigned digits_bin(T v) noexcept
return the number of digits required to encode a binary number.
Definition charconv.hpp:539
void write_bin_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition charconv.hpp:680

◆ write_dec() [2/2]

template<class T>
size_t c4::write_dec ( substr buf,
T val,
size_t num_digits )
inlinenoexcept

same as c4::write_dec(), but pad with zeroes on the left such that the resulting string is num_digits wide.

If the given number requires more than num_digits, then the number prevails.

Definition at line 813 of file charconv.hpp.

814{
815 return detail::write_num_digits<T, &write_dec<T>>(buf, val, num_digits);
816}

◆ write_hex() [2/2]

template<class T>
size_t c4::write_hex ( substr buf,
T val,
size_t num_digits )
inlinenoexcept

same as c4::write_hex(), but pad with zeroes on the left such that the resulting string is num_digits wide.

If the given number requires more than num_digits, then the number prevails.

Definition at line 822 of file charconv.hpp.

823{
824 return detail::write_num_digits<T, &write_hex<T>>(buf, val, num_digits);
825}

◆ write_bin() [2/2]

template<class T>
size_t c4::write_bin ( substr buf,
T val,
size_t num_digits )
inlinenoexcept

same as c4::write_bin(), but pad with zeroes on the left such that the resulting string is num_digits wide.

If the given number requires more than num_digits, then the number prevails.

Definition at line 831 of file charconv.hpp.

832{
833 return detail::write_num_digits<T, &write_bin<T>>(buf, val, num_digits);
834}

◆ write_oct() [2/2]

template<class T>
size_t c4::write_oct ( substr buf,
T val,
size_t num_digits )
inlinenoexcept

same as c4::write_oct(), but pad with zeroes on the left such that the resulting string is num_digits wide.

If the given number requires more than num_digits, then the number prevails.

Definition at line 840 of file charconv.hpp.

841{
842 return detail::write_num_digits<T, &write_oct<T>>(buf, val, num_digits);
843}