rapidyaml  0.8.0
parse and emit YAML, and do it fast
unformat: formatted read from string

Functions

template<class Arg , class... Args>
size_t c4::unformat (csubstr buf, csubstr fmt, Arg &a, Args &...more)
 using a format string, deserialize the arguments from the given buffer. More...
 

Detailed Description

Function Documentation

◆ unformat()

template<class Arg , class... Args>
size_t c4::unformat ( csubstr  buf,
csubstr  fmt,
Arg &  a,
Args &...  more 
)

using a format string, deserialize the arguments from the given buffer.

Returns
the number of characters read from the buffer, or npos if a conversion failed.
See also
c4::format(). c4::unformat() is the inverse function to format().

Definition at line 865 of file format.hpp.

866 {
867  const size_t pos = fmt.find("{}");
868  if(C4_UNLIKELY(pos == csubstr::npos))
869  return unformat(buf, fmt);
870  size_t num = pos;
871  size_t out = num;
872  buf = buf.len >= num ? buf.sub(num) : substr{};
873  num = from_chars_first(buf, &a);
874  if(C4_UNLIKELY(num == csubstr::npos))
875  return csubstr::npos;
876  out += num;
877  buf = buf.len >= num ? buf.sub(num) : substr{};
878  num = unformat(buf, fmt.sub(pos + 2), more...);
879  if(C4_UNLIKELY(num == csubstr::npos))
880  return csubstr::npos;
881  out += num;
882  return out;
883 }
size_t from_chars_first(csubstr buf, fmt::raw_wrapper r)
read a variable in raw binary format, using memcpy
Definition: format.hpp:486
size_t unformat(csubstr buf, csubstr fmt, Arg &a, Args &...more)
using a format string, deserialize the arguments from the given buffer.
Definition: format.hpp:865
@ npos
a null string position
Definition: common.hpp:267

References c4::from_chars_first(), and c4::yml::npos.

Referenced by sample::from_chars(), and sample::sample_formatting().