-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathStringify.cpp
More file actions
97 lines (68 loc) · 2.21 KB
/
Stringify.cpp
File metadata and controls
97 lines (68 loc) · 2.21 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//==============================================================================
#include "Stringify.h"
//==============================================================================
std::string Stringify::Int(int x) {
std::ostringstream o;
o << x;
return o.str();
}
//------------------------------------------------------------------------------
std::string Stringify::Char(char* x) {
std::string o = x;
return o;
}
//------------------------------------------------------------------------------
std::string Stringify::Float(float x) {
std::ostringstream o;
o << x;
return o.str();
}
//------------------------------------------------------------------------------
std::string Stringify::Double(double x) {
std::ostringstream o;
o << x;
return o.str();
}
//==============================================================================
int Stringify::ToInt(const std::string& String) {
if(String == "") return 0;
int X;
std::stringstream strStream(String);
strStream >> X;
return X;
}
//------------------------------------------------------------------------------
float Stringify::ToFloat(const std::string& String) {
if(String == "") return 0;
float X;
std::stringstream strStream(String);
strStream >> X;
return X;
}
//------------------------------------------------------------------------------
double Stringify::ToDouble(const std::string& String) {
if(String == "") return 0;
double X;
std::stringstream strStream(String);
strStream >> X;
return X;
}
//==============================================================================
//http://www.infernodevelopment.com/perfect-c-string-explode-split
std::vector<std::string> Stringify::Explode(std::string str, const std::string& separator) {
std::vector<std::string> Results;
int found;
found = str.find_first_of(separator);
while(found != std::string::npos){
if(found > 0){
Results.push_back(str.substr(0,found));
}
str = str.substr(found+1);
found = str.find_first_of(separator);
}
if(str.length() > 0){
Results.push_back(str);
}
return Results;
}
//==============================================================================