rapidyaml  0.11.0
parse and emit YAML, and do it fast
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. More...
 
template<class T >
size_t c4::write_hex (substr buf, T v) noexcept
 write an integer to a string in hexadecimal format. More...
 
template<class T >
size_t c4::write_oct (substr buf, T v) noexcept
 write an integer to a string in octal format. More...
 
template<class T >
size_t c4::write_bin (substr buf, T v) noexcept
 write an integer to a string in binary format. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

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,
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 701 of file charconv.hpp.

702 {
703  C4_STATIC_ASSERT(std::is_integral<T>::value);
704  C4_ASSERT(v >= 0);
705  unsigned digits = digits_dec(v);
706  if(C4_LIKELY(buf.len >= digits))
707  write_dec_unchecked(buf, v, digits);
708  return digits;
709 }
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:601

References c4::digits_dec(), and c4::write_dec_unchecked().

◆ write_hex() [1/2]

template<class T >
size_t c4::write_hex ( substr  buf,
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 720 of file charconv.hpp.

721 {
722  C4_STATIC_ASSERT(std::is_integral<T>::value);
723  C4_ASSERT(v >= 0);
724  unsigned digits = digits_hex(v);
725  if(C4_LIKELY(buf.len >= digits))
726  write_hex_unchecked(buf, v, digits);
727  return digits;
728 }
unsigned digits_hex(T v) noexcept
return the number of digits required to encode an hexadecimal number.
Definition: charconv.hpp:516
void write_hex_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:634

References c4::digits_hex(), and c4::write_hex_unchecked().

◆ write_oct() [1/2]

template<class T >
size_t c4::write_oct ( substr  buf,
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 739 of file charconv.hpp.

740 {
741  C4_STATIC_ASSERT(std::is_integral<T>::value);
742  C4_ASSERT(v >= 0);
743  unsigned digits = digits_oct(v);
744  if(C4_LIKELY(buf.len >= digits))
745  write_oct_unchecked(buf, v, digits);
746  return digits;
747 }
unsigned digits_oct(T v_) noexcept
return the number of digits required to encode an octal number.
Definition: charconv.hpp:534
void write_oct_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:650

References c4::digits_oct(), and c4::write_oct_unchecked().

◆ write_bin() [1/2]

template<class T >
size_t c4::write_bin ( substr  buf,
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 758 of file charconv.hpp.

759 {
760  C4_STATIC_ASSERT(std::is_integral<T>::value);
761  C4_ASSERT(v >= 0);
762  unsigned digits = digits_bin(v);
763  C4_ASSERT(digits > 0);
764  if(C4_LIKELY(buf.len >= digits))
765  write_bin_unchecked(buf, v, digits);
766  return digits;
767 }
unsigned digits_bin(T v) noexcept
return the number of digits required to encode a binary number.
Definition: charconv.hpp:525
void write_bin_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:666

References c4::digits_bin(), and c4::write_bin_unchecked().

◆ write_dec() [2/2]

template<class T >
size_t c4::write_dec ( substr  buf,
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 is requires more than num_digits, then the number prevails.

Definition at line 799 of file charconv.hpp.

800 {
801  return detail::write_num_digits<T, &write_dec<T>>(buf, val, num_digits);
802 }

◆ write_hex() [2/2]

template<class T >
size_t c4::write_hex ( substr  buf,
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 is requires more than num_digits, then the number prevails.

Definition at line 808 of file charconv.hpp.

809 {
810  return detail::write_num_digits<T, &write_hex<T>>(buf, val, num_digits);
811 }

◆ write_bin() [2/2]

template<class T >
size_t c4::write_bin ( substr  buf,
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 is requires more than num_digits, then the number prevails.

Definition at line 817 of file charconv.hpp.

818 {
819  return detail::write_num_digits<T, &write_bin<T>>(buf, val, num_digits);
820 }

◆ write_oct() [2/2]

template<class T >
size_t c4::write_oct ( substr  buf,
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 is requires more than num_digits, then the number prevails.

Definition at line 826 of file charconv.hpp.

827 {
828  return detail::write_num_digits<T, &write_oct<T>>(buf, val, num_digits);
829 }