cvs: /php3/functions pcre.c php3_pcre.h
| From: | Andrey Zmievski | Date: | Tue, 20 Jul 1999 17:08:05 +0000 |
| Subject: | cvs: /php3/functions pcre.c php3_pcre.h | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-8811@lists.php.net to get a copy of this message | ||
andrey Tue Jul 20 17:08:05 1999 EDT
Modified files:
/php3/functions pcre.c php3_pcre.h
Log:
Added locale support.
Index: php3/functions/pcre.c
diff -u php3/functions/pcre.c:1.11 php3/functions/pcre.c:1.12
--- php3/functions/pcre.c:1.11 Fri Jun 25 18:08:14 1999
+++ php3/functions/pcre.c Tue Jul 20 17:08:05 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: pcre.c,v 1.11 1999/06/25 22:08:14 andrey Exp $ */
+/* $Id: pcre.c,v 1.12 1999/07/20 21:08:05 andrey Exp $ */
#include "php.h"
@@ -76,6 +76,9 @@
{
pcre_cache_entry *pce = (pcre_cache_entry *) data;
pefree(pce->re, 1);
+#if HAVE_SETLOCALE
+ pefree((void*)pce->tables, 1);
+#endif
}
/* {{{ void php_info_pcre(_php3_MODULE_INFO_FUNC_ARGS) */
@@ -124,25 +127,35 @@
/* {{{ static pcre* _pcre_get_compiled_regex(char *regex, pcre_extra *extra) */
static pcre* _pcre_get_compiled_regex(char *regex, pcre_extra *extra) {
- pcre *re = NULL;
- int coptions = 0;
- int soptions = 0;
- const char *error;
- int erroffset;
- char delimiter;
- char *p, *pp;
- char *pattern;
- int regex_len;
- int do_study = 0;
+ pcre *re = NULL;
+ int coptions = 0;
+ int soptions = 0;
+ const char *error;
+ int erroffset;
+ char delimiter;
+ char *p, *pp;
+ char *pattern;
+ int regex_len;
+ int do_study = 0;
+ unsigned const char *tables = NULL;
+#if HAVE_SETLOCALE
+ char *locale = setlocale(LC_CTYPE, NULL);
+#endif
pcre_cache_entry *pce;
- pcre_cache_entry new_entry;
+ pcre_cache_entry new_entry;
/* Try to lookup the cached regex entry, and if successful, just pass
back the compiled pattern, otherwise go on and compile it. */
regex_len = strlen(regex);
if (_php3_hash_find(&pcre_cache, regex, regex_len+1, (void **)&pce) == SUCCESS) {
- extra = pce->extra;
- return pce->re;
+#if HAVE_SETLOCALE
+ if (!strcmp(pce->locale, locale)) {
+#endif
+ extra = pce->extra;
+ return pce->re;
+#if HAVE_SETLOCALE
+ }
+#endif
}
p = regex;
@@ -209,12 +222,17 @@
}
}
+#if HAVE_SETLOCALE
+ if (strcmp(locale, "C"))
+ tables = pcre_maketables();
+#endif
+
/* Compile pattern and display a warning if compilation failed. */
re = pcre_compile(pattern,
coptions,
&error,
&erroffset,
- NULL);
+ tables);
if (re == NULL) {
php3_error(E_WARNING, "Compilation failed: %s at offset %d\n", error, erroffset);
@@ -236,6 +254,10 @@
/* Store the compiled pattern and extra info in the cache. */
new_entry.re = re;
new_entry.extra = extra;
+#if HAVE_SETLOCALE
+ new_entry.locale = locale;
+ new_entry.tables = tables;
+#endif
_php3_hash_update(&pcre_cache, regex, regex_len+1, (void *)&new_entry,
sizeof(pcre_cache_entry), NULL);
Index: php3/functions/php3_pcre.h
diff -u php3/functions/php3_pcre.h:1.4 php3/functions/php3_pcre.h:1.5
--- php3/functions/php3_pcre.h:1.4 Fri Jun 4 10:03:33 1999
+++ php3/functions/php3_pcre.h Tue Jul 20 17:08:05 1999
@@ -27,7 +27,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php3_pcre.h,v 1.4 1999/06/04 14:03:33 andrey Exp $ */
+/* $Id: php3_pcre.h,v 1.5 1999/07/20 21:08:05 andrey Exp $ */
#ifndef _PHP_PCRE_H
#define _PHP_PCRE_H
@@ -38,6 +38,9 @@
#include "internal_functions.h"
#include "pcrelib/pcre.h"
+#if HAVE_LOCALE_H
+#include <locale.h>
+#endif
extern void php_info_pcre(void);
extern int php_minit_pcre(INIT_FUNC_ARGS);
@@ -56,6 +59,10 @@
typedef struct {
pcre *re;
pcre_extra *extra;
+#if HAVE_SETLOCALE
+ char *locale;
+ unsigned const char *tables;
+#endif
} pcre_cache_entry;
HashTable pcre_cache;