rapidyaml  0.16.0
parseandemitYAML,anddoitfast
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

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 987 of file format.hpp.

Referenced by from_chars(), and sample_formatting().

988 {
989  const size_t pos = fmt.find("{}");
990  if C4_UNLIKELY(pos == csubstr::npos)
991  return unformat(buf, fmt);
992  size_t num = pos;
993  size_t out = num;
994  buf = buf.len >= num ? buf.sub(num) : substr{};
995  num = from_chars_first(buf, &a);
996  if C4_UNLIKELY(num == csubstr::npos)
997  return csubstr::npos;
998  out += num;
999  buf = buf.len >= num ? buf.sub(num) : substr{};
1000  num = unformat(buf, fmt.sub(pos + 2), more...);
1001  if C4_UNLIKELY(num == csubstr::npos)
1002  return csubstr::npos;
1003  out += num;
1004  return out;
1005 }
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:987
size_t from_chars_first(csubstr buf, fmt::raw_wrapper r)
read a variable in raw binary format, using memcpy
Definition: format.hpp:478
basic_substring< char > substr
a mutable string view
Definition: substr.hpp:2355
a null string position
Definition: common.hpp:138
basic_substring< const char > csubstr
an immutable string view
Definition: substr.hpp:2356