-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties.ms
More file actions
120 lines (100 loc) · 3.4 KB
/
properties.ms
File metadata and controls
120 lines (100 loc) · 3.4 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
proc _util_properties_init_self() {
@self = array()
# field @private_count - счетчик добавление аргументов, необходим для сортировки
# field @private_store - карта аргументов
# field @private_link - карта связки ключей и их значения @private_count
@self['private_count'] = 0
@self['private_store'] = array()
@self['private_link'] = array()
return(@self)
}
proc _private_util_properties_add_link(@self, @key) {
@self['private_link'][@key] = @self['private_count']
@self['private_count']++
}
proc _util_properties_get_string(@self, @key) {
return(@self['private_store'][@key])
}
proc _util_properties_get_array(@self, @key) {
return(array_get(@self['private_store'][@key]))
}
proc _util_properties_get_int(@self, @key) {
return(integer(@self['private_store'][@key]))
}
proc _util_properties_get_bool(@self, @key) {
return(boolean((@self['private_store'][@key])))
}
proc _util_properties_push(@self, @key, @value) {
_private_util_properties_add_link(@self, @key)
@self['private_store'][@key] = @value
}
proc _util_properties_add_all(@self, @map) {
foreach(@key: @value in @map) {
_properties_pull(@self, @key, @value)
}
}
proc _util_properties_contains(@self, @key) {
return(array_index_exists(@self['private_store'], @key))
}
proc _util_properties_key_set(@self) {
return(array_keys(@self['private_store']))
}
proc _util_properties_values(@self) {
@values = array()
array_push_all(@values, @self['private_store'])
return(@values)
}
proc _util_properties_to_map(@self) {
return(@self['private_store'][])
}
proc _util_properties_remove_all(@self, @key_set) {
foreach(@key in @key_set) {
_properties_remove(@self, @key)
}
}
proc _util_properties_remove(@self, @key) {
@temp = @self['private_store'][@key]
array_remove(@self['private_store'], @key)
array_remove(@self['private_link'], @key)
return(@temp)
}
proc _util_properties_clear(@self, @key) {
@self['private_count'] = 0
@self['private_store'] = array()
@self['private_link'] = array()
}
proc _util_properties_is_empty(@self) {
return(array_size(array_keys(@self['private_store'])) == 0)
}
proc _util_properties_parse_string(@self, @text) {
@entries = split("\n", @text)
for(@i = 0, @i < array_size(@entries), @i++) {
if (trim(@entries[@i]) == "", continue())
if (@entries[@i][0] == '#', continue())
@key_value = reg_split("[=]", @entries[@i])
if (array_size(@key_value) != 2) {
throw(IOException, "Syntax error at: ".@i);
}
@key = @key_value[0]
@value = @key_value[1]
_util_properties_push(@self, @key, @value)
}
}
proc _util_properties_to_string(@self) {
if (_util_properties_is_empty(@self), return(""))
@builder = res_create_resource('STRING_BUILDER')
@store = array()
foreach(@key: @value in @self['private_store']) {
@store[] = array(@key, @value, @self['private_link'][@key])
}
array_sort(@store, closure(@left, @right){
return(@left[2] > @right[2]);
});
@size = array_size(@store)
for(@i = 0, @i < @size - 1, @i++) {
string_append(@builder, @store[@i][0], '=', @store[@i][1], '\n')
}
string_append(@builder, @store[-1][0], '=', @store[-1][1])
string_append(@builder, '\n')
return(string(@builder))
}