rapidyaml  0.12.1
parse and emit YAML, and do it fast
catsep: cat arguments to string with separator

Functions

template<class Sep , class Arg , class... Args>
size_t c4::catsep (substr buf, Sep const &sep, Arg const &a, Args const &...more)
 serialize the arguments, concatenating them to the given fixed-size buffer, using a separator between each argument. More...
 
template<class... Args>
substr c4::catsep_sub (substr buf, Args &&...args)
 like c4::catsep() but return a substr instead of a size More...
 
template<class CharOwningContainer , class Sep , class... Args>
void c4::catseprs (CharOwningContainer *cont, Sep const &sep, Args const &...args)
 catsep+resize: like c4::catsep(), but receives a container, and resizes it as needed to contain the result. More...
 
template<class CharOwningContainer , class Sep , class... Args>
CharOwningContainer c4::catseprs (Sep const &sep, Args const &...args)
 catsep+resize: like c4::catsep(), but create a new container with the result. More...
 
template<class CharOwningContainer , class Sep , class... Args>
csubstr c4::catseprs_append (CharOwningContainer *cont, Sep const &sep, Args const &...args)
 catsep+resize+append: like catsep(), but receives a container, and appends the arguments, resizing the container as needed to contain the result. More...
 

Detailed Description

Function Documentation

◆ catsep()

template<class Sep , class Arg , class... Args>
size_t c4::catsep ( substr  buf,
Sep const &  sep,
Arg const &  a,
Args const &...  more 
)

serialize the arguments, concatenating them to the given fixed-size buffer, using a separator between each argument.

The buffer size is strictly respected: no writes will occur beyond its end.

Returns
the number of characters needed to write all the arguments into the buffer.
See also
c4::catseprs() if instead of a fixed-size buffer, a resizeable container is desired
c4::uncatsep() for the inverse function (ie, reading instead of writing)
c4::cat() if no separator is needed
c4::format() if a format string is desired

Definition at line 727 of file format.hpp.

728 {
729  size_t num = to_chars(buf, a);
730  buf = buf.len >= num ? buf.sub(num) : substr{};
731  num += detail::catsep_more(buf, sep, more...);
732  return num;
733 }
size_t to_chars(substr buf, fmt::right_< T > const &align)
Definition: format.hpp:558

References c4::to_chars().

◆ catsep_sub()

template<class... Args>
substr c4::catsep_sub ( substr  buf,
Args &&...  args 
)

like c4::catsep() but return a substr instead of a size

See also
c4::catsep(). c4::uncatsep() is the inverse of c4::catsep().

Definition at line 738 of file format.hpp.

739 {
740  size_t sz = catsep(buf, std::forward<Args>(args)...);
741  C4_CHECK(sz <= buf.len);
742  return {buf.str, sz <= buf.len ? sz : buf.len};
743 }
size_t catsep(substr buf, Sep const &sep, Arg const &a, Args const &...more)
serialize the arguments, concatenating them to the given fixed-size buffer, using a separator between...
Definition: format.hpp:727

References c4::catsep().

◆ catseprs() [1/2]

template<class CharOwningContainer , class Sep , class... Args>
void c4::catseprs ( CharOwningContainer *  cont,
Sep const &  sep,
Args const &...  args 
)
inline

catsep+resize: like c4::catsep(), but receives a container, and resizes it as needed to contain the result.

The container is overwritten. To append to the container use the append overload.

See also
c4::catsep()

Definition at line 951 of file format.hpp.

952 {
953 retry:
954  substr buf = to_substr(*cont);
955  size_t ret = catsep(buf, sep, args...);
956  cont->resize(ret);
957  if(ret > buf.len)
958  goto retry;
959 }
substr to_substr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2208

References c4::catsep(), and c4::to_substr().

◆ catseprs() [2/2]

template<class CharOwningContainer , class Sep , class... Args>
CharOwningContainer c4::catseprs ( Sep const &  sep,
Args const &...  args 
)
inline

catsep+resize: like c4::catsep(), but create a new container with the result.

Returns
the requested container

Definition at line 967 of file format.hpp.

968 {
969  CharOwningContainer cont;
970  catseprs(&cont, sep, args...);
971  return cont;
972 }
CharOwningContainer catseprs(Sep const &sep, Args const &...args)
catsep+resize: like c4::catsep(), but create a new container with the result.
Definition: format.hpp:967

References c4::catseprs().

◆ catseprs_append()

template<class CharOwningContainer , class Sep , class... Args>
csubstr c4::catseprs_append ( CharOwningContainer *  cont,
Sep const &  sep,
Args const &...  args 
)
inline

catsep+resize+append: like catsep(), but receives a container, and appends the arguments, resizing the container as needed to contain the result.

The buffer is appended to.

Returns
a csubstr of the appended part

Definition at line 982 of file format.hpp.

983 {
984  const size_t pos = cont->size();
985 retry:
986  substr buf = to_substr(*cont).sub(pos);
987  size_t ret = catsep(buf, sep, args...);
988  cont->resize(pos + ret);
989  if(ret > buf.len)
990  goto retry;
991  return to_csubstr(*cont).range(pos, cont->size());
992 }
csubstr to_csubstr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2210

References c4::catsep(), c4::to_csubstr(), and c4::to_substr().