forked from projectM-visualizer/projectm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
81 lines (71 loc) · 1.97 KB
/
Utils.cpp
File metadata and controls
81 lines (71 loc) · 1.97 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
#include "Utils.hpp"
#include <algorithm>
namespace libprojectM {
namespace Utils {
auto ToLower(const std::string& str) -> std::string
{
std::string lowerStr(str);
ToLowerInPlace(lowerStr);
return lowerStr;
}
auto ToUpper(const std::string& str) -> std::string
{
std::string upperStr(str);
ToUpperInPlace(upperStr);
return upperStr;
}
void ToLowerInPlace(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
}
void ToUpperInPlace(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), ::toupper);
}
auto StripComments(const std::string& source) -> std::string
{
std::string result = source;
size_t i = 0;
while (i < result.size())
{
if (i + 1 < result.size() && result.at(i) == '/' && result.at(i + 1) == '/')
{
// Line comment: replace until end of line
while (i < result.size() && result.at(i) != '\n' && result.at(i) != '\r')
{
result.at(i) = ' ';
i++;
}
}
else if (i + 1 < result.size() && result.at(i) == '/' && result.at(i + 1) == '*')
{
// Block comment: replace until closing */
result.at(i) = ' ';
result.at(i + 1) = ' ';
i += 2;
while (i < result.size())
{
if (i + 1 < result.size() && result.at(i) == '*' && result.at(i + 1) == '/')
{
result.at(i) = ' ';
result.at(i + 1) = ' ';
i += 2;
break;
}
// Preserve newlines to keep line structure intact
if (result.at(i) != '\n' && result.at(i) != '\r')
{
result.at(i) = ' ';
}
i++;
}
}
else
{
i++;
}
}
return result;
}
} // namespace Utils
} // namespace libprojectM