rapidyaml  0.7.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 855 of file format.hpp.

856 {
857  const size_t pos = fmt.find("{}");
858  if(C4_UNLIKELY(pos == csubstr::npos))
859  return unformat(buf, fmt);
860  size_t num = pos;
861  size_t out = num;
862  buf = buf.len >= num ? buf.sub(num) : substr{};
863  num = from_chars_first(buf, &a);
864  if(C4_UNLIKELY(num == csubstr::npos))
865  return csubstr::npos;
866  out += num;
867  buf = buf.len >= num ? buf.sub(num) : substr{};
868  num = unformat(buf, fmt.sub(pos + 2), more...);
869  if(C4_UNLIKELY(num == csubstr::npos))
870  return csubstr::npos;
871  out += num;
872  return out;
873 }
size_t from_chars_first(csubstr buf, fmt::raw_wrapper r)
read a variable in raw binary format, using memcpy
Definition: format.hpp:476
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:855
@ 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().