philsupertramp/game-math
Loading...
Searching...
No Matches
include
math
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
22
inline
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
47
std::string
strip
(
const
std::string&
in
);
48
60
template
<
typename
Out>
61
void
split
(
const
std::string&
s
,
char
delim
,
Out
result
);
62
63
70
std::vector<std::string>
split
(
const
std::string&
s
,
char
delim
);
71
78
template
<
typename
Out>
79
void
split
(
const
std::string&
s
,
Out
result
);
80
81
87
std::vector<std::string>
split
(
const
std::string&
s
);
88
89
std::vector<std::string>
split_by_regex
(
const
std::string&
s
,
const
std::regex&
regex
);
90
Matrix
Definition
Matrix.h:42
split
void split(const std::string &s, char delim, Out result)
format
std::string format(const char *fmt,...)
Definition
format.h:22
split_by_regex
std::vector< std::string > split_by_regex(const std::string &s, const std::regex ®ex)
strip
std::string strip(const std::string &in)
Generated by
1.9.8