1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

ltree support for multibyte encodings. Patch was made by

laser <laserlist@pgsqldb.com> with some editorization by me.
This commit is contained in:
Teodor Sigaev
2008-06-30 18:30:48 +00:00
parent 995fb74202
commit 8eee65c996
5 changed files with 136 additions and 87 deletions

View File

@ -1,13 +1,14 @@
/*
* op function for ltree and lquery
* Teodor Sigaev <teodor@stack.net>
* $PostgreSQL: pgsql/contrib/ltree/lquery_op.c,v 1.12 2008/05/12 00:00:42 alvherre Exp $
* $PostgreSQL: pgsql/contrib/ltree/lquery_op.c,v 1.13 2008/06/30 18:30:48 teodor Exp $
*/
#include "postgres.h"
#include <ctype.h>
#include "utils/array.h"
#include "utils/formatting.h"
#include "ltree.h"
PG_FUNCTION_INFO_V1(ltq_regex);
@ -32,23 +33,24 @@ static char *
getlexeme(char *start, char *end, int *len)
{
char *ptr;
while (start < end && *start == '_')
start++;
int charlen;
while (start < end && (charlen = pg_mblen(start)) == 1 && t_iseq(start,'_') )
start += charlen;
ptr = start;
if (ptr == end)
if (ptr >= end)
return NULL;
while (ptr < end && *ptr != '_')
ptr++;
while (ptr < end && !( (charlen = pg_mblen(ptr)) == 1 && t_iseq(ptr, '_') ) )
ptr += charlen;
*len = ptr - start;
return start;
}
bool
compare_subnode(ltree_level * t, char *qn, int len, int (*cmpptr) (const char *, const char *, size_t), bool anyend)
compare_subnode(ltree_level * t, char *qn, int len, int (*cmpptr) (const char *, const char *, size_t), bool anyend)
{
char *endt = t->name + t->len;
char *endq = qn + len;
@ -85,6 +87,21 @@ bool
return true;
}
int
ltree_strncasecmp(const char *a, const char *b, size_t s)
{
char *al = str_tolower(a, s);
char *bl = str_tolower(b, s);
int res;
res = strncmp(al, bl,s);
pfree(al);
pfree(bl);
return res;
}
static bool
checkLevel(lquery_level * curq, ltree_level * curt)
{
@ -94,7 +111,7 @@ checkLevel(lquery_level * curq, ltree_level * curt)
for (i = 0; i < curq->numvar; i++)
{
cmpptr = (curvar->flag & LVAR_INCASE) ? pg_strncasecmp : strncmp;
cmpptr = (curvar->flag & LVAR_INCASE) ? ltree_strncasecmp : strncmp;
if (curvar->flag & LVAR_SUBLEXEME)
{