diff options
Diffstat (limited to 'contrib/tsearch2/ts_locale.c')
| -rw-r--r-- | contrib/tsearch2/ts_locale.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/contrib/tsearch2/ts_locale.c b/contrib/tsearch2/ts_locale.c index 5dc67abc8d..29c07c0eab 100644 --- a/contrib/tsearch2/ts_locale.c +++ b/contrib/tsearch2/ts_locale.c @@ -5,7 +5,9 @@ #include "mb/pg_wchar.h" -#if defined(TS_USE_WIDE) && defined(WIN32) +#ifdef TS_USE_WIDE + +#ifdef WIN32 size_t wchar2char(char *to, const wchar_t *from, size_t len) @@ -69,4 +71,59 @@ char2wchar(wchar_t *to, const char *from, size_t len) return mbstowcs(to, from, len); } +#endif /* WIN32 */ + +int +_t_isalpha( char *ptr ) { + wchar_t character; + + char2wchar(&character, ptr, 1); + + return iswalpha( (wint_t)character ); +} + +int +_t_isprint( char *ptr ) { + wchar_t character; + + char2wchar(&character, ptr, 1); + + return iswprint( (wint_t)character ); +} + +#endif /* TS_USE_WIDE */ + +char * +lowerstr(char *str) +{ + char *ptr = str; + +#ifdef TS_USE_WIDE + /* + * Use wide char code only when max encoding length > 1 and ctype != C. + * Some operating systems fail with multi-byte encodings and a C locale. + * Also, for a C locale there is no need to process as multibyte. From + * backend/utils/adt/oracle_compat.c Teodor + */ + if (pg_database_encoding_max_length() > 1 && !lc_ctype_is_c()) { + wchar_t *wstr, *wptr; + int len = strlen(str); + + wptr = wstr = (wchar_t *) palloc(sizeof(wchar_t) * (len+1)); + char2wchar(wstr, str, len+1); + while (*wptr) { + *wptr = towlower((wint_t) *wptr); + wptr++; + } + wchar2char(str, wstr, len); + pfree( wstr ); + } else #endif + while (*ptr) + { + *ptr = tolower(*(unsigned char *) ptr); + ptr++; + } + return str; +} + |
