Re: regexp character class locale awareness patch

From: Manuel Sugawara <masm(at)fciencias(dot)unam(dot)mx>
To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)atentus(dot)com>, peter_e(at)gmx(dot)net, t-ishii(at)sra(dot)co(dot)jp, pgsql-hackers(at)postgresql(dot)org
Subject: Re: regexp character class locale awareness patch
Date: 2002-04-17 23:15:56
Message-ID: m3u1q9dihf.fsf@dep4.fciencias.unam.mx
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:

> Alvaro Herrera wrote:
> > En Tue, 16 Apr 2002 19:21:50 -0400 (EDT)
> > Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> escribi?:
> >
> > > Here is a patch based on this discussion.
> >
> > I still think the xdigit class could be handled the same way the digit
> > class is (by enumeration rather than using the isxdigit function). That
> > saves you a cicle, and I don't think there's any loss.
>
> In fact, I will email you when I apply the original patch.

I miss that case :-(. Here is the pached patch.

Regards,
Manuel.

Index: src/backend/regex/regcomp.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/regex/regcomp.c,v
retrieving revision 1.28
diff -c -r1.28 regcomp.c
*** src/backend/regex/regcomp.c 28 Oct 2001 06:25:49 -0000 1.28
--- src/backend/regex/regcomp.c 16 Apr 2002 23:12:38 -0000
***************
*** 47,53 ****
#include "regex/regex.h"
#include "regex/utils.h"
#include "regex/regex2.h"
! #include "regex/cclass.h"
#include "regex/cname.h"

/*
--- 47,60 ----
#include "regex/regex.h"
#include "regex/utils.h"
#include "regex/regex2.h"
! struct cclass
! {
! char *name;
! char *chars;
! char *multis;
! };
! static struct cclass* cclasses = NULL;
! static struct cclass* cclass_init(void);
#include "regex/cname.h"

/*
***************
*** 174,179 ****
--- 181,189 ----
pg_wchar *wcp;
#endif

+ if ( cclasses == NULL )
+ cclasses = cclass_init();
+
#ifdef REDEBUG
#define GOODFLAGS(f) (f)
#else
***************
*** 884,890 ****
struct cclass *cp;
size_t len;
char *u;
! char c;

while (MORE() && pg_isalpha(PEEK()))
NEXT();
--- 894,900 ----
struct cclass *cp;
size_t len;
char *u;
! unsigned char c;

while (MORE() && pg_isalpha(PEEK()))
NEXT();
***************
*** 905,911 ****

u = cp->chars;
while ((c = *u++) != '\0')
! CHadd(cs, c);
for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
MCadd(p, cs, u);
}
--- 915,921 ----

u = cp->chars;
while ((c = *u++) != '\0')
! CHadd(cs, c);
for (u = cp->multis; *u != '\0'; u += strlen(u) + 1)
MCadd(p, cs, u);
}
***************
*** 1715,1718 ****
--- 1725,1788 ----
#else
return (islower((unsigned char) c));
#endif
+ }
+
+ static struct cclass *
+ cclass_init(void)
+ {
+ struct cclass *cp = NULL;
+ struct cclass *classes = NULL;
+ struct cclass_factory
+ {
+ char *name;
+ int (*func)(int);
+ char *chars;
+ } cclass_factories [] =
+ {
+ { "alnum", isalnum, NULL },
+ { "alpha", isalpha, NULL },
+ { "blank", NULL, " \t" },
+ { "cntrl", iscntrl, NULL },
+ { "digit", NULL, "0123456789" },
+ { "graph", isgraph, NULL },
+ { "lower", islower, NULL },
+ { "print", isprint, NULL },
+ { "punct", ispunct, NULL },
+ { "space", NULL, "\t\n\v\f\r " },
+ { "upper", isupper, NULL },
+ { "xdigit",NULL, "abcdefABCDEF0123456789" },
+ { NULL, NULL, NULL }
+ };
+ struct cclass_factory *cf = NULL;
+
+ classes = malloc(sizeof(struct cclass) * (sizeof(cclass_factories) / sizeof(struct cclass_factory)));
+ if (classes == NULL)
+ elog(ERROR,"cclass_init: out of memory");
+
+ cp = classes;
+ for(cf = cclass_factories; cf->name != NULL; cf++)
+ {
+ cp->name = strdup(cf->name);
+ if ( cf->chars )
+ cp->chars = strdup(cf->chars);
+ else
+ {
+ int x = 0, y = 0;
+ cp->chars = malloc(sizeof(char) * 256);
+ if (cp->chars == NULL)
+ elog(ERROR,"cclass_init: out of memory");
+ for (x = 0; x < 256; x++)
+ {
+ if((cf->func)(x))
+ *(cp->chars + y++) = x;
+ }
+ *(cp->chars + y) = '\0';
+ }
+ cp->multis = "";
+ cp++;
+ }
+ cp->name = cp->chars = NULL;
+ cp->multis = "";
+
+ return classes;
}

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dav Coleman 2002-04-17 23:28:54 SQL Query Optimization
Previous Message Bill Cunningham 2002-04-17 22:20:08 Re: Index Scans become Seq Scans after VACUUM ANALYSE