* dir.c (dir_s_glob): [DOC] Improve wording and layout.

* dir.c (file_s_fnmatch):  ditto.

* dir.c (Init_Dir):  [DOC] Document File::Constants::FNM_XXX
  constants.  (These won't show up in RDoc until a new RDoc is
  imported.)



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2013-09-13 21:08:36 +00:00
parent a332bc59bf
commit 2614d9ba2f
3 changed files with 123 additions and 70 deletions

View File

@ -1,3 +1,13 @@
Sat Sep 14 06:08:10 2013 Eric Hodel <drbrain@segment7.net>
* dir.c (dir_s_glob): [DOC] Improve wording and layout.
* dir.c (file_s_fnmatch): ditto.
* dir.c (Init_Dir): [DOC] Document File::Constants::FNM_XXX
constants. (These won't show up in RDoc until a new RDoc is
imported.)
Sat Sep 14 04:57:51 2013 Eric Hodel <drbrain@segment7.net> Sat Sep 14 04:57:51 2013 Eric Hodel <drbrain@segment7.net>
* lib/rubygems: Update to RubyGems 2.1.3 * lib/rubygems: Update to RubyGems 2.1.3

181
dir.c
View File

@ -1792,49 +1792,56 @@ dir_s_aref(int argc, VALUE *argv, VALUE obj)
/* /*
* call-seq: * call-seq:
* Dir.glob( pattern, [flags] ) -> array * Dir.glob( pattern, [flags] ) -> matches
* Dir.glob( pattern, [flags] ) {| filename | block } -> nil * Dir.glob( pattern, [flags] ) { |filename| block } -> nil
* *
* Returns the filenames found by expanding <i>pattern</i> which is * Expands +pattern+, which is an Array of patterns or a pattern String, and
* an +Array+ of the patterns or the pattern +String+, either as an * returns the results as +matches+ or as arguments given to the block.
* <i>array</i> or as parameters to the block. Note that this pattern
* is not a regexp (it's closer to a shell glob). See
* <code>File::fnmatch</code> for the meaning of the <i>flags</i>
* parameter. Note that case sensitivity depends on your system (so
* <code>File::FNM_CASEFOLD</code> is ignored), as does the order
* in which the results are returned.
* *
* <code>*</code>:: Matches any file. Can be restricted by * Note that this pattern is not a regexp, it's closer to a shell glob. See
* other values in the glob. <code>*</code> * File::fnmatch for the meaning of the +flags+ parameter. Note that case
* will match all files; <code>c*</code> will * sensitivity depends on your system (so File::FNM_CASEFOLD is ignored), as
* match all files beginning with * does the order in which the results are returned.
* <code>c</code>; <code>*c</code> will match *
* all files ending with <code>c</code>; and * <code>*</code>::
* <code>\*c\*</code> will match all files that * Matches any file. Can be restricted by other values in the glob.
* have <code>c</code> in them (including at * Equivalent to <code>/ .* /x</code> in regexp.
* the beginning or end). Equivalent to *
* <code>/ .* /x</code> in regexp. Note, this * <code>*</code>:: Matches all files
* will not match Unix-like hidden files (dotfiles). * <code>c*</code>:: Matches all files beginning with <code>c</code>
* In order to include those in the match results, * <code>*c</code>:: Matches all files ending with <code>c</code>
* you must use something like <code>"{*,.*}"</code>. * <code>\*c\*</code>:: Match all files that have <code>c</code> in them
* <code>**</code>:: Matches directories recursively. * (including at the beginning or end).
* <code>?</code>:: Matches any one character. Equivalent to *
* <code>/.{1}/</code> in regexp. * Note, this will not match Unix-like hidden files (dotfiles). In order
* <code>[set]</code>:: Matches any one character in +set+. * to include those in the match results, you must use the
* Behaves exactly like character sets in * File::FNM_DOTMATCH flag or something like <code>"{*,.*}"</code>.
* Regexp, including set negation *
* (<code>[^a-z]</code>). * <code>**</code>::
* <code>{p,q}</code>:: Matches either literal <code>p</code> or * Matches directories recursively.
* literal <code>q</code>. Matching literals *
* may be more than one character in length. * <code>?</code>::
* More than two literals may be specified. * Matches any one character. Equivalent to <code>/.{1}/</code> in regexp.
* Equivalent to pattern alternation in *
* regexp. * <code>[set]</code>::
* <code> \\ </code>:: Escapes the next metacharacter. * Matches any one character in +set+. Behaves exactly like character sets
* Note that this means you cannot use backslash * in Regexp, including set negation (<code>[^a-z]</code>).
* in windows as part of a glob, *
* i.e. <code>Dir["c:\\foo*"]</code> will not work, * <code>{p,q}</code>::
* use <code>Dir["c:/foo*"]</code> instead. * Matches either literal <code>p</code> or literal <code>q</code>.
* Equivalent to pattern alternation in regexp.
*
* Matching literals may be more than one character in length. More than
* two literals may be specified.
*
* <code> \\ </code>::
* Escapes the next metacharacter.
*
* Note that this means you cannot use backslash on windows as part of a
* glob, i.e. <code>Dir["c:\\foo*"]</code> will not work, use
* <code>Dir["c:/foo*"]</code> instead.
*
* Examples:
* *
* Dir["config.?"] #=> ["config.h"] * Dir["config.?"] #=> ["config.h"]
* Dir.glob("config.?") #=> ["config.h"] * Dir.glob("config.?") #=> ["config.h"]
@ -1983,37 +1990,44 @@ fnmatch_brace(const char *pattern, VALUE val, void *enc)
* File.fnmatch( pattern, path, [flags] ) -> (true or false) * File.fnmatch( pattern, path, [flags] ) -> (true or false)
* File.fnmatch?( pattern, path, [flags] ) -> (true or false) * File.fnmatch?( pattern, path, [flags] ) -> (true or false)
* *
* Returns true if <i>path</i> matches against <i>pattern</i> The * Returns true if +path+ matches against +pattern+. The pattern is not a
* pattern is not a regular expression; instead it follows rules * regular expression; instead it follows rules similar to shell filename
* similar to shell filename globbing. It may contain the following * globbing. It may contain the following metacharacters:
* metacharacters:
* *
* <code>*</code>:: Matches any file. Can be restricted by * <code>*</code>::
* other values in the glob. <code>*</code> * Matches any file. Can be restricted by other values in the glob.
* will match all files; <code>c*</code> will * Equivalent to <code>/ .* /x</code> in regexp.
* match all files beginning with
* <code>c</code>; <code>*c</code> will match
* all files ending with <code>c</code>; and
* <code>\*c*</code> will match all files that
* have <code>c</code> in them (including at
* the beginning or end). Equivalent to
* <code>/ .* /x</code> in regexp.
* <code>**</code>:: Matches directories recursively or files
* expansively.
* <code>?</code>:: Matches any one character. Equivalent to
* <code>/.{1}/</code> in regexp.
* <code>[set]</code>:: Matches any one character in +set+.
* Behaves exactly like character sets in
* Regexp, including set negation
* (<code>[^a-z]</code>).
* <code> \ </code>:: Escapes the next metacharacter.
* <code>{a,b}</code>:: Matches pattern a and pattern b if
* <code>File::FNM_EXTGLOB</code> flag is enabled.
* Behaves like a Regexp union (<code>(?:a|b)</code>).
* *
* <i>flags</i> is a bitwise OR of the <code>FNM_xxx</code> * <code>*</code>:: Matches all files regular files
* parameters. The same glob pattern and flags are used by * <code>c*</code>:: Matches all files beginning with <code>c</code>
* <code>Dir::glob</code>. * <code>*c</code>:: Matches all files ending with <code>c</code>
* <code>\*c*</code>:: Matches all files that have <code>c</code> in them
* (including at the beginning or end).
*
* To match hidden files (that start with a <code>.</code> set the
* File::FNM_DOTMATCH flag.
*
* <code>**</code>::
* Matches directories recursively or files expansively.
*
* <code>?</code>::
* Matches any one character. Equivalent to <code>/.{1}/</code> in regexp.
*
* <code>[set]</code>::
* Matches any one character in +set+. Behaves exactly like character sets
* in Regexp, including set negation (<code>[^a-z]</code>).
*
* <code> \ </code>::
* Escapes the next metacharacter.
*
* <code>{a,b}</code>::
* Matches pattern a and pattern b if File::FNM_EXTGLOB flag is enabled.
* Behaves like a Regexp union (<code>(?:a|b)</code>).
*
* +flags+ is a bitwise OR of the <code>FNM_XXX</code> constants. The same
* glob pattern and flags are used by Dir::glob.
*
* Examples:
* *
* File.fnmatch('cat', 'cat') #=> true # match entire string * File.fnmatch('cat', 'cat') #=> true # match entire string
* File.fnmatch('cat', 'category') #=> false # only match partial string * File.fnmatch('cat', 'category') #=> false # only match partial string
@ -2197,10 +2211,37 @@ Init_Dir(void)
rb_define_singleton_method(rb_cFile,"fnmatch", file_s_fnmatch, -1); rb_define_singleton_method(rb_cFile,"fnmatch", file_s_fnmatch, -1);
rb_define_singleton_method(rb_cFile,"fnmatch?", file_s_fnmatch, -1); rb_define_singleton_method(rb_cFile,"fnmatch?", file_s_fnmatch, -1);
/* Document-const: File::Constants::FNM_NOESCAPE
*
* Disables escapes in File.fnmatch and Dir.glob patterns
*/
rb_file_const("FNM_NOESCAPE", INT2FIX(FNM_NOESCAPE)); rb_file_const("FNM_NOESCAPE", INT2FIX(FNM_NOESCAPE));
/* Document-const: File::Constants::FNM_PATHNAME
*
* Wildcards in File.fnmatch and Dir.glob patterns do not match directory
* separators
*/
rb_file_const("FNM_PATHNAME", INT2FIX(FNM_PATHNAME)); rb_file_const("FNM_PATHNAME", INT2FIX(FNM_PATHNAME));
/* Document-const: File::Constants::FNM_DOTMATCH
*
* The '*' wildcard matches filenames starting with "." in File.fnmatch
* and Dir.glob patterns
*/
rb_file_const("FNM_DOTMATCH", INT2FIX(FNM_DOTMATCH)); rb_file_const("FNM_DOTMATCH", INT2FIX(FNM_DOTMATCH));
/* Document-const: File::Constants::FNM_CASEFOLD
*
* Makes File.fnmatch patterns case insensitive (but not Dir.glob
* patterns).
*/
rb_file_const("FNM_CASEFOLD", INT2FIX(FNM_CASEFOLD)); rb_file_const("FNM_CASEFOLD", INT2FIX(FNM_CASEFOLD));
/* Document-const: File::Constants::FNM_EXTGLOB
*
* Allows file globbing through "{a,b}" in File.fnmatch patterns.
*/
rb_file_const("FNM_EXTGLOB", INT2FIX(FNM_EXTGLOB)); rb_file_const("FNM_EXTGLOB", INT2FIX(FNM_EXTGLOB));
rb_file_const("FNM_SYSCASE", INT2FIX(FNM_SYSCASE)); rb_file_const("FNM_SYSCASE", INT2FIX(FNM_SYSCASE));
} }

2
file.c
View File

@ -5567,6 +5567,8 @@ static const char null_device[] =
* <code>0644</code>, which means read/write for owner, read-only for * <code>0644</code>, which means read/write for owner, read-only for
* all others. The only change that can be made is to make the file * all others. The only change that can be made is to make the file
* read-only, which is reported as <code>0444</code>. * read-only, which is reported as <code>0444</code>.
*
* Various constants for the methods in File can be found in File::Constants.
*/ */
void void