rapidyaml  0.7.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 708 of file charconv.hpp.

709 {
710  C4_STATIC_ASSERT(std::is_integral<T>::value);
711  C4_ASSERT(v >= 0);
712  unsigned digits = digits_dec(v);
713  if(C4_LIKELY(buf.len >= digits))
714  write_dec_unchecked(buf, v, digits);
715  return digits;
716 }
auto digits_dec(T v) noexcept -> typename std::enable_if< sizeof(T)==1u, unsigned >::type
decimal digits for 8 bit integers
Definition: charconv.hpp:441
void write_dec_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:608

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

Referenced by c4::itoa(), c4::utoa(), and c4::xtoa().

◆ 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 727 of file charconv.hpp.

728 {
729  C4_STATIC_ASSERT(std::is_integral<T>::value);
730  C4_ASSERT(v >= 0);
731  unsigned digits = digits_hex(v);
732  if(C4_LIKELY(buf.len >= digits))
733  write_hex_unchecked(buf, v, digits);
734  return digits;
735 }
unsigned digits_hex(T v) noexcept
return the number of digits required to encode an hexadecimal number.
Definition: charconv.hpp:524
void write_hex_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:641

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

Referenced by c4::itoa(), and c4::utoa().

◆ 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 746 of file charconv.hpp.

747 {
748  C4_STATIC_ASSERT(std::is_integral<T>::value);
749  C4_ASSERT(v >= 0);
750  unsigned digits = digits_oct(v);
751  if(C4_LIKELY(buf.len >= digits))
752  write_oct_unchecked(buf, v, digits);
753  return digits;
754 }
unsigned digits_oct(T v_) noexcept
return the number of digits required to encode an octal number.
Definition: charconv.hpp:542
void write_oct_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:657

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

Referenced by c4::itoa(), and c4::utoa().

◆ 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 765 of file charconv.hpp.

766 {
767  C4_STATIC_ASSERT(std::is_integral<T>::value);
768  C4_ASSERT(v >= 0);
769  unsigned digits = digits_bin(v);
770  C4_ASSERT(digits > 0);
771  if(C4_LIKELY(buf.len >= digits))
772  write_bin_unchecked(buf, v, digits);
773  return digits;
774 }
unsigned digits_bin(T v) noexcept
return the number of digits required to encode a binary number.
Definition: charconv.hpp:533
void write_bin_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:673

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

Referenced by c4::itoa(), and c4::utoa().

◆ 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 803 of file charconv.hpp.

804 {
805  return detail::write_num_digits<T, &write_dec<T>>(buf, val, num_digits);
806 }

Referenced by c4::to_chars().

◆ 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 812 of file charconv.hpp.

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

◆ 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 821 of file charconv.hpp.

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

◆ 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 830 of file charconv.hpp.

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