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

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}
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
void write_dec_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition charconv.hpp:614
size_t len
the length of the substring
Definition substr.hpp:218

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

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

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}
unsigned digits_hex(T v) noexcept
return the number of digits required to encode an hexadecimal number.
Definition charconv.hpp:529
void write_hex_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition charconv.hpp:647

Referenced by itoa(), and utoa().

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

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}
unsigned digits_oct(T v_) noexcept
return the number of digits required to encode an octal number.
Definition charconv.hpp:547
void write_oct_unchecked(substr buf, T v, unsigned digits_v) noexcept
Definition charconv.hpp:663

Referenced by itoa(), and utoa().

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

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

Referenced by itoa(), and utoa().

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

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

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

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

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

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

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

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