rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
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.

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

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 from_chars_first(csubstr buf, uint8_t *v) noexcept
basic_substring< char > substr
a mutable string view
Definition substr.hpp:2356
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 len
the length of the substring
Definition substr.hpp:218
basic_substring sub(size_t first) const noexcept
return [first,len[
Definition substr.hpp:503