rapidyaml  0.12.0
parse and emit YAML, and do it fast
cat: concatenate arguments to string

Functions

template<class Arg , class... Args>
size_t c4::cat (substr buf, Arg const &a, Args const &...more)
 serialize the arguments, concatenating them to the given fixed-size buffer. More...
 
template<class... Args>
substr c4::cat_sub (substr buf, Args &&...args)
 like c4::cat() but return a substr instead of a size More...
 
template<class CharOwningContainer , class... Args>
void c4::catrs (CharOwningContainer *cont, Args const &...args)
 cat+resize: like c4::cat(), but receives a container, and resizes it as needed to contain the result. More...
 
template<class CharOwningContainer , class... Args>
CharOwningContainer c4::catrs (Args const &...args)
 cat+resize: like c4::cat(), but creates and returns a new container sized as needed to contain the result. More...
 
template<class CharOwningContainer , class... Args>
csubstr c4::catrs_append (CharOwningContainer *cont, Args const &...args)
 cat+resize+append: like c4::cat(), but receives a container, and appends to it instead of overwriting it. More...
 

Detailed Description

Function Documentation

◆ cat()

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

serialize the arguments, concatenating them to the given fixed-size buffer.

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::catrs() if instead of a fixed-size buffer, a resizeable container is desired
c4::uncat() for the inverse function
c4::catsep() if a separator between each argument is to be used
c4::format() if a format string is desired

Definition at line 594 of file format.hpp.

595 {
596  size_t num = to_chars(buf, a);
597  buf = buf.len >= num ? buf.sub(num) : substr{};
598  num += cat(buf, more...);
599  return num;
600 }
size_t cat(substr buf, Arg const &a, Args const &...more)
serialize the arguments, concatenating them to the given fixed-size buffer.
Definition: format.hpp:594
size_t to_chars(substr buf, fmt::right_< T > const &align)
Definition: format.hpp:558

References c4::to_chars().

◆ cat_sub()

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

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

Definition at line 604 of file format.hpp.

605 {
606  size_t sz = cat(buf, std::forward<Args>(args)...);
607  C4_CHECK(sz <= buf.len);
608  return {buf.str, sz <= buf.len ? sz : buf.len};
609 }

References c4::cat().

◆ catrs() [1/2]

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

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

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

See also
c4::cat()

Definition at line 898 of file format.hpp.

899 {
900 retry:
901  substr buf = to_substr(*cont);
902  size_t ret = cat(buf, args...);
903  cont->resize(ret);
904  if(ret > buf.len)
905  goto retry;
906 }
substr to_substr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2208

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

◆ catrs() [2/2]

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

cat+resize: like c4::cat(), but creates and returns a new container sized as needed to contain the result.

See also
c4::cat()

Definition at line 913 of file format.hpp.

914 {
915  CharOwningContainer cont;
916  catrs(&cont, args...);
917  return cont;
918 }
CharOwningContainer catrs(Args const &...args)
cat+resize: like c4::cat(), but creates and returns a new container sized as needed to contain the re...
Definition: format.hpp:913

References c4::catrs().

◆ catrs_append()

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

cat+resize+append: like c4::cat(), but receives a container, and appends to it instead of overwriting it.

The container is resized as needed to contain the result.

Returns
the region newly appended to the original container
See also
c4::cat()
c4::catrs()

Definition at line 929 of file format.hpp.

930 {
931  const size_t pos = cont->size();
932 retry:
933  substr buf = to_substr(*cont).sub(pos);
934  size_t ret = cat(buf, args...);
935  cont->resize(pos + ret);
936  if(ret > buf.len)
937  goto retry;
938  return to_csubstr(*cont).range(pos, cont->size());
939 }
csubstr to_csubstr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2210

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