Module: Protocol::Media::Registry::Native

Defined in:
ext/protocol/media/registry/native.c

Class Method Summary collapse

Class Method Details

.lookup(name) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'ext/protocol/media/registry/native.c', line 9

static VALUE Protocol_Media_Registry_lookup(VALUE _self, VALUE name)
{
	StringValue(name);
	
	const struct MediaTypeRecord *record = lookup_record(RSTRING_PTR(name), (unsigned int)RSTRING_LEN(name));
	if (!record) return Qnil;
	
	VALUE result = rb_ary_new_capa(3);
	rb_ary_push(result, rb_str_new_cstr(record->name));
	rb_ary_push(result, record->encoding ? rb_str_new_cstr(record->encoding) : Qnil);
	
	if (record->extensions) {
		rb_ary_push(result, rb_str_split(rb_str_new_cstr(record->extensions), " "));
	} else {
		rb_ary_push(result, Qnil);
	}
	
	return result;
}

.lookup_extension(extension) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'ext/protocol/media/registry/native.c', line 29

static VALUE Protocol_Media_Registry_lookup_extension(VALUE _self, VALUE extension)
{
	StringValue(extension);
	
	const struct ExtensionRecord *record = lookup_extension(RSTRING_PTR(extension), (unsigned int)RSTRING_LEN(extension));
	if (!record) return Qnil;
	
	return rb_str_new_cstr(record->name);
}