File::FNM_CASEFOLD doesn't work for Dir.glob?

It’s no fun to have to do:

Dir.glob(’[fF][oO][oO][dD][iI][rR]/*’)

That makes two oddiites between File.fnmatch? and Dir.glob. The other
is that. File.fnmatch? doesn’t support **. Wouldn’t it be better if
these two functions drew upon the same source code?

T.

Hi,

It work’s fine for me:

[email protected]:~/tmp$ touch file.txt
[email protected]:~/tmp$ touch file.Txt
[email protected]:~/tmp$ irb --simple-prompt

Dir.glob(’*.txt’, File::FNM_CASEFOLD)
=> [“file.txt”, “file.Txt”]

quit
[email protected]:~/tmp$ ruby -v
ruby 1.8.4 (2005-12-24) [i486-linux]


Martins

Hi,

At Fri, 14 Jul 2006 22:39:19 +0900,
[email protected] wrote in [ruby-talk:201917]:

It’s no fun to have to do:

Dir.glob(’[fF][oO][oO][dD][iI][rR]/*’)

Seems nice to be backported from the trunk.

That makes two oddiites between File.fnmatch? and Dir.glob. The other
is that. File.fnmatch? doesn’t support **. Wouldn’t it be better if
these two functions drew upon the same source code?

File::FNM_PATHNAME

Index: dir.c

RCS file: /cvs/ruby/src/ruby/dir.c,v
retrieving revision 1.92.2.34
diff -p -u -2 -I ‘$Date’ -r1.92.2.34 dir.c
— dir.c 17 May 2006 09:14:34 -0000 1.92.2.34
+++ dir.c 14 Jul 2006 14:32:43 -0000
@@ -68,8 +68,21 @@ char strchr _((char,char));
#endif

+#ifndef CASEFOLD_FILESYSTEM
+# if defined DOSISH || defined __VMS
+# define CASEFOLD_FILESYSTEM 1
+# else
+# define CASEFOLD_FILESYSTEM 0
+# endif
+#endif
+
#define FNM_NOESCAPE 0x01
#define FNM_PATHNAME 0x02
#define FNM_DOTMATCH 0x04
#define FNM_CASEFOLD 0x08
+#if CASEFOLD_FILESYSTEM
+#define FNM_SYSCASE FNM_CASEFOLD
+#else
+#define FNM_SYSCASE 0
+#endif

#define FNM_NOMATCH 1
@@ -807,5 +820,5 @@ sys_warning_1(mesg)
}

-#define GLOB_VERBOSE (1 << (sizeof(int) * CHAR_BIT - 1))
+#define GLOB_VERBOSE (1U << (sizeof(int) * CHAR_BIT - 1))
#define sys_warning(val)
((flags & GLOB_VERBOSE) && rb_protect((VALUE
(*)_((VALUE)))sys_warning_1, (VALUE)(val), 0))
@@ -820,5 +833,6 @@ has_magic(s, send, flags)
register char c;
int open = 0;

  • int escape = !(flags & FNM_NOESCAPE);
  • const int escape = !(flags & FNM_NOESCAPE);

  • const int nocase = flags & FNM_CASEFOLD;

    while ((c = *p++) != ‘\0’) {
    @@ -839,4 +853,9 @@ has_magic(s, send, flags)
    if (escape && *p++ == ‘\0’)
    return Qfalse;

  •   break;
    
  • default:
    
  •   if (!FNM_SYSCASE && ISALPHA(c) && nocase)
    
  •   return Qtrue;
    

    }

@@ -1104,4 +1123,5 @@ ruby_glob(path, flags, func, arg)
VALUE arg;
{

  • flags |= FNM_SYSCASE;
    return glob_helper(path, 0, flags & ~GLOB_VERBOSE, func, arg);
    }
    @@ -1144,4 +1164,5 @@ rb_glob2(path, flags, func, arg)
    args.v = arg;

  • flags |= FNM_SYSCASE;
    return glob_helper(path, 0, flags | GLOB_VERBOSE, rb_glob_caller,
    (VALUE)&args);
    }
    @@ -1583,3 +1604,4 @@ Init_Dir()
    rb_file_const(“FNM_DOTMATCH”, INT2FIX(FNM_DOTMATCH));
    rb_file_const(“FNM_CASEFOLD”, INT2FIX(FNM_CASEFOLD));

  • rb_file_const(“FNM_SYSCASE”, INT2FIX(FNM_SYSCASE));
    }

13 wrote:

[email protected]:~/tmp$ ruby -v
ruby 1.8.4 (2005-12-24) [i486-linux]

Oddness…

$ touch file.txt
$ touch file.Txt
$ irb --simple-prompt

Dir.glob(’*.txt’,File::FNM_CASEFOLD)
=> [“file.txt”, “file.Txt”]

exit
$ touch README
$ irb --simple-prompt

Dir.glob(‘readme’,File::FNM_CASEFOLD)
=> []

T.

Hi,

In message “Re: File::FNM_CASEFOLD doesn’t work for Dir.glob?”
on Sat, 15 Jul 2006 00:31:13 +0900, [email protected] writes:

|> It’s no fun to have to do:
|>
|> Dir.glob(’[fF][oO][oO][dD][iI][rR]/*’)
|
|Seems nice to be backported from the trunk.

Yes, please.

						matz.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs