diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-04-10 08:45:26 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-04-10 08:45:26 +0000 |
commit | 19c42c0740145dec1be93c332647f4310ea19918 (patch) | |
tree | 88516eac5daf33e2e935c3d38415e13d542ac131 /file.c | |
parent | ff0abdc55e57f42f75204429c9eca471df48d835 (diff) |
* variable.c (rb_obj_remove_instance_variable): raise NameError if
specified instance variable is not defined.
* variable.c (generic_ivar_remove): modified to check ivar
existence.
* file.c (rb_file_s_extname): new method based on the proposal
(and patch) from Mike Hall. [new]
* eval.c (error_handle): default to 1 unless status is set.
* eval.c (ruby_options): guard error_handle() with PROT_NONE.
* eval.c (ruby_stop): ditto.
* math.c (math_acosh): added. [new]
* math.c (math_asinh): ditto.
* math.c (math_atanh): ditto.
* struct.c (rb_struct_each_pair): method added. [new]
* class.c (rb_singleton_class): wrong condition; was creating
unnecessary singleton class.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 27 |
1 files changed, 25 insertions, 2 deletions
@@ -1564,9 +1564,9 @@ rmext(p, e) { int l1, l2; - l1 = strlen(p); if (!e) return 0; + l1 = strlen(p); l2 = strlen(e); if (l2 == 2 && e[1] == '*') { e = strrchr(p, *e); @@ -1628,11 +1628,33 @@ rb_file_s_dirname(klass, fname) if (p == name) p++; dirname = rb_str_new(name, p - name); - if (OBJ_TAINTED(fname)) OBJ_TAINT(dirname); + OBJ_INFECT(dirname, fname); return dirname; } static VALUE +rb_file_s_extname(klass, fname) + VALUE klass, fname; +{ + char *name, *p, *e; + VALUE extname; + + name = StringValuePtr(fname); + p = strrdirsep(name); /* get the last path component */ + if (!p) + p = name; + else + p++; + + e = strrchr(p, '.'); /* get the last dot of the last component */ + if (!e || e == p) /* no dot, or the only dot is first? */ + return rb_str_new2(""); + extname = rb_str_new2(e); /* keep the dot, too! */ + OBJ_INFECT(extname, fname); + return extname; +} + +static VALUE rb_file_s_split(klass, path) VALUE klass, path; { @@ -2559,6 +2581,7 @@ Init_File() rb_define_singleton_method(rb_cFile, "expand_path", rb_file_s_expand_path, -1); rb_define_singleton_method(rb_cFile, "basename", rb_file_s_basename, -1); rb_define_singleton_method(rb_cFile, "dirname", rb_file_s_dirname, 1); + rb_define_singleton_method(rb_cFile, "extname", rb_file_s_extname, 1); separator = rb_obj_freeze(rb_str_new2("/")); rb_define_const(rb_cFile, "Separator", separator); |