ucl 0.1.0 → 0.1.2
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 +57 -27
- data/ucl.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3fb8e8b518ea32adfa5365bf32e260487f3aa4ec9e546738911e6cf37a16e300
|
4
|
+
data.tar.gz: e9067e8747899c187f9ae400cd4bfe58e4343c41ff04b70cdbe161a500062bfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 962eea2f25228aec1ee903315074ceabd9cc424b2afab0963e68179fd39f1666abe6954404594ae6d4c658704b89200d4bfad21174bc9cd298b8ce66ea9252b7
|
7
|
+
data.tar.gz: b5c9bbe4b92be69734f5bd0df81a043dba97158489da7f67d7fce6e33f976a6eb209c45b7a72690bd441aa2fd8aed203f47389753328efd875fe05175e875afa
|
data/ext/ucl.c
CHANGED
@@ -25,6 +25,11 @@
|
|
25
25
|
static VALUE mUCL = Qundef;
|
26
26
|
static VALUE eUCLError = Qundef;
|
27
27
|
|
28
|
+
static int ucl_allowed_flags = UCL_PARSER_KEY_LOWERCASE |
|
29
|
+
UCL_PARSER_NO_TIME |
|
30
|
+
UCL_PARSER_DISABLE_MACRO |
|
31
|
+
UCL_PARSER_NO_FILEVARS ;
|
32
|
+
|
28
33
|
|
29
34
|
VALUE
|
30
35
|
_iterate_valid_ucl(ucl_object_t const *root, int flags)
|
@@ -103,6 +108,20 @@ _iterate_valid_ucl(ucl_object_t const *root, int flags)
|
|
103
108
|
}
|
104
109
|
}
|
105
110
|
|
111
|
+
static VALUE
|
112
|
+
ucl_s_get_flags(VALUE klass)
|
113
|
+
{
|
114
|
+
return rb_iv_get(klass, "@flags");
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
static VALUE
|
119
|
+
ucl_s_set_flags(VALUE klass, VALUE val)
|
120
|
+
{
|
121
|
+
rb_check_type(val, T_FIXNUM);
|
122
|
+
rb_iv_set(klass, "@flags", val);
|
123
|
+
return val;
|
124
|
+
}
|
106
125
|
|
107
126
|
|
108
127
|
/**
|
@@ -116,19 +135,14 @@ _iterate_valid_ucl(ucl_object_t const *root, int flags)
|
|
116
135
|
static VALUE
|
117
136
|
ucl_s_parse(int argc, VALUE *argv, VALUE klass)
|
118
137
|
{
|
119
|
-
static int allowed_flags = UCL_PARSER_KEY_LOWERCASE |
|
120
|
-
UCL_PARSER_NO_TIME |
|
121
|
-
UCL_PARSER_DISABLE_MACRO |
|
122
|
-
UCL_PARSER_NO_FILEVARS ;
|
123
|
-
|
124
138
|
VALUE data, flags;
|
125
139
|
rb_scan_args(argc, argv, "11", &data, &flags);
|
126
|
-
if (NIL_P(flags)) flags =
|
140
|
+
if (NIL_P(flags)) flags = ucl_s_get_flags(mUCL);
|
127
141
|
|
128
142
|
rb_check_type(data, T_STRING);
|
129
143
|
rb_check_type(flags, T_FIXNUM);
|
130
144
|
|
131
|
-
int c_flags = FIX2INT(flags) &
|
145
|
+
int c_flags = FIX2INT(flags) & ucl_allowed_flags;
|
132
146
|
|
133
147
|
struct ucl_parser *parser =
|
134
148
|
ucl_parser_new(c_flags | UCL_PARSER_NO_IMPLICIT_ARRAYS);
|
@@ -138,20 +152,16 @@ ucl_s_parse(int argc, VALUE *argv, VALUE klass)
|
|
138
152
|
RSTRING_LEN(data));
|
139
153
|
|
140
154
|
if (ucl_parser_get_error(parser)) {
|
141
|
-
|
155
|
+
const char *errormsg = ucl_parser_get_error(parser);
|
156
|
+
if (parser != NULL) { ucl_parser_free(parser); }
|
157
|
+
rb_raise(eUCLError, "%s", errormsg);
|
142
158
|
}
|
143
159
|
|
144
160
|
ucl_object_t *root = ucl_parser_get_object(parser);
|
161
|
+
VALUE res = _iterate_valid_ucl(root, FIX2INT(flags));
|
145
162
|
|
146
|
-
|
147
|
-
|
148
|
-
if (parser != NULL) {
|
149
|
-
ucl_parser_free(parser);
|
150
|
-
}
|
151
|
-
|
152
|
-
if (root != NULL) {
|
153
|
-
ucl_object_unref(root);
|
154
|
-
}
|
163
|
+
if (parser != NULL) { ucl_parser_free(parser); }
|
164
|
+
if (root != NULL) { ucl_object_unref(root); }
|
155
165
|
|
156
166
|
return res;
|
157
167
|
}
|
@@ -173,22 +183,38 @@ ucl_s_load_file(int argc, VALUE *argv, VALUE klass)
|
|
173
183
|
{
|
174
184
|
VALUE file, flags;
|
175
185
|
rb_scan_args(argc, argv, "11", &file, &flags);
|
186
|
+
if (NIL_P(flags)) flags = ucl_s_get_flags(mUCL);
|
176
187
|
|
177
|
-
|
178
|
-
|
179
|
-
|
188
|
+
rb_check_type(file, T_STRING);
|
189
|
+
rb_check_type(flags, T_FIXNUM);
|
190
|
+
|
191
|
+
int c_flags = FIX2INT(flags) & ucl_allowed_flags;
|
192
|
+
char *c_file = StringValueCStr(file);
|
193
|
+
|
194
|
+
struct ucl_parser *parser =
|
195
|
+
ucl_parser_new(c_flags | UCL_PARSER_NO_IMPLICIT_ARRAYS);
|
196
|
+
ucl_parser_add_file(parser, c_file);
|
197
|
+
|
198
|
+
if (ucl_parser_get_error(parser)) {
|
199
|
+
const char *errormsg = ucl_parser_get_error(parser);
|
200
|
+
if (parser != NULL) { ucl_parser_free(parser); }
|
201
|
+
rb_raise(eUCLError, "%s", errormsg);
|
202
|
+
}
|
180
203
|
|
181
|
-
|
182
|
-
VALUE
|
183
|
-
2, read_args, RB_PASS_KEYWORDS);
|
204
|
+
ucl_object_t *root = ucl_parser_get_object(parser);
|
205
|
+
VALUE res = _iterate_valid_ucl(root, FIX2INT(flags));
|
184
206
|
|
185
|
-
|
186
|
-
|
207
|
+
if (parser != NULL) { ucl_parser_free(parser); }
|
208
|
+
if (root != NULL) { ucl_object_unref(root); }
|
209
|
+
|
210
|
+
return res;
|
187
211
|
}
|
188
212
|
|
189
213
|
|
190
214
|
|
191
215
|
|
216
|
+
|
217
|
+
|
192
218
|
void Init_ucl(void) {
|
193
219
|
/* Main classes */
|
194
220
|
mUCL = rb_define_class("UCL", rb_cObject);
|
@@ -200,11 +226,15 @@ void Init_ucl(void) {
|
|
200
226
|
rb_define_const(mUCL, "DISABLE_MACRO", INT2FIX(UCL_PARSER_DISABLE_MACRO));
|
201
227
|
rb_define_const(mUCL, "NO_FILEVARS", INT2FIX(UCL_PARSER_NO_FILEVARS ));
|
202
228
|
rb_define_const(mUCL, "KEY_SYMBOL", INT2FIX(UCL_PARSER_KEY_SYMBOL ));
|
203
|
-
|
229
|
+
|
230
|
+
/* Variables */
|
231
|
+
ucl_s_set_flags(mUCL, INT2FIX(0));
|
232
|
+
|
204
233
|
/* Definitions */
|
205
234
|
rb_define_singleton_method(mUCL, "load_file", ucl_s_load_file, -1);
|
206
235
|
rb_define_singleton_method(mUCL, "parse", ucl_s_parse, -1);
|
207
|
-
|
236
|
+
rb_define_singleton_method(mUCL, "flags", ucl_s_get_flags, 0);
|
237
|
+
rb_define_singleton_method(mUCL, "flags=", ucl_s_set_flags, 1);
|
208
238
|
}
|
209
239
|
|
210
240
|
|
data/ucl.gemspec
CHANGED
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.2
|
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: 2022-12-
|
11
|
+
date: 2022-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |2+
|
14
14
|
|