Alvaro Herrera wrote:
> Bruce Momjian wrote:
>
> > I moved str_initcap() over into oracle_compat.c and then had initcap()
> > convert to/from TEXT to call it. The code is a little weird because
> > str_initcap() needs to convert to text to use texttowcs(), so in
> > multibyte encodings initcap converts the string to text, then to char,
> > then to text to call texttowcs(). I didn't see a cleaner way to do
> > this.
>
> Why not use wchar2char? It seems there's room for extra cleanup here.
>
> Also, the prototype of str_initcap in builtins.h looks out of place.
I talked to Alvaro on IM, and there is certainly much more cleanup to do
in this area. I will work from the bottom up. First, is moving the
USE_WIDE_UPPER_LOWER define to c.h, and removing TS_USE_WIDE and using
USE_WIDE_UPPER_LOWER instead. Patch attached and applied.
--
Bruce Momjian <[EMAIL PROTECTED]> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ If your life is a hard drive, Christ can be your backup. +
Index: src/backend/tsearch/regis.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/tsearch/regis.c,v
retrieving revision 1.4
diff -c -c -r1.4 regis.c
*** src/backend/tsearch/regis.c 21 Jan 2008 02:46:10 -0000 1.4
--- src/backend/tsearch/regis.c 17 Jun 2008 16:06:54 -0000
***************
*** 178,184 ****
r->node = NULL;
}
! #ifdef TS_USE_WIDE
static bool
mb_strchr(char *str, char *c)
{
--- 178,184 ----
r->node = NULL;
}
! #ifdef USE_WIDE_UPPER_LOWER
static bool
mb_strchr(char *str, char *c)
{
Index: src/backend/tsearch/ts_locale.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/tsearch/ts_locale.c,v
retrieving revision 1.7
diff -c -c -r1.7 ts_locale.c
*** src/backend/tsearch/ts_locale.c 1 Jan 2008 19:45:52 -0000 1.7
--- src/backend/tsearch/ts_locale.c 17 Jun 2008 16:06:54 -0000
***************
*** 17,23 ****
#include "tsearch/ts_public.h"
! #ifdef TS_USE_WIDE
/*
* wchar2char --- convert wide characters to multibyte format
--- 17,23 ----
#include "tsearch/ts_public.h"
! #ifdef USE_WIDE_UPPER_LOWER
/*
* wchar2char --- convert wide characters to multibyte format
***************
*** 190,196 ****
return iswprint((wint_t) character[0]);
}
! #endif /* TS_USE_WIDE */
/*
--- 190,196 ----
return iswprint((wint_t) character[0]);
}
! #endif /* USE_WIDE_UPPER_LOWER */
/*
***************
*** 260,266 ****
if (len == 0)
return pstrdup("");
! #ifdef TS_USE_WIDE
/*
* Use wide char code only when max encoding length > 1 and ctype != C.
--- 260,266 ----
if (len == 0)
return pstrdup("");
! #ifdef USE_WIDE_UPPER_LOWER
/*
* Use wide char code only when max encoding length > 1 and ctype != C.
***************
*** 307,313 ****
Assert(wlen < len);
}
else
! #endif /* TS_USE_WIDE */
{
const char *ptr = str;
char *outptr;
--- 307,313 ----
Assert(wlen < len);
}
else
! #endif /* USE_WIDE_UPPER_LOWER */
{
const char *ptr = str;
char *outptr;
Index: src/backend/tsearch/wparser_def.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/tsearch/wparser_def.c,v
retrieving revision 1.14
diff -c -c -r1.14 wparser_def.c
*** src/backend/tsearch/wparser_def.c 1 Jan 2008 19:45:52 -0000 1.14
--- src/backend/tsearch/wparser_def.c 17 Jun 2008 16:06:54 -0000
***************
*** 238,244 ****
/* string and position information */
char *str; /* multibyte string */
int lenstr; /* length of mbstring */
! #ifdef TS_USE_WIDE
wchar_t *wstr; /* wide character string */
int lenwstr; /* length of wsting */
#endif
--- 238,244 ----
/* string and position information */
char *str; /* multibyte string */
int lenstr; /* length of mbstring */
! #ifdef USE_WIDE_UPPER_LOWER
wchar_t *wstr; /* wide character string */
int lenwstr; /* length of wsting */
#endif
***************
*** 291,297 ****
prs->str = str;
prs->lenstr = len;
! #ifdef TS_USE_WIDE
/*
* Use wide char code only when max encoding length > 1.
--- 291,297 ----
prs->str = str;
prs->lenstr = len;
! #ifdef USE_WIDE_UPPER_LOWER
/*
* Use wide char code only when max encoding length > 1.
***************
*** 328,334 ****
prs->state = ptr;
}
! #ifdef TS_USE_WIDE
if (prs->wstr)
pfree(prs->wstr);
#endif
--- 328,334 ----
prs->state = ptr;
}
! #ifdef USE_WIDE_UPPER_LOWER
if (prs->wstr)
pfree(prs->wstr);
#endif
***************
*** 344,350 ****
* often are used for Asian languages
*/
! #ifdef TS_USE_WIDE
#define p_iswhat(type) \
static int \
--- 344,350 ----
* often are used for Asian languages
*/
! #ifdef USE_WIDE_UPPER_LOWER
#define p_iswhat(type) \
static int \
***************
*** 439,445 ****
Assert(prs->state);
return ((prs->state->charlen == 1 && *(prs->str + prs->state->posbyte) == c)) ? 1 : 0;
}
! #else /* TS_USE_WIDE */
#define p_iswhat(type) \
static int \
--- 439,445 ----
Assert(prs->state);
return ((prs->state->charlen == 1 && *(prs->str + prs->state->posbyte) == c)) ? 1 : 0;
}
! #else /* USE_WIDE_UPPER_LOWER */
#define p_iswhat(type) \
static int \
***************
*** 463,469 ****
p_iswhat(alnum)
p_iswhat(alpha)
! #endif /* TS_USE_WIDE */
p_iswhat(digit)
p_iswhat(lower)
--- 463,469 ----
p_iswhat(alnum)
p_iswhat(alpha)
! #endif /* USE_WIDE_UPPER_LOWER */
p_iswhat(digit)
p_iswhat(lower)
Index: src/backend/utils/adt/formatting.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/formatting.c,v
retrieving revision 1.141
diff -c -c -r1.141 formatting.c
*** src/backend/utils/adt/formatting.c 20 May 2008 01:41:02 -0000 1.141
--- src/backend/utils/adt/formatting.c 17 Jun 2008 16:06:54 -0000
***************
*** 948,955 ****
static NUMCacheEntry *NUM_cache_getnew(char *str);
static void NUM_cache_remove(NUMCacheEntry *ent);
! #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
! #define USE_WIDE_UPPER_LOWER
/* externs are in oracle_compat.c */
extern char *wstring_upper(char *str);
extern char *wstring_lower(char *str);
--- 948,954 ----
static NUMCacheEntry *NUM_cache_getnew(char *str);
static void NUM_cache_remove(NUMCacheEntry *ent);
! #ifdef USE_WIDE_UPPER_LOWER
/* externs are in oracle_compat.c */
extern char *wstring_upper(char *str);
extern char *wstring_lower(char *str);
Index: src/backend/utils/adt/oracle_compat.c
===================================================================
RCS file: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v
retrieving revision 1.79
diff -c -c -r1.79 oracle_compat.c
*** src/backend/utils/adt/oracle_compat.c 19 May 2008 18:08:16 -0000 1.79
--- src/backend/utils/adt/oracle_compat.c 17 Jun 2008 16:06:54 -0000
***************
*** 40,51 ****
* functions, which of course will not work as desired in multibyte character
* sets. Note that in either case we are effectively assuming that the
* database character encoding matches the encoding implied by LC_CTYPE.
- *
- * We assume if we have these two functions, we have their friends too, and
- * can use the wide-character method.
*/
! #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
! #define USE_WIDE_UPPER_LOWER
char *wstring_lower(char *str);
char *wstring_upper(char *str);
wchar_t *texttowcs(const text *txt);
--- 40,47 ----
* functions, which of course will not work as desired in multibyte character
* sets. Note that in either case we are effectively assuming that the
* database character encoding matches the encoding implied by LC_CTYPE.
*/
! #ifdef USE_WIDE_UPPER_LOWER
char *wstring_lower(char *str);
char *wstring_upper(char *str);
wchar_t *texttowcs(const text *txt);
Index: src/include/c.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/c.h,v
retrieving revision 1.226
diff -c -c -r1.226 c.h
*** src/include/c.h 21 Apr 2008 00:26:46 -0000 1.226
--- src/include/c.h 17 Jun 2008 16:06:55 -0000
***************
*** 813,818 ****
--- 813,826 ----
#define HAVE_STRTOULL 1
#endif
+ /*
+ * We assume if we have these two functions, we have their friends too, and
+ * can use the wide-character functions.
+ */
+ #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
+ #define USE_WIDE_UPPER_LOWER
+ #endif
+
/* EXEC_BACKEND defines */
#ifdef EXEC_BACKEND
#define NON_EXEC_STATIC
Index: src/include/tsearch/ts_locale.h
===================================================================
RCS file: /cvsroot/pgsql/src/include/tsearch/ts_locale.h,v
retrieving revision 1.5
diff -c -c -r1.5 ts_locale.h
*** src/include/tsearch/ts_locale.h 1 Jan 2008 19:45:59 -0000 1.5
--- src/include/tsearch/ts_locale.h 17 Jun 2008 16:06:55 -0000
***************
*** 29,41 ****
#include <wctype.h>
#endif
- #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
- #define TS_USE_WIDE
- #endif
-
#define TOUCHAR(x) (*((const unsigned char *) (x)))
! #ifdef TS_USE_WIDE
extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen);
extern size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen);
--- 29,37 ----
#include <wctype.h>
#endif
#define TOUCHAR(x) (*((const unsigned char *) (x)))
! #ifdef USE_WIDE_UPPER_LOWER
extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen);
extern size_t char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen);
***************
*** 49,55 ****
#define t_iseq(x,c) (TOUCHAR(x) == (unsigned char) (c))
#define COPYCHAR(d,s) memcpy(d, s, pg_mblen(s))
! #else /* not TS_USE_WIDE */
#define t_isdigit(x) isdigit(TOUCHAR(x))
#define t_isspace(x) isspace(TOUCHAR(x))
--- 45,51 ----
#define t_iseq(x,c) (TOUCHAR(x) == (unsigned char) (c))
#define COPYCHAR(d,s) memcpy(d, s, pg_mblen(s))
! #else /* not USE_WIDE_UPPER_LOWER */
#define t_isdigit(x) isdigit(TOUCHAR(x))
#define t_isspace(x) isspace(TOUCHAR(x))
***************
*** 58,64 ****
#define t_iseq(x,c) (TOUCHAR(x) == (unsigned char) (c))
#define COPYCHAR(d,s) (*((unsigned char *) (d)) = TOUCHAR(s))
! #endif /* TS_USE_WIDE */
extern char *lowerstr(const char *str);
extern char *lowerstr_with_len(const char *str, int len);
--- 54,60 ----
#define t_iseq(x,c) (TOUCHAR(x) == (unsigned char) (c))
#define COPYCHAR(d,s) (*((unsigned char *) (d)) = TOUCHAR(s))
! #endif /* USE_WIDE_UPPER_LOWER */
extern char *lowerstr(const char *str);
extern char *lowerstr_with_len(const char *str, int len);
--
Sent via pgsql-patches mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-patches