rapidyaml  0.13.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.

This is the inverse function to c4::format().

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

Definition at line 991 of file format.hpp.

992 {
993  const size_t pos = fmt.find("{}");
994  if(C4_UNLIKELY(pos == csubstr::npos))
995  return unformat(buf, fmt);
996  size_t num = pos;
997  size_t out = num;
998  buf = buf.len >= num ? buf.sub(num) : substr{};
999  num = from_chars_first(buf, &a);
1000  if(C4_UNLIKELY(num == csubstr::npos))
1001  return csubstr::npos;
1002  out += num;
1003  buf = buf.len >= num ? buf.sub(num) : substr{};
1004  num = unformat(buf, fmt.sub(pos + 2), more...);
1005  if(C4_UNLIKELY(num == csubstr::npos))
1006  return csubstr::npos;
1007  out += num;
1008  return out;
1009 }
size_t from_chars_first(csubstr buf, fmt::raw_wrapper r)
read a variable in raw binary format, using memcpy
Definition: format.hpp:482
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:991
@ npos
a null string position
Definition: common.hpp:258