[jit] Add support for constrained calls with vtype return types in gsharedvt code...
[mono.git] / mono / wrapper / glob.c
1 /*
2  * glob.c: Simple glob support for the class libraries
3  *
4  * Author:
5  *   Miguel de Icaza (miguel@ximian.com).
6  *
7  * (C) 2002 Ximian, Inc.
8  */
9 #include <sys/types.h>
10 #include <glib.h>
11 #include <config.h>
12 #include <regex.h>
13 #include "wrapper.h"
14
15 gpointer
16 mono_glob_compile (const char *glob)
17 {
18         regex_t *compiled = g_new (regex_t, 1);
19         GString *str = g_string_new ("^");
20         const char *p;
21         
22         for (p = glob; *p; p++){
23                 switch (*p){
24                 case '?':
25                         g_string_append_c (str, '.');
26                         break;
27                 case '*':
28                         g_string_append (str, ".*");
29                         break;
30                         
31                 case '[': case ']': case '\\': case '(': case ')':
32                 case '^': case '$': case '.':
33                         g_string_append_c (str, '\\');
34                         /* fall */
35                 default:
36                         g_string_append_c (str, *p);
37                 }
38         }
39         g_string_append_c (str, '$');
40         regcomp (compiled, str->str, 0);
41
42         return compiled;
43 }
44
45 int
46 mono_glob_match (gpointer handle, const char *str)
47 {
48         regex_t *compiled = (regex_t *) handle;
49
50         return regexec (compiled, str, 0, NULL, 0) == 0;
51 }
52
53 void
54 mono_glob_dispose (gpointer handle)
55 {
56         regfree ((regex_t *) handle);
57 }