mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/pathname/pathname.c (path_fnmatch): Pathname#fnmatch and
Pathname#fnmatch? translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28910 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d82dd262d0
commit
b50fb9034e
4 changed files with 30 additions and 9 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun Aug 8 07:29:55 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* ext/pathname/pathname.c (path_fnmatch): Pathname#fnmatch and
|
||||||
|
Pathname#fnmatch? translated from pathname.rb.
|
||||||
|
|
||||||
Sun Aug 8 07:18:22 2010 Tanaka Akira <akr@fsij.org>
|
Sun Aug 8 07:18:22 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* include/ruby/subst.h (snprintf): redefinition moved from ruby.h.
|
* include/ruby/subst.h (snprintf): redefinition moved from ruby.h.
|
||||||
|
|
|
@ -512,13 +512,6 @@ end
|
||||||
|
|
||||||
class Pathname # * File *
|
class Pathname # * File *
|
||||||
|
|
||||||
# See <tt>File.fnmatch</tt>. Return +true+ if the receiver matches the given
|
|
||||||
# pattern.
|
|
||||||
def fnmatch(pattern, *args) File.fnmatch(pattern, @path, *args) end
|
|
||||||
|
|
||||||
# See <tt>File.fnmatch?</tt> (same as #fnmatch).
|
|
||||||
def fnmatch?(pattern, *args) File.fnmatch?(pattern, @path, *args) end
|
|
||||||
|
|
||||||
# See <tt>File.ftype</tt>. Returns "type" of file ("file", "directory",
|
# See <tt>File.ftype</tt>. Returns "type" of file ("file", "directory",
|
||||||
# etc).
|
# etc).
|
||||||
def ftype() File.ftype(@path) end
|
def ftype() File.ftype(@path) end
|
||||||
|
|
|
@ -128,8 +128,8 @@ path_hash(VALUE self)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* pathname.to_s => string
|
* pathname.to_s -> string
|
||||||
* pathname.to_path => string
|
* pathname.to_path -> string
|
||||||
*
|
*
|
||||||
* Return the path as a String.
|
* Return the path as a String.
|
||||||
*
|
*
|
||||||
|
@ -295,6 +295,25 @@ path_lchown(VALUE self, VALUE owner, VALUE group)
|
||||||
return rb_funcall(rb_cFile, rb_intern("lchown"), 3, owner, group, get_strpath(self));
|
return rb_funcall(rb_cFile, rb_intern("lchown"), 3, owner, group, get_strpath(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call-seq:
|
||||||
|
* pathname.fnmatch(pattern, [flags]) -> string
|
||||||
|
* pathname.fnmatch?(pattern, [flags]) -> string
|
||||||
|
*
|
||||||
|
* See <tt>File.fnmatch</tt>. Return +true+ if the receiver matches the given
|
||||||
|
* pattern.
|
||||||
|
*/
|
||||||
|
static VALUE
|
||||||
|
path_fnmatch(int argc, VALUE *argv, VALUE self)
|
||||||
|
{
|
||||||
|
VALUE str = get_strpath(self);
|
||||||
|
VALUE pattern, flags;
|
||||||
|
if (rb_scan_args(argc, argv, "11", &pattern, &flags) == 1)
|
||||||
|
return rb_funcall(rb_cFile, rb_intern("fnmatch"), 2, pattern, str);
|
||||||
|
else
|
||||||
|
return rb_funcall(rb_cFile, rb_intern("fnmatch"), 3, pattern, str, flags);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* == Pathname
|
* == Pathname
|
||||||
*
|
*
|
||||||
|
@ -502,4 +521,6 @@ Init_pathname()
|
||||||
rb_define_method(rb_cPathname, "lchmod", path_lchmod, 1);
|
rb_define_method(rb_cPathname, "lchmod", path_lchmod, 1);
|
||||||
rb_define_method(rb_cPathname, "chown", path_chown, 2);
|
rb_define_method(rb_cPathname, "chown", path_chown, 2);
|
||||||
rb_define_method(rb_cPathname, "lchown", path_lchown, 2);
|
rb_define_method(rb_cPathname, "lchown", path_lchown, 2);
|
||||||
|
rb_define_method(rb_cPathname, "fnmatch", path_fnmatch, -1);
|
||||||
|
rb_define_method(rb_cPathname, "fnmatch?", path_fnmatch, -1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -788,6 +788,8 @@ class TestPathname < Test::Unit::TestCase
|
||||||
path = Pathname("a")
|
path = Pathname("a")
|
||||||
assert_equal(true, path.fnmatch("*"))
|
assert_equal(true, path.fnmatch("*"))
|
||||||
assert_equal(false, path.fnmatch("*.*"))
|
assert_equal(false, path.fnmatch("*.*"))
|
||||||
|
assert_equal(false, Pathname(".foo").fnmatch("*"))
|
||||||
|
assert_equal(true, Pathname(".foo").fnmatch("*", File::FNM_DOTMATCH))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fnmatch?
|
def test_fnmatch?
|
||||||
|
|
Loading…
Add table
Reference in a new issue