Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <int N>
- struct s_str_sbuilder
- {
- static_assert(N > 0);
- int len = 0;
- int max_chars = N;
- char data[N + 1];
- char* cstr()
- {
- assert(len > 0);
- return data;
- }
- char* get_end_ptr()
- {
- return &data[len];
- }
- void append(char* format, ...)
- {
- char* where_to_write = &data[len];
- va_list args;
- va_start(args, format);
- int written = vsnprintf(where_to_write, max_chars + 1 - len, format, args);
- assert(written > 0 && written < max_chars);
- va_end(args);
- len += written;
- data[len] = 0;
- }
- void remove_last_char()
- {
- assert(len > 0);
- len -= 1;
- data[len] = 0;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement