Cthulhu  0.2.10
Cthulhu compiler collection
utils.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-3.0-only
2 #pragma once
3 
4 #include "std/str.h"
5 
6 #include <stdint.h>
7 
8 namespace ed
9 {
10  template<size_t N>
12  {
13  char buffer[N];
14  size_t length;
15 
16  public:
17  static SmallString sprintf(const char *format, auto&&... args)
18  {
19  SmallString<N> result;
20  result.length = str_sprintf(result.buffer, N, format, args...);
21  return result;
22  }
23 
24  operator const char *() const { return buffer; }
25 
26  const char *c_str() const { return buffer; }
27  size_t size() const { return length; }
28  };
29 
30  template<size_t N>
31  SmallString<N> strfmt(const char *format, auto&&... args)
32  {
33  return SmallString<N>::sprintf(format, args...);
34  }
35 }
static SmallString sprintf(const char *format, auto &&... args)
Definition: utils.hpp:17
size_t size() const
Definition: utils.hpp:27
const char * c_str() const
Definition: utils.hpp:26
CT_STD_API size_t str_sprintf(STA_WRITES(len) char *str, size_t len, STA_FORMAT_STRING const char *fmt,...)
format a string with printf-like syntax
Definition: compile.hpp:13
SmallString< N > strfmt(const char *format, auto &&... args)
Definition: utils.hpp:31