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>
11
class
SmallString
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
}
ed::SmallString
Definition:
utils.hpp:12
ed::SmallString::sprintf
static SmallString sprintf(const char *format, auto &&... args)
Definition:
utils.hpp:17
ed::SmallString::size
size_t size() const
Definition:
utils.hpp:27
ed::SmallString::c_str
const char * c_str() const
Definition:
utils.hpp:26
str_sprintf
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
ed
Definition:
compile.hpp:13
ed::strfmt
SmallString< N > strfmt(const char *format, auto &&... args)
Definition:
utils.hpp:31
str.h
frontend
gui
editor
include
editor
utils.hpp
Generated by
1.9.1