-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstr.h
More file actions
121 lines (80 loc) · 3.51 KB
/
str.h
File metadata and controls
121 lines (80 loc) · 3.51 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#pragma once
#include <string>
#include <vector>
#include <sstream>
namespace str {
std::wstring to_wstr(const std::string& str);
std::string to_str(const std::wstring& wstr);
int to_int(const std::string& str);
unsigned long to_ulong(const std::string& str, int radix = 10);
long long to_long_long(const std::string& str);
void ltrim(std::string& s, const std::string& chars = " \r\n\t");
void rtrim(std::string& s, const std::string& chars = " \r\n\t");
void trim(std::string& s, const std::string& chars = " \r\n\t");
void upper(std::string& s);
void lower(std::string& s);
void capitalize(std::string& s);
void unescape_special_chars(std::string& s);
void replace_all(std::string& s, const std::string& search, const std::string& replacement);
std::vector<std::string> split(const std::string& str, const std::string& delimiter, bool trim_lines = false, bool remove_empty_entries = false);
template<class ForwardIterator>
std::string join(ForwardIterator begin, ForwardIterator end, const std::string& separator) {
std::ostringstream ss;
size_t count{};
for (ForwardIterator it = begin; it != end; ++it, ++count) {
if (count != 0) ss << separator;
ss << *it;
}
return ss.str();
}
std::string to_human_readable_size(unsigned long size);
std::vector<std::string> match_all_regex(const std::string& expression, const std::string& input);
std::string get_domain_from_url(const std::string& url);
std::string humanise(int value, std::string singular, std::string plural = "", std::string once = "", std::string twice = "");
inline bool is_base64(unsigned char c);
std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_len);
std::string base64_encode(const std::string& input);
std::string base64_decode(std::string const& encoded_string);
std::string url_encode(const std::string& value);
std::string url_decode(const std::string& value);
#if WIN32
size_t word_count(const std::string& sentence);
#endif
std::string remove_non_ascii(const std::string& s);
std::string strip_html(const std::string& s);
std::string rgx_extract(const std::string& s, const std::string& expr);
std::vector<std::string> rgx_extract_to_vec(const std::string& s, const std::string& expr);
std::string deduplicate_lines(const std::string& s);
/**
* @brief Case insensitive compare
* @param haystack
* @param needle
* @return
*/
bool contains_ic(const std::string& haystack, const std::string& needle);
bool equal_ic(const std::string& s1, const std::string& s2);
/**
* @brief Escapes pipe character in the string with backslash and pipe.
* @param input
* @return
*/
std::string escape_pipe(const std::string& input);
/**
* @brief Unescapes backslash and pipe character in the string with just pipe.
* @param input
* @return
*/
std::string unescape_pipe(const std::string& input);
/**
* @brief Joins vector of strings with pipe character, taking into account that some strings may contain pipe character.
* @param parts
* @return
*/
std::string join_with_pipe(const std::vector<std::string>& parts);
/**
* @brief Split string by pipe character, taking into account that some strings may contain pipe character.
* @param line
* @return
*/
std::vector<std::string> split_pipe(const std::string& line);
}