-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
47 lines (40 loc) · 1.44 KB
/
Utils.cpp
File metadata and controls
47 lines (40 loc) · 1.44 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
#include "Utils.h"
#include <algorithm>
#include <cctype>
#include <iostream>
namespace Utils {
std::string colorForLevel(LogLevel level) {
switch (level) {
case LogLevel::DEBUG: return DIM + CYAN;
case LogLevel::INFO: return GREEN;
case LogLevel::WARNING: return YELLOW;
case LogLevel::ERROR: return RED;
case LogLevel::CRITICAL: return BOLD + RED;
default: return RESET;
}
}
std::string toLower(const std::string& s) {
std::string result = s;
std::transform(result.begin(), result.end(), result.begin(), ::tolower);
return result;
}
std::string toUpper(const std::string& s) {
std::string result = s;
std::transform(result.begin(), result.end(), result.begin(), ::toupper);
return result;
}
std::string trim(const std::string& s) {
size_t start = s.find_first_not_of(" \t\r\n");
size_t end = s.find_last_not_of(" \t\r\n");
if (start == std::string::npos) return "";
return s.substr(start, end - start + 1);
}
bool containsIgnoreCase(const std::string& haystack, const std::string& needle) {
std::string h = toLower(haystack);
std::string n = toLower(needle);
return h.find(n) != std::string::npos;
}
void printSeparator(char ch, int width) {
std::cout << std::string(width, ch) << "\n";
}
}