rapidyaml  0.7.1
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 864 of file format.hpp.

865 {
866  const size_t pos = fmt.find("{}");
867  if(C4_UNLIKELY(pos == csubstr::npos))
868  return unformat(buf, fmt);
869  size_t num = pos;
870  size_t out = num;
871  buf = buf.len >= num ? buf.sub(num) : substr{};
872  num = from_chars_first(buf, &a);
873  if(C4_UNLIKELY(num == csubstr::npos))
874  return csubstr::npos;
875  out += num;
876  buf = buf.len >= num ? buf.sub(num) : substr{};
877  num = unformat(buf, fmt.sub(pos + 2), more...);
878  if(C4_UNLIKELY(num == csubstr::npos))
879  return csubstr::npos;
880  out += num;
881  return out;
882 }
size_t from_chars_first(csubstr buf, fmt::raw_wrapper r)
read a variable in raw binary format, using memcpy
Definition: format.hpp:485
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:864
@ npos
a null string position
Definition: common.hpp:266

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

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