On Jan 28, 2016 01:23, "Tony Mechelynck" <[email protected]> wrote: > > On Thu, Jan 28, 2016 at 6:25 AM, Justin M. Keyes <[email protected]> wrote: > > On Wed, Jan 27, 2016 at 11:40 PM, Tony Mechelynck > > <[email protected]> wrote: > >> On Thu, Jan 28, 2016 at 4:45 AM, Justin M. Keyes < [email protected]> > >> wrote: > >>> > >>> glob2regpat("") returns "^$", but that not the regex equivalent of an > >>> empty wildcard pattern. It should probably return empty string instead. > >>> Here's a patch: > >>> > >>> diff --git a/src/eval.c b/src/eval.c > >>> index 5f05c3d..b68d086 100644 > >>> --- a/src/eval.c > >>> +++ b/src/eval.c > >>> @@ -12993,7 +12993,7 @@ f_glob2regpat(argvars, rettv) > >>> char_u> *pat = get_tv_string_chk(&argvars[0]); > >>> - > >>> rettv->v_type = VAR_STRING; > >>> - rettv->vval.v_string = (pat == NULL) > >>> + rettv->vval.v_string = (pat == NULL || *pat == NUL) > >>> > > > ? NULL : file_pat_to_reg_pat(pat, NULL, NULL, > >>> FALSE); > >>> } > >>> > >>> > >> An empty regpat matches everywhere. > > > > Yes. Why wouldn't an empty glob pattern be interpreted as an empty > > regex pattern? > > > >> When matching a string (as in "if string_var =~# pattern_var | DoSomething | > >> else | DoSomethingElse | endif"), in order to match an empty string you need > > > > You mean an empty *line*. That's very different than an empty string, > > and I don't see how an empty glob pattern would imply that only empty > > lines should be matched. > > > > I'm not intending to be pedantic, but this should at least be > > documented if it's intended. > > > > I mean an empty _string_, not an empty line. When matching against a > string by means, for example, of the ~=# operator mentioned in my > previous post, the ^ pattern-item means "start of string" and the $ > pattern-item means "end of string". And the glob wildcard to match > anything is not "", remember, but * on Linux or *.* on MS-DOS. "" as a > glob wildcard matches only an empty name. > > If you had read the help text for the glob2regpat() function you > mentioned, you would have noticed that it _is_ mentioned. Just look at > the example, where the resulting regexp pattern is bracketed by ^ and > $, as follows: > > glob2regpat({expr}) *glob2regpat()* > Convert a file pattern, as used by glob(), into a search > pattern. The result can be used to match with a string that > is a file name. E.g. > > if filename =~ glob2regpat('Make*.mak') > < This is equivalent to: > > if filename =~ '^Make.*\.mak$' > > Without these bracketing "anchoring" items, the pattern "Make.*\.mak" > would also match, let's say, "FakeOrMakeOrBreak.maktakbak", which is > not matched by the glob pattern "Make*.mak".
I did read the help, it doesn't mention empty wildcard. But after more reflection, I now understand that empty regex would not be equivalent to typical behavior of, say, "find" where glob pattern is omitted. -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
