Function unformat

Synopsis

#include <src/c4/format.hpp>

template <class Arg, class... Args>
size_t unformat(csubstr buf, csubstr fmt, Arg &C4_RESTRICT a, Args &C4_RESTRICT ...more)

Description

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
c4::format(). c4::unformat() is the inverse function to format().

Mentioned in

Source

Lines 664-683 in src/c4/format.hpp.

template<class Arg, class... Args>
size_t unformat(csubstr buf, csubstr fmt, Arg & C4_RESTRICT a, Args & C4_RESTRICT ...more)
{
    size_t pos = fmt.find("{}");
    if(C4_UNLIKELY(pos == csubstr::npos))
    {
        return unformat(buf, fmt);
    }
    size_t num = pos;
    size_t out = num;
    buf  = buf.len >= num ? buf.sub(num) : substr{};
    num  = from_chars_first(buf, &a);
    if(C4_UNLIKELY(num == csubstr::npos)) return csubstr::npos;
    out += num;
    buf  = buf.len >= num ? buf.sub(num) : substr{};
    num  = unformat(buf, fmt.sub(pos + 2), more...);
    if(C4_UNLIKELY(num == csubstr::npos)) return csubstr::npos;
    out += num;
    return out;
}





Add Discussion as Guest

Log in