242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'ext/json_extractor/json_extractor.c', line 242
static VALUE rb_extract_subdocument(VALUE self, VALUE str, VALUE key) {
char *data, *substr;
VALUE result;
// No str?
if(str == Qnil) {
return Qnil;
}
// No key?
if(key == Qnil) {
return Qnil;
}
// If str points to a file, let's read it and use that. Otherwise...
if(file_exists(RSTRING_PTR(str))) {
data = read_all(RSTRING_PTR(str));
substr = extract_subdocument(data, RSTRING_PTR(key));
free(data);
} else {
substr = extract_subdocument(RSTRING_PTR(str), RSTRING_PTR(key));
}
if(substr == NULL) {
return Qnil;
}
result = rb_str_new2(substr);
// TODO: Figure out if this is right. It behaves properly, so I'm assuming
// it's OK.
free(substr);
return result;
}
|