]>
git.saurik.com Git - apple/libc.git/blob - regex/TRE/lib/regcomp.c
2 tre_regcomp.c - TRE POSIX compatible regex compilation functions.
4 This software is released under a BSD-style license.
5 See the file LICENSE for details and copyright.
11 #endif /* HAVE_CONFIG_H */
18 #include "tre-internal.h"
21 #ifndef BUILDING_VARIANT
23 tre_regncomp_l(regex_t
*preg
, const char *regex
, size_t n
, int cflags
, locale_t loc
)
30 wregex
= xmalloc(sizeof(tre_char_t
) * (n
+ 1));
34 NORMALIZE_LOCALE(loc
);
37 /* If the current locale uses the standard single byte encoding of
38 characters, we don't do a multibyte string conversion. If we did,
39 many applications which use the default locale would break since
40 the default "C" locale uses the 7-bit ASCII character set, and
41 all characters with the eighth bit set would be considered invalid. */
43 if (TRE_MB_CUR_MAX_L(loc
) == 1)
44 #endif /* TRE_MULTIBYTE */
47 const unsigned char *str
= (const unsigned char *)regex
;
48 tre_char_t
*wstr
= wregex
;
50 for (i
= 0; i
< n
; i
++)
58 tre_char_t
*wcptr
= wregex
;
61 memset(&state
, '\0', sizeof(state
));
62 #endif /* HAVE_MBSTATE_T */
65 consumed
= tre_mbrtowc_l(wcptr
, regex
, n
, &state
, loc
);
80 DPRINT(("mbrtowc: error %d: %s.\n", errno
, strerror(errno
)));
88 wlen
= wcptr
- wregex
;
90 #endif /* TRE_MULTIBYTE */
93 ret
= tre_compile(preg
, wregex
, wlen
, cflags
, loc
);
95 #else /* !TRE_WCHAR */
97 NORMALIZE_LOCALE(loc
);
100 ret
= tre_compile(preg
, (const tre_char_t
*)regex
, n
, cflags
, loc
);
101 #endif /* !TRE_WCHAR */
107 tre_regncomp(regex_t
*preg
, const char *regex
, size_t n
, int cflags
)
112 loc
= __current_locale();
113 #else /* !__LIBC__ */
114 loc
= duplocale(NULL
);
115 if (!loc
) return REG_ESPACE
;
116 #endif /* !__LIBC__ */
118 return tre_regncomp_l(preg
, regex
, n
, cflags
, loc
);
122 tre_regcomp_l(regex_t
*preg
, const char *regex
, int cflags
, locale_t loc
)
126 if (cflags
& REG_PEND
)
128 if ((const char *)(preg
->re_endp
) < regex
)
130 len
= (const char *)(preg
->re_endp
) - regex
;
134 return tre_regncomp_l(preg
, regex
, len
, cflags
, loc
);
136 #endif /* !BUILDING_VARIANT */
139 tre_regcomp(regex_t
*preg
, const char *regex
, int cflags
)
144 loc
= __current_locale();
145 #else /* !__LIBC__ */
146 loc
= duplocale(NULL
);
147 if (!loc
) return REG_ESPACE
;
148 #endif /* !__LIBC__ */
150 return tre_regcomp_l(preg
, regex
, cflags
, loc
);
154 #ifndef BUILDING_VARIANT
157 tre_regwncomp_l(regex_t
*preg
, const wchar_t *regex
, size_t n
, int cflags
, locale_t loc
)
160 NORMALIZE_LOCALE(loc
);
161 #endif /* __LIBC__ */
162 return tre_compile(preg
, regex
, n
, cflags
, loc
);
166 tre_regwncomp(regex_t
*preg
, const wchar_t *regex
, size_t n
, int cflags
)
171 loc
= __current_locale();
172 #else /* !__LIBC__ */
173 loc
= duplocale(NULL
);
174 if (!loc
) return REG_ESPACE
;
175 #endif /* !__LIBC__ */
177 return tre_compile(preg
, regex
, n
, cflags
, loc
);
181 tre_regwcomp_l(regex_t
*preg
, const wchar_t *regex
, int cflags
, locale_t loc
)
184 NORMALIZE_LOCALE(loc
);
185 #endif /* __LIBC__ */
186 return tre_compile(preg
, regex
, wcslen(regex
), cflags
, loc
);
190 tre_regwcomp(regex_t
*preg
, const wchar_t *regex
, int cflags
)
192 return tre_regwncomp(preg
, regex
, wcslen(regex
), cflags
);
194 #endif /* TRE_WCHAR */
197 tre_regfree(regex_t
*preg
)
201 #endif /* !BUILDING_VARIANT */