philsupertramp/game-math
Loading...
Searching...
No Matches
format.h
Go to the documentation of this file.
1
8#pragma once
9#include <cstdarg>
10#include <regex>
11#include <sstream>
12#include <string>
13#include <vector>
14
22inline std::string format(const char* fmt, ...) {
23 int size = 512;
24 char* buffer = 0;
25 buffer = new char[size];
26 va_list vl;
27 va_start(vl, fmt);
28 int nsize = vsnprintf(buffer, size, fmt, vl);
29 std::string ret(buffer);
30 if(size <= nsize) { //fail delete buffer and try again
31 delete[] buffer;
32 buffer = 0;
33 buffer = new char[nsize - size + 2]; //+1 for /0
34 nsize = vsnprintf(buffer, (nsize - size) + 2, &fmt[size], vl);
35 ret += buffer;
36 }
37 va_end(vl);
38 delete[] buffer;
39 return ret;
40}
41
47std::string strip(const std::string& in);
48
60template<typename Out>
61void split(const std::string& s, char delim, Out result);
62
63
70std::vector<std::string> split(const std::string& s, char delim);
71
78template<typename Out>
79void split(const std::string& s, Out result);
80
81
87std::vector<std::string> split(const std::string& s);
88
89std::vector<std::string> split_by_regex(const std::string& s, const std::regex& regex);
90
void split(const std::string &s, char delim, Out result)
std::string format(const char *fmt,...)
Definition: format.h:22
std::vector< std::string > split_by_regex(const std::string &s, const std::regex &regex)
std::string strip(const std::string &in)