SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
String.cc
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
7 #include "swcdb/core/Compat.h"
8 #include "swcdb/core/String.h"
9 
10 #include <cstdio>
11 #include <cstdarg>
12 
13 
14 namespace SWC {
15 
16 
17 std::string format(const char* fmt, ...) {
18  std::va_list ap1;
19  va_start(ap1, fmt);
20  std::string res;
21 
22  std::va_list ap2;
23  va_copy(ap2, ap1);
24 
25  res.resize(std::vsnprintf(nullptr, 0, fmt, ap1));
26  std::vsnprintf(res.data(), res.size() + 1, fmt, ap2);
27 
28  va_end(ap1);
29  va_end(ap2);
30  return res;
31 }
32 
33 SWC_PRAGMA_DIAGNOSTIC_PUSH
34 SWC_PRAGMA_DIAGNOSTIC_IGNORED("-Wformat-nonliteral")
35 std::string format_unsafe(const char* fmt, ...) {
36  std::va_list ap1;
37  va_start(ap1, fmt);
38  std::string res;
39 
40  std::va_list ap2;
41  va_copy(ap2, ap1);
42 
43  res.resize(std::vsnprintf(nullptr, 0, fmt, ap1));
44  std::vsnprintf(res.data(), res.size() + 1, fmt, ap2);
45 
46  va_end(ap1);
47  va_end(ap2);
48  return res;
49 }
50 SWC_PRAGMA_DIAGNOSTIC_POP
51 
52 
53 } // namespace SWC
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
Compat.h
SWC::SWC_PRAGMA_DIAGNOSTIC_IGNORED
SWC_PRAGMA_DIAGNOSTIC_PUSH SWC_PRAGMA_DIAGNOSTIC_IGNORED("-Wformat-nonliteral") std
Definition: String.cc:34
SWC::format
std::string format(const char *fmt,...) __attribute__((format(printf
Definition: String.cc:17
String.h