projects
/
ruby-vorbistagger.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Added common aliases for Ogg::Vorbis::Comments#has_key?.
[ruby-vorbistagger.git]
/
ext
/
comments.c
diff --git
a/ext/comments.c
b/ext/comments.c
index 98dd73c4e04b34ccf1876102bab67f2be59bcacc..b37f59146ea3067ff1902137cb554389f61731eb 100644
(file)
--- a/
ext/comments.c
+++ b/
ext/comments.c
@@
-48,7
+48,7
@@
comments_init (VALUE self, vcedit_state *state)
o->items = rb_ary_new2 (vc->comments);
for (i = 0; i < vc->comments; i++) {
o->items = rb_ary_new2 (vc->comments);
for (i = 0; i < vc->comments; i++) {
- VALUE k, v;
+ VALUE k, v
, pair
;
char *ptr, *content = vc->user_comments[i];
ptr = strchr (content, '=');
char *ptr, *content = vc->user_comments[i];
ptr = strchr (content, '=');
@@
-59,8
+59,10
@@
comments_init (VALUE self, vcedit_state *state)
v = rb_str_new2 (ptr + 1);
v = rb_str_new2 (ptr + 1);
- rb_ary_store (o->items, i,
- rb_ary_new3 (2, k, v));
+ pair = rb_ary_new3 (2, k, v);
+ OBJ_FREEZE (pair);
+
+ rb_ary_store (o->items, i, pair);
}
rb_iv_set (self, "@items", o->items);
}
rb_iv_set (self, "@items", o->items);
@@
-138,12
+140,12
@@
c_inspect (VALUE self)
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
for (i = 0; i < items->len; i++) {
struct RArray *pair = RARRAY (items->ptr[i]);
+ if (i)
+ rb_str_buf_cat (ret, ", ", 2);
+
rb_str_buf_append (ret, rb_inspect (pair->ptr[0]));
rb_str_buf_cat (ret, "=>", 2);
rb_str_buf_append (ret, rb_inspect (pair->ptr[1]));
rb_str_buf_append (ret, rb_inspect (pair->ptr[0]));
rb_str_buf_cat (ret, "=>", 2);
rb_str_buf_append (ret, rb_inspect (pair->ptr[1]));
-
- if (i < items->len - 1)
- rb_str_buf_cat (ret, ", ", 2);
}
rb_str_buf_cat (ret, "}", 1);
}
rb_str_buf_cat (ret, "}", 1);
@@
-333,6
+335,7
@@
c_aref (VALUE self, VALUE key)
static VALUE
c_aset (VALUE self, VALUE key, VALUE value)
{
static VALUE
c_aset (VALUE self, VALUE key, VALUE value)
{
+ VALUE tmp;
RbVorbisComments *o;
struct RArray *items;
int i;
RbVorbisComments *o;
struct RArray *items;
int i;
@@
-352,7
+355,10
@@
c_aset (VALUE self, VALUE key, VALUE value)
}
}
}
}
- rb_ary_push (o->items, rb_ary_new3 (2, key, value));
+ tmp = rb_ary_new3 (2, rb_str_dup_frozen (key), value);
+ OBJ_FREEZE (tmp);
+
+ rb_ary_push (o->items, tmp);
return value;
}
return value;
}
@@
-545,6
+551,9
@@
Init_Comments (VALUE mVorbis)
rb_define_alias (c, "size", "length");
rb_define_alias (c, "each_pair", "each");
rb_define_alias (c, "size", "length");
rb_define_alias (c, "each_pair", "each");
+ rb_define_alias (c, "key?", "has_key?");
+ rb_define_alias (c, "include?", "has_key?");
+ rb_define_alias (c, "member?", "has_key?");
id_casecmp = rb_intern ("casecmp");
id_replace = rb_intern ("replace");
id_casecmp = rb_intern ("casecmp");
id_replace = rb_intern ("replace");