-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathData.hpp
More file actions
92 lines (87 loc) · 2 KB
/
Data.hpp
File metadata and controls
92 lines (87 loc) · 2 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
#pragma once
#include <map>
#include <string>
#include <vector>
#include "lSDK/UnicodeUtilities.hpp"
struct Data final
{
using list_t = std::vector<lSDK::string_t>;
using lists_t = std::map<lSDK::string_t, list_t, std::less<>>;
lists_t lists;
using global_t = std::map<lSDK::string_t, Data, std::less<>>;
static global_t global;
};
inline auto escape_item(lSDK::string_view_t item, lSDK::string_view_t const to, lSDK::string_view_t const esc)
{
lSDK::string_t temp;
while(!empty(item))
{
if(!empty(to) && item.substr(0, size(to)) == to)
{
temp.append(esc);
temp.append(to);
item.remove_prefix(size(to));
}
else if(!empty(esc) && item.substr(0, size(esc)) == esc)
{
temp.append(esc);
temp.append(esc);
item.remove_prefix(size(esc));
}
else
{
temp.append(item.substr(0, 1));
item.remove_prefix(1);
}
}
return temp;
}
inline auto combine_escaped(Data::list_t const &list, lSDK::string_view_t const delim, lSDK::string_view_t const esc)
-> lSDK::string_t
{
lSDK::string_t text;
for(std::size_t i = 0; i < size(list); ++i)
{
if(i != 0)
{
text.append(delim);
}
text.append(escape_item(list[i], delim, esc));
}
return text;
}
template<typename Callable>
constexpr void split_escaped(lSDK::string_view_t str, lSDK::string_view_t const delim, lSDK::string_view_t const esc, Callable &&item_handler)
{
lSDK::string_view_t temp = str;
while(!empty(str))
{
if(!empty(esc) && str.substr(0, size(esc)) == esc)
{
if(str.substr(size(esc), size(delim)) == delim)
{
str.remove_prefix(size(esc) + size(delim));
}
else if(str.substr(size(esc), size(esc)) == esc)
{
str.remove_prefix(size(esc)*2);
}
else
{
str.remove_prefix(size(esc));
}
}
else if(!empty(delim) && str.substr(0, size(delim)) == delim)
{
std::ptrdiff_t const len = data(str) - data(temp);
item_handler(temp.substr(0, static_cast<std::size_t>(len)));
str.remove_prefix(size(delim));
temp = str;
}
else
{
str.remove_prefix(1);
}
}
item_handler(temp);
}