-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathmenuutils.cpp
More file actions
45 lines (40 loc) · 1.04 KB
/
menuutils.cpp
File metadata and controls
45 lines (40 loc) · 1.04 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
#include "menuutils.h"
#include <locale>
#include <sstream>
template<typename Out>
void split(const std::string &s, char delim, Out result) {
std::stringstream ss;
ss.str(s);
std::string item;
while (std::getline(ss, item, delim)) {
*(result++) = item;
}
}
namespace NativeMenu {
unsigned numZeroes(unsigned number) {
unsigned digits = 0;
while (number % 10 == 0) {
if (number == 0) break;
number /= 10;
digits++;
}
return digits;
}
unsigned behindDec(float f) {
unsigned max = 6;
unsigned base = 1;
for (unsigned i = 0; i < max; i++) {
base *= 10;
}
int nums = (max)-numZeroes(unsigned(f*base));
return nums < 0 ? 1 : nums;
}
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
::split(s, delim, std::back_inserter(elems));
return elems;
}
float lerp(float a, float b, float f) {
return a + f * (b - a);
}
}