rapidyaml  0.16.0
parseandemitYAML,anddoitfast
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

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

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

715 {
716  C4_STATIC_ASSERT(std::is_integral<T>::value);
717  C4_ASSERT(v >= 0);
718  unsigned digits = digits_dec(v);
719  if C4_LIKELY(buf.len >= digits)
720  write_dec_unchecked(buf, v, digits);
721  return digits;
722 }
void write_dec_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:614
auto digits_dec(T v) noexcept-> typename std::enable_if< sizeof(T)==1u, unsigned >::type
decimal digits for 8 bit integers
Definition: charconv.hpp:432
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 733 of file charconv.hpp.

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

734 {
735  C4_STATIC_ASSERT(std::is_integral<T>::value);
736  C4_ASSERT(v >= 0);
737  unsigned digits = digits_hex(v);
738  if C4_LIKELY(buf.len >= digits)
739  write_hex_unchecked(buf, v, digits);
740  return digits;
741 }
void write_hex_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:647
unsigned digits_hex(T v) noexcept
return the number of digits required to encode an hexadecimal number.
Definition: charconv.hpp:529
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 752 of file charconv.hpp.

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

753 {
754  C4_STATIC_ASSERT(std::is_integral<T>::value);
755  C4_ASSERT(v >= 0);
756  unsigned digits = digits_oct(v);
757  if C4_LIKELY(buf.len >= digits)
758  write_oct_unchecked(buf, v, digits);
759  return digits;
760 }
void write_oct_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:663
unsigned digits_oct(T v_) noexcept
return the number of digits required to encode an octal number.
Definition: charconv.hpp:547
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 771 of file charconv.hpp.

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

772 {
773  C4_STATIC_ASSERT(std::is_integral<T>::value);
774  C4_ASSERT(v >= 0);
775  unsigned digits = digits_bin(v);
776  C4_ASSERT(digits > 0);
777  if C4_LIKELY(buf.len >= digits)
778  write_bin_unchecked(buf, v, digits);
779  return digits;
780 }
unsigned digits_bin(T v) noexcept
return the number of digits required to encode a binary number.
Definition: charconv.hpp:538
void write_bin_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition: charconv.hpp:679
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 812 of file charconv.hpp.

813 {
814  return detail::write_num_digits<T, &write_dec<T>>(buf, val, num_digits);
815 }
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 821 of file charconv.hpp.

822 {
823  return detail::write_num_digits<T, &write_hex<T>>(buf, val, num_digits);
824 }
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 830 of file charconv.hpp.

831 {
832  return detail::write_num_digits<T, &write_bin<T>>(buf, val, num_digits);
833 }
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 839 of file charconv.hpp.

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