rapidyaml  0.13.0
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 c4::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
Note
The arguments to format are restricted (legal because they are rvalues). This may require a workaround when arguments of type char[]/const char[] are passed repeatedly to the function. For example,
const char str[] = "Hi! ";
cat(buf, str, str, str); // compile error: 'passing argument 2 to ‘restrict’-qualified parameter aliases with arguments 3, 4'
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:653
It is possible to work around the problem by suppressing -Wrestrict or by using the decayed type char* or const char*, or even wrapping the argument in a csubstr():
const char str[] = "Hi! ";
csubstr ss = to_csubstr(str);
cat(buf, ss, ss, ss); // ok! compiles cleanly
csubstr to_csubstr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2204

Definition at line 778 of file format.hpp.

779 {
780  size_t num = to_chars(buf, a);
781  buf = buf.len >= num ? buf.sub(num) : substr{};
782  num += detail::catsep_more(buf, sep, more...);
783  return num;
784 }
size_t to_chars(substr buf, fmt::center_< T > const &align)
Definition: format.hpp:596

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

791 {
792  size_t sz = catsep(buf, std::forward<Args>(args)...);
793  C4_CHECK(sz <= buf.len);
794  return {buf.str, sz <= buf.len ? sz : buf.len};
795 }
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:778

◆ 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 c4::catseprs_append().

See also
c4::catsep()
c4::catseprs_append()
Note
The arguments to format are restricted (legal because they are rvalues). This may require a workaround when arguments of type char[]/const char[] are passed repeatedly to the function. For example,
const char str[] = "Hi! ";
cat(buf, str, str, str); // compile error: 'passing argument 2 to ‘restrict’-qualified parameter aliases with arguments 3, 4'
It is possible to work around the problem by suppressing -Wrestrict or by using the decayed type char* or const char*, or even wrapping the argument in a csubstr():
const char str[] = "Hi! ";
csubstr ss = to_csubstr(str);
cat(buf, ss, ss, ss); // ok! compiles cleanly

Definition at line 1156 of file format.hpp.

1157 {
1158  cont->resize(cont->capacity()); // improve the odds of fitting in the original buffer
1159 retry:
1160  substr buf = to_substr(*cont);
1161  size_t ret = catsep(buf, sep, args...);
1162  cont->resize(ret);
1163  if(ret > buf.len)
1164  goto retry;
1165 }
substr to_substr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2202

◆ 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
Note
The arguments to format are restricted (legal because they are rvalues). This may require a workaround when arguments of type char[]/const char[] are passed repeatedly to the function. For example,
const char str[] = "Hi! ";
cat(buf, str, str, str); // compile error: 'passing argument 2 to ‘restrict’-qualified parameter aliases with arguments 3, 4'
It is possible to work around the problem by suppressing -Wrestrict or by using the decayed type char* or const char*, or even wrapping the argument in a csubstr():
const char str[] = "Hi! ";
csubstr ss = to_csubstr(str);
cat(buf, ss, ss, ss); // ok! compiles cleanly

Definition at line 1191 of file format.hpp.

1192 {
1193  CharOwningContainer cont;
1194  catseprs(&cont, sep, args...);
1195  return cont;
1196 }
CharOwningContainer catseprs(Sep const &sep, Args const &...args)
catsep+resize: like c4::catsep(), but create a new container with the result.
Definition: format.hpp:1191

◆ 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 c4::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
Note
The arguments to format are restricted (legal because they are rvalues). This may require a workaround when arguments of type char[]/const char[] are passed repeatedly to the function. For example,
const char str[] = "Hi! ";
cat(buf, str, str, str); // compile error: 'passing argument 2 to ‘restrict’-qualified parameter aliases with arguments 3, 4'
It is possible to work around the problem by suppressing -Wrestrict or by using the decayed type char* or const char*, or even wrapping the argument in a csubstr():
const char str[] = "Hi! ";
csubstr ss = to_csubstr(str);
cat(buf, ss, ss, ss); // ok! compiles cleanly

Definition at line 1224 of file format.hpp.

1225 {
1226  const size_t pos = cont->size();
1227  cont->resize(cont->capacity()); // improve the odds of fitting in the original buffer
1228 retry:
1229  substr buf = to_substr(*cont).sub(pos);
1230  size_t ret = catsep(buf, sep, args...);
1231  cont->resize(pos + ret);
1232  if(ret > buf.len)
1233  goto retry;
1234  return to_csubstr(*cont).range(pos, cont->size());
1235 }