+
+ // Append characters to the buffer. Caller must make certain there
+ // is enough space to contain the characters first.
+ void append(const char * s, int len) noexcept
+ {
+ int index = cur_idx + length;
+ if (index >= SIZE) index -= SIZE;
+
+ length += len; // (before we destroy len)
+
+ int max = SIZE - index;
+ std::memcpy(buf + index, s, std::min(max, len));
+ if (len > max) {
+ // Wrapped around buffer: copy the rest
+ s += max;
+ len -= max;
+ std::memcpy(buf, s, len);
+ }
+ }