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"
22 tre_regncomp_l(regex_t
*preg
, const char *regex
, size_t n
, int cflags
,
30 wregex
= xmalloc(sizeof(tre_char_t
) * (n
+ 1));
36 /* If the current locale uses the standard single byte encoding of
37 characters, we don't do a multibyte string conversion. If we did,
38 many applications which use the default locale would break since
39 the default "C" locale uses the 7-bit ASCII character set, and
40 all characters with the eighth bit set would be considered invalid. */
42 if (TRE_MB_CUR_MAX_L(loc
) == 1)
43 #endif /* TRE_MULTIBYTE */
46 const unsigned char *str
= (const unsigned char *)regex
;
47 tre_char_t
*wstr
= wregex
;
49 for (i
= 0; i
< n
; i
++)
57 tre_char_t
*wcptr
= wregex
;
60 memset(&state
, '\0', sizeof(state
));
61 #endif /* HAVE_MBSTATE_T */
64 consumed
= tre_mbrtowc_l(wcptr
, regex
, n
, &state
, loc
);
79 DPRINT(("mbrtowc: error %d: %s.\n", errno
, strerror(errno
)));
87 wlen
= wcptr
- wregex
;
89 #endif /* TRE_MULTIBYTE */
92 ret
= tre_compile(preg
, wregex
, wlen
, cflags
, loc
);
94 #else /* !TRE_WCHAR */
96 ret
= tre_compile(preg
, (const tre_char_t
*)regex
, n
, cflags
, loc
);
97 #endif /* !TRE_WCHAR */
103 tre_regncomp(regex_t
*preg
, const char *regex
, size_t n
, int cflags
)
105 return tre_regncomp_l(preg
, regex
, n
, cflags
, __get_locale());
109 tre_regcomp_l(regex_t
*preg
, const char *regex
, int cflags
, locale_t loc
)
113 if (cflags
& REG_PEND
)
115 if ((const char *)(preg
->re_endp
) < regex
)
117 len
= (const char *)(preg
->re_endp
) - regex
;
121 return tre_regncomp_l(preg
, regex
, len
, cflags
, loc
);
125 tre_regcomp(regex_t
*preg
, const char *regex
, int cflags
)
127 return tre_regcomp_l(preg
, regex
, cflags
, __get_locale());
132 tre_regwncomp_l(regex_t
*preg
, const wchar_t *regex
, size_t n
, int cflags
,
136 return tre_compile(preg
, regex
, n
, cflags
, loc
);
140 tre_regwncomp(regex_t
*preg
, const wchar_t *regex
, size_t n
, int cflags
)
142 return tre_compile(preg
, regex
, n
, cflags
, __get_locale());
146 tre_regwcomp_l(regex_t
*preg
, const wchar_t *regex
, int cflags
, locale_t loc
)
149 return tre_compile(preg
, regex
, wcslen(regex
), cflags
, loc
);
153 tre_regwcomp(regex_t
*preg
, const wchar_t *regex
, int cflags
)
155 return tre_regwncomp(preg
, regex
, wcslen(regex
), cflags
);
157 #endif /* TRE_WCHAR */
160 tre_regfree(regex_t
*preg
)