* ext/pathname/pathname.c (path_sub_ext): Pathname#sub_ext translated
from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ffe49186c9
commit
caa05197d3
@ -1,3 +1,8 @@
|
||||
Sun Aug 1 14:59:04 2010 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/pathname/pathname.c (path_sub_ext): Pathname#sub_ext translated
|
||||
from pathname.rb.
|
||||
|
||||
Sun Aug 1 10:23:48 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* lib/irb/init.rb (IRB.parse_opts): set VERBOSE to true when debug
|
||||
|
@ -39,15 +39,6 @@ class Pathname
|
||||
SEPARATOR_PAT = /#{Regexp.quote File::SEPARATOR}/
|
||||
end
|
||||
|
||||
# Return a pathname which the extension of the basename is substituted by
|
||||
# <i>repl</i>.
|
||||
#
|
||||
# If self has no extension part, <i>repl</i> is appended.
|
||||
def sub_ext(repl)
|
||||
ext = File.extname(@path)
|
||||
self.class.new(@path.chomp(ext) + repl)
|
||||
end
|
||||
|
||||
# chop_basename(path) -> [pre-basename, basename] or nil
|
||||
def chop_basename(path)
|
||||
base = File.basename(path)
|
||||
|
@ -167,6 +167,37 @@ path_sub(int argc, VALUE *argv, VALUE self)
|
||||
return rb_class_new_instance(1, &str, rb_obj_class(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a pathname which the extension of the basename is substituted by
|
||||
* <i>repl</i>.
|
||||
*
|
||||
* If self has no extension part, <i>repl</i> is appended.
|
||||
*/
|
||||
static VALUE
|
||||
path_sub_ext(VALUE self, VALUE repl)
|
||||
{
|
||||
VALUE str = get_strpath(self);
|
||||
VALUE str2;
|
||||
long extlen;
|
||||
const char *ext;
|
||||
const char *p;
|
||||
|
||||
StringValue(repl);
|
||||
p = RSTRING_PTR(str);
|
||||
ext = ruby_find_extname(p, &extlen);
|
||||
if (ext == NULL) {
|
||||
ext = p + RSTRING_LEN(str);
|
||||
}
|
||||
else if (extlen <= 1) {
|
||||
ext += extlen;
|
||||
}
|
||||
str2 = rb_str_dup(str);
|
||||
rb_str_set_len(str2, ext-p);
|
||||
rb_str_append(str2, repl);
|
||||
OBJ_INFECT(str2, str);
|
||||
return rb_class_new_instance(1, &str2, rb_obj_class(self));
|
||||
}
|
||||
|
||||
/*
|
||||
* == Pathname
|
||||
*
|
||||
@ -364,4 +395,5 @@ Init_pathname()
|
||||
rb_define_method(rb_cPathname, "to_path", path_to_s, 0);
|
||||
rb_define_method(rb_cPathname, "inspect", path_inspect, 0);
|
||||
rb_define_method(rb_cPathname, "sub", path_sub, -1);
|
||||
rb_define_method(rb_cPathname, "sub_ext", path_sub_ext, 1);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user