-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
64 lines (44 loc) · 1.7 KB
/
utils.h
File metadata and controls
64 lines (44 loc) · 1.7 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
#ifndef UTILS_H
#define UTILS_H
#include <string>
#include <vector>
#include <cstdint>
#include <sstream>
#include <iomanip>
// Utility functions for string manipulation, IP validation, etc.
namespace utils {
// Check if string is a valid IPv4 address (RFC 791)
bool is_valid_ipv4(const std::string& ip);
// Check if IP is private (RFC 1918)
bool is_private_ip(const std::string& ip);
// Parse IP address string to 32-bit integer
uint32_t ip_to_uint32(const std::string& ip);
// Convert 32-bit integer to IP address string
std::string uint32_to_ip(uint32_t ip);
// Trim whitespace from string
std::string trim(const std::string& str);
// Split string by delimiter
std::vector<std::string> split(const std::string& str, char delimiter);
// Convert string to lowercase
std::string to_lower(const std::string& str);
// Format bytes to human-readable size
std::string format_bytes(uint64_t bytes);
// Safe string to number conversion
bool safe_str_to_uint16(const std::string& str, uint16_t& result);
bool safe_str_to_uint32(const std::string& str, uint32_t& result);
bool safe_str_to_uint64(const std::string& str, uint64_t& result);
bool safe_str_to_double(const std::string& str, double& result);
// Check if terminal is available (defensive terminal handling)
bool is_terminal();
// Safe output function (checks terminal state before writing)
void safe_print(const std::string& message);
// Flush output safely
void safe_flush();
// Create directory if it doesn't exist
bool create_directory(const std::string& path);
// Ensure log directory and file exist
bool ensure_log_file(const std::string& log_file_path);
// Check if file exists
bool file_exists(const std::string& path);
} // namespace utils
#endif // UTILS_H