-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringFormat.h
More file actions
44 lines (37 loc) · 1.09 KB
/
StringFormat.h
File metadata and controls
44 lines (37 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include "build_config.h"
#include <string>
#include <cstdarg>
namespace StringUtils
{
COMMON_API std::string vprintf( const char *format, std::va_list args );
#ifdef __GNUC__
__attribute__((format(printf,1,2)))
#endif
inline std::string printf( const char *format, ... )
{
std::va_list list;
va_start( list, format );
std::string res = vprintf( format, list );
va_end( list );
return std::move(res);
}
COMMON_API bool vsnprintf( char *buffer, size_t bufSize, const char *format, std::va_list args );
inline bool snprintf( char *buffer, size_t bufSize, const char *format, ... )
{
std::va_list list;
va_start( list, format );
bool res = vsnprintf( buffer, bufSize, format, list );
va_end( list );
return res;
}
template< int N >
inline bool sprintf( char (&buffer)[N], const char *format, ... )
{
std::va_list list;
va_start( list, format );
bool res = vsnprintf( buffer, N, format, list );
va_end( list );
return res;
}
}