-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.hpp
46 lines (35 loc) · 1.4 KB
/
string.hpp
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
#ifndef _POLYWEB_STRING_HPP
#define _POLYWEB_STRING_HPP
#include "Polynet/string.hpp"
#include <string>
#include <vector>
namespace pw {
namespace string {
bool starts_with(pn::StringView str, pn::StringView beginning);
bool ends_with(pn::StringView str, pn::StringView ending);
void trim_right(std::string& str);
void trim_left(std::string& str);
void trim(std::string& str);
std::string trim_right_copy(std::string str);
std::string trim_left_copy(std::string str);
std::string trim_copy(std::string str);
void to_lower(std::string& str);
void to_upper(std::string& str);
std::string to_lower_copy(pn::StringView str);
std::string to_upper_copy(pn::StringView str);
bool iequals(pn::StringView a, pn::StringView b);
std::vector<std::string> split(pn::StringView str, char delimiter);
std::vector<std::string> split_and_trim(pn::StringView str, char delimiter);
struct CaseInsensitiveComparer {
bool operator()(pn::StringView a, pn::StringView b) const {
return string::iequals(a, b);
}
};
struct CaseInsensitiveHasher {
size_t operator()(pn::StringView str) const {
return std::hash<std::string>()(string::to_lower_copy(str));
}
};
} // namespace string
} // namespace pw
#endif