ucl 0.1.2 → 0.1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/ucl.c +91 -83
- data/ucl.gemspec +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a2fae349a8cdd822fbe00b6aa665cbdb04116e0c3dd9d6f7e21cd60d9420b07
|
4
|
+
data.tar.gz: b61d92056c4d69c0be28e3a4515fbb187a5e10a522ae181c38a6c00b51f28d21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6bbdf996a6be09f56dc12d1709f35b8e0f13a22ff1f0581af11c526b74b82eca11ac352989bd2414691a86ce4025e0caffcd0f196b200a5dcff650c8fc55d61
|
7
|
+
data.tar.gz: ae3d58daa278a8f97f055ec47dbd2f874d3cd953bda701217d5b09999411a2617bcb340f9c826ca2db742bf4ed3999ebee55b0794485f40c452ff6acda2aa2fd
|
data/ext/ucl.c
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#include <stdbool.h>
|
6
6
|
|
7
7
|
/* Fake flag */
|
8
|
-
#define UCL_PARSER_KEY_SYMBOL (1 <<
|
8
|
+
#define UCL_PARSER_KEY_SYMBOL (1 << 12)
|
9
9
|
|
10
10
|
|
11
11
|
/**
|
@@ -25,87 +25,83 @@
|
|
25
25
|
static VALUE mUCL = Qundef;
|
26
26
|
static VALUE eUCLError = Qundef;
|
27
27
|
|
28
|
-
static int
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
static int ucl_allowed_c_flags = UCL_PARSER_KEY_LOWERCASE |
|
29
|
+
UCL_PARSER_NO_TIME |
|
30
|
+
UCL_PARSER_DISABLE_MACRO |
|
31
|
+
UCL_PARSER_NO_FILEVARS ;
|
32
|
+
|
32
33
|
|
33
34
|
|
34
35
|
VALUE
|
35
|
-
_iterate_valid_ucl(ucl_object_t const *root, int flags)
|
36
|
+
_iterate_valid_ucl(ucl_object_t const *root, int flags, bool *failed)
|
36
37
|
{
|
37
|
-
|
38
|
-
|
39
|
-
const ucl_object_t *cur;
|
40
|
-
ucl_object_iter_t it_obj = NULL;
|
38
|
+
ucl_object_iter_t it = ucl_object_iterate_new(NULL);
|
39
|
+
const ucl_object_t *obj = NULL;
|
41
40
|
|
42
|
-
VALUE
|
43
|
-
|
44
|
-
while ((obj = ucl_object_iterate (root, &it, false))) {
|
45
|
-
VALUE val;
|
46
|
-
|
47
|
-
switch (obj->type) {
|
48
|
-
case UCL_INT:
|
49
|
-
val = rb_ll2inum((long long)ucl_object_toint(obj));
|
50
|
-
break;
|
51
|
-
|
52
|
-
case UCL_FLOAT:
|
53
|
-
val = rb_float_new(ucl_object_todouble(obj));
|
54
|
-
break;
|
55
|
-
|
56
|
-
case UCL_STRING:
|
57
|
-
val = rb_str_new_cstr(ucl_object_tostring(obj));
|
58
|
-
break;
|
59
|
-
|
60
|
-
case UCL_BOOLEAN:
|
61
|
-
val = ucl_object_toboolean(obj) ? Qtrue : Qfalse;
|
62
|
-
break;
|
63
|
-
|
64
|
-
case UCL_TIME:
|
65
|
-
val = rb_float_new(ucl_object_todouble(obj));
|
66
|
-
break;
|
67
|
-
|
68
|
-
case UCL_OBJECT:
|
69
|
-
it_obj = NULL;
|
70
|
-
val = rb_hash_new();
|
71
|
-
while ((cur = ucl_object_iterate(obj, &it_obj, true))) {
|
72
|
-
const char *obj_key = ucl_object_key(cur);
|
73
|
-
VALUE key = (flags & UCL_PARSER_KEY_SYMBOL)
|
74
|
-
? rb_id2sym(rb_intern(obj_key))
|
75
|
-
: rb_str_new_cstr(obj_key);
|
76
|
-
rb_hash_aset(val, key, _iterate_valid_ucl(cur, flags));
|
77
|
-
}
|
78
|
-
break;
|
79
|
-
|
80
|
-
case UCL_ARRAY:
|
81
|
-
it_obj = NULL;
|
82
|
-
val = rb_ary_new();
|
83
|
-
while ((cur = ucl_object_iterate (obj, &it_obj, true))) {
|
84
|
-
rb_ary_push(val, _iterate_valid_ucl(cur, flags));
|
85
|
-
}
|
86
|
-
break;
|
87
|
-
|
88
|
-
case UCL_USERDATA:
|
89
|
-
val = rb_str_new(obj->value.sv, obj->len);
|
90
|
-
break;
|
91
|
-
|
92
|
-
case UCL_NULL:
|
93
|
-
val = Qnil;
|
94
|
-
break;
|
95
|
-
|
96
|
-
default:
|
97
|
-
rb_bug("unhandled type (%d)", obj->type);
|
98
|
-
|
99
|
-
}
|
100
|
-
rb_ary_push(lst, val);
|
41
|
+
VALUE val;
|
101
42
|
|
43
|
+
switch (root->type) {
|
44
|
+
case UCL_INT:
|
45
|
+
val = rb_ll2inum((long long)ucl_object_toint(root));
|
46
|
+
break;
|
47
|
+
|
48
|
+
case UCL_FLOAT:
|
49
|
+
val = rb_float_new(ucl_object_todouble(root));
|
50
|
+
break;
|
51
|
+
|
52
|
+
case UCL_STRING: {
|
53
|
+
size_t len;
|
54
|
+
const char *str = ucl_object_tolstring(root, &len);
|
55
|
+
val = rb_str_new(str, len);
|
56
|
+
break;
|
102
57
|
}
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
58
|
+
|
59
|
+
case UCL_BOOLEAN:
|
60
|
+
val = ucl_object_toboolean(root) ? Qtrue : Qfalse;
|
61
|
+
break;
|
62
|
+
|
63
|
+
case UCL_TIME:
|
64
|
+
val = rb_float_new(ucl_object_todouble(root));
|
65
|
+
break;
|
66
|
+
|
67
|
+
case UCL_OBJECT:
|
68
|
+
val = rb_hash_new();
|
69
|
+
it = ucl_object_iterate_reset(it, root);
|
70
|
+
while ((obj = ucl_object_iterate_safe(it, !true))) {
|
71
|
+
size_t keylen;
|
72
|
+
const char *key = ucl_object_keyl(obj, &keylen);
|
73
|
+
VALUE v_key = rb_str_new(key, keylen);
|
74
|
+
if (flags & UCL_PARSER_KEY_SYMBOL)
|
75
|
+
v_key = rb_to_symbol(v_key);
|
76
|
+
rb_hash_aset(val, v_key, _iterate_valid_ucl(obj, flags, failed));
|
77
|
+
}
|
78
|
+
*failed = ucl_object_iter_chk_excpn(it);
|
79
|
+
break;
|
80
|
+
|
81
|
+
case UCL_ARRAY:
|
82
|
+
val = rb_ary_new();
|
83
|
+
it = ucl_object_iterate_reset(it, root);
|
84
|
+
while ((obj = ucl_object_iterate_safe(it, !true))) {
|
85
|
+
rb_ary_push(val, _iterate_valid_ucl(obj, flags, failed));
|
86
|
+
}
|
87
|
+
*failed = ucl_object_iter_chk_excpn(it);
|
88
|
+
break;
|
89
|
+
|
90
|
+
case UCL_USERDATA:
|
91
|
+
val = rb_str_new(root->value.sv, root->len);
|
92
|
+
break;
|
93
|
+
|
94
|
+
case UCL_NULL:
|
95
|
+
val = Qnil;
|
96
|
+
break;
|
97
|
+
|
98
|
+
default:
|
99
|
+
rb_bug("unhandled type (%d)", root->type);
|
100
|
+
|
108
101
|
}
|
102
|
+
|
103
|
+
ucl_object_iterate_free(it);
|
104
|
+
return val;
|
109
105
|
}
|
110
106
|
|
111
107
|
static VALUE
|
@@ -142,7 +138,7 @@ ucl_s_parse(int argc, VALUE *argv, VALUE klass)
|
|
142
138
|
rb_check_type(data, T_STRING);
|
143
139
|
rb_check_type(flags, T_FIXNUM);
|
144
140
|
|
145
|
-
int c_flags = FIX2INT(flags) &
|
141
|
+
int c_flags = FIX2INT(flags) & ucl_allowed_c_flags;
|
146
142
|
|
147
143
|
struct ucl_parser *parser =
|
148
144
|
ucl_parser_new(c_flags | UCL_PARSER_NO_IMPLICIT_ARRAYS);
|
@@ -157,12 +153,17 @@ ucl_s_parse(int argc, VALUE *argv, VALUE klass)
|
|
157
153
|
rb_raise(eUCLError, "%s", errormsg);
|
158
154
|
}
|
159
155
|
|
160
|
-
|
161
|
-
|
156
|
+
bool failed = false;
|
157
|
+
ucl_object_t *root = ucl_parser_get_object(parser);
|
158
|
+
VALUE res = _iterate_valid_ucl(root, FIX2INT(flags), &failed);
|
162
159
|
|
163
160
|
if (parser != NULL) { ucl_parser_free(parser); }
|
164
161
|
if (root != NULL) { ucl_object_unref(root); }
|
165
|
-
|
162
|
+
|
163
|
+
if (failed) {
|
164
|
+
rb_raise(eUCLError, "failed to iterate over ucl object");
|
165
|
+
}
|
166
|
+
|
166
167
|
return res;
|
167
168
|
}
|
168
169
|
|
@@ -188,25 +189,32 @@ ucl_s_load_file(int argc, VALUE *argv, VALUE klass)
|
|
188
189
|
rb_check_type(file, T_STRING);
|
189
190
|
rb_check_type(flags, T_FIXNUM);
|
190
191
|
|
191
|
-
int c_flags = FIX2INT(flags) &
|
192
|
+
int c_flags = FIX2INT(flags) & ucl_allowed_c_flags;
|
192
193
|
char *c_file = StringValueCStr(file);
|
193
|
-
|
194
|
+
|
194
195
|
struct ucl_parser *parser =
|
195
196
|
ucl_parser_new(c_flags | UCL_PARSER_NO_IMPLICIT_ARRAYS);
|
197
|
+
|
196
198
|
ucl_parser_add_file(parser, c_file);
|
197
|
-
|
199
|
+
ucl_parser_set_filevars(parser, c_file, false);
|
200
|
+
|
198
201
|
if (ucl_parser_get_error(parser)) {
|
199
202
|
const char *errormsg = ucl_parser_get_error(parser);
|
200
203
|
if (parser != NULL) { ucl_parser_free(parser); }
|
201
204
|
rb_raise(eUCLError, "%s", errormsg);
|
202
205
|
}
|
203
206
|
|
204
|
-
|
205
|
-
|
207
|
+
bool failed = false;
|
208
|
+
ucl_object_t *root = ucl_parser_get_object(parser);
|
209
|
+
VALUE res = _iterate_valid_ucl(root, FIX2INT(flags), &failed);
|
206
210
|
|
207
211
|
if (parser != NULL) { ucl_parser_free(parser); }
|
208
212
|
if (root != NULL) { ucl_object_unref(root); }
|
209
213
|
|
214
|
+
if (failed) {
|
215
|
+
rb_raise(eUCLError, "failed to iterate over ucl object");
|
216
|
+
}
|
217
|
+
|
210
218
|
return res;
|
211
219
|
}
|
212
220
|
|
data/ucl.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'ucl'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.3.1'
|
4
4
|
s.summary = " Universal configuration library parser"
|
5
5
|
s.description = <<~EOF
|
6
6
|
|
@@ -11,9 +11,9 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = 'https://github.com/sdalu/ruby-ucl'
|
12
12
|
s.license = 'MIT'
|
13
13
|
|
14
|
-
s.authors = [ "Stéphane D'Alu"
|
14
|
+
s.authors = [ "Stéphane D'Alu" ]
|
15
15
|
s.email = [ 'sdalu@sdalu.com' ]
|
16
16
|
|
17
|
-
s.extensions
|
18
|
-
s.files
|
17
|
+
s.extensions = [ 'ext/extconf.rb' ]
|
18
|
+
s.files = %w[ ucl.gemspec ] + Dir['ext/**/*.{c,h,rb}']
|
19
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ucl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stéphane D'Alu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2+
|
14
14
|
|
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
|
-
rubygems_version: 3.3.
|
46
|
+
rubygems_version: 3.3.26
|
47
47
|
signing_key:
|
48
48
|
specification_version: 4
|
49
49
|
summary: Universal configuration library parser
|