mirror of
https://github.com/postgres/postgres.git
synced 2025-07-20 05:03:10 +03:00
Change wchar2char() and char2wchar() to accept a locale_t.
These are libc-specific functions, so should require a locale_t rather than a pg_locale_t (which could use another provider). Discussion: https://postgr.es/m/a8666c391dfcabe79868d95f7160eac533ace718.camel%40j-davis.com
This commit is contained in:
@ -36,7 +36,7 @@ t_isalpha(const char *ptr)
|
|||||||
{
|
{
|
||||||
int clen = pg_mblen(ptr);
|
int clen = pg_mblen(ptr);
|
||||||
wchar_t character[WC_BUF_LEN];
|
wchar_t character[WC_BUF_LEN];
|
||||||
pg_locale_t mylocale = 0; /* TODO */
|
locale_t mylocale = 0; /* TODO */
|
||||||
|
|
||||||
if (clen == 1 || database_ctype_is_c)
|
if (clen == 1 || database_ctype_is_c)
|
||||||
return isalpha(TOUCHAR(ptr));
|
return isalpha(TOUCHAR(ptr));
|
||||||
@ -51,7 +51,7 @@ t_isalnum(const char *ptr)
|
|||||||
{
|
{
|
||||||
int clen = pg_mblen(ptr);
|
int clen = pg_mblen(ptr);
|
||||||
wchar_t character[WC_BUF_LEN];
|
wchar_t character[WC_BUF_LEN];
|
||||||
pg_locale_t mylocale = 0; /* TODO */
|
locale_t mylocale = 0; /* TODO */
|
||||||
|
|
||||||
if (clen == 1 || database_ctype_is_c)
|
if (clen == 1 || database_ctype_is_c)
|
||||||
return isalnum(TOUCHAR(ptr));
|
return isalnum(TOUCHAR(ptr));
|
||||||
|
@ -299,7 +299,7 @@ TParserInit(char *str, int len)
|
|||||||
*/
|
*/
|
||||||
if (prs->charmaxlen > 1)
|
if (prs->charmaxlen > 1)
|
||||||
{
|
{
|
||||||
pg_locale_t mylocale = 0; /* TODO */
|
locale_t mylocale = 0; /* TODO */
|
||||||
|
|
||||||
prs->usewide = true;
|
prs->usewide = true;
|
||||||
if (database_ctype_is_c)
|
if (database_ctype_is_c)
|
||||||
|
@ -457,7 +457,7 @@ strlower_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
|
|||||||
/* Output workspace cannot have more codes than input bytes */
|
/* Output workspace cannot have more codes than input bytes */
|
||||||
workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
|
workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
|
||||||
|
|
||||||
char2wchar(workspace, srclen + 1, src, srclen, locale);
|
char2wchar(workspace, srclen + 1, src, srclen, loc);
|
||||||
|
|
||||||
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
|
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
|
||||||
workspace[curr_char] = towlower_l(workspace[curr_char], loc);
|
workspace[curr_char] = towlower_l(workspace[curr_char], loc);
|
||||||
@ -468,7 +468,7 @@ strlower_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
|
|||||||
max_size = curr_char * pg_database_encoding_max_length();
|
max_size = curr_char * pg_database_encoding_max_length();
|
||||||
result = palloc(max_size + 1);
|
result = palloc(max_size + 1);
|
||||||
|
|
||||||
result_size = wchar2char(result, workspace, max_size + 1, locale);
|
result_size = wchar2char(result, workspace, max_size + 1, loc);
|
||||||
|
|
||||||
if (result_size + 1 > destsize)
|
if (result_size + 1 > destsize)
|
||||||
return result_size;
|
return result_size;
|
||||||
@ -552,7 +552,7 @@ strtitle_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
|
|||||||
/* Output workspace cannot have more codes than input bytes */
|
/* Output workspace cannot have more codes than input bytes */
|
||||||
workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
|
workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
|
||||||
|
|
||||||
char2wchar(workspace, srclen + 1, src, srclen, locale);
|
char2wchar(workspace, srclen + 1, src, srclen, loc);
|
||||||
|
|
||||||
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
|
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
|
||||||
{
|
{
|
||||||
@ -569,7 +569,7 @@ strtitle_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
|
|||||||
max_size = curr_char * pg_database_encoding_max_length();
|
max_size = curr_char * pg_database_encoding_max_length();
|
||||||
result = palloc(max_size + 1);
|
result = palloc(max_size + 1);
|
||||||
|
|
||||||
result_size = wchar2char(result, workspace, max_size + 1, locale);
|
result_size = wchar2char(result, workspace, max_size + 1, loc);
|
||||||
|
|
||||||
if (result_size + 1 > destsize)
|
if (result_size + 1 > destsize)
|
||||||
return result_size;
|
return result_size;
|
||||||
@ -640,7 +640,7 @@ strupper_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
|
|||||||
/* Output workspace cannot have more codes than input bytes */
|
/* Output workspace cannot have more codes than input bytes */
|
||||||
workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
|
workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
|
||||||
|
|
||||||
char2wchar(workspace, srclen + 1, src, srclen, locale);
|
char2wchar(workspace, srclen + 1, src, srclen, loc);
|
||||||
|
|
||||||
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
|
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
|
||||||
workspace[curr_char] = towupper_l(workspace[curr_char], loc);
|
workspace[curr_char] = towupper_l(workspace[curr_char], loc);
|
||||||
@ -651,7 +651,7 @@ strupper_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
|
|||||||
max_size = curr_char * pg_database_encoding_max_length();
|
max_size = curr_char * pg_database_encoding_max_length();
|
||||||
result = palloc(max_size + 1);
|
result = palloc(max_size + 1);
|
||||||
|
|
||||||
result_size = wchar2char(result, workspace, max_size + 1, locale);
|
result_size = wchar2char(result, workspace, max_size + 1, loc);
|
||||||
|
|
||||||
if (result_size + 1 > destsize)
|
if (result_size + 1 > destsize)
|
||||||
return result_size;
|
return result_size;
|
||||||
@ -1130,7 +1130,7 @@ wcstombs_l(char *dest, const wchar_t *src, size_t n, locale_t loc)
|
|||||||
* zero-terminated. The output will be zero-terminated iff there is room.
|
* zero-terminated. The output will be zero-terminated iff there is room.
|
||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
|
wchar2char(char *to, const wchar_t *from, size_t tolen, locale_t loc)
|
||||||
{
|
{
|
||||||
size_t result;
|
size_t result;
|
||||||
|
|
||||||
@ -1160,7 +1160,7 @@ wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
if (locale == (pg_locale_t) 0)
|
if (loc == (locale_t) 0)
|
||||||
{
|
{
|
||||||
/* Use wcstombs directly for the default locale */
|
/* Use wcstombs directly for the default locale */
|
||||||
result = wcstombs(to, from, tolen);
|
result = wcstombs(to, from, tolen);
|
||||||
@ -1168,7 +1168,7 @@ wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Use wcstombs_l for nondefault locales */
|
/* Use wcstombs_l for nondefault locales */
|
||||||
result = wcstombs_l(to, from, tolen, locale->info.lt);
|
result = wcstombs_l(to, from, tolen, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -1185,7 +1185,7 @@ wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
|
|||||||
*/
|
*/
|
||||||
size_t
|
size_t
|
||||||
char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen,
|
char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen,
|
||||||
pg_locale_t locale)
|
locale_t loc)
|
||||||
{
|
{
|
||||||
size_t result;
|
size_t result;
|
||||||
|
|
||||||
@ -1220,7 +1220,7 @@ char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen,
|
|||||||
/* mbstowcs requires ending '\0' */
|
/* mbstowcs requires ending '\0' */
|
||||||
char *str = pnstrdup(from, fromlen);
|
char *str = pnstrdup(from, fromlen);
|
||||||
|
|
||||||
if (locale == (pg_locale_t) 0)
|
if (loc == (locale_t) 0)
|
||||||
{
|
{
|
||||||
/* Use mbstowcs directly for the default locale */
|
/* Use mbstowcs directly for the default locale */
|
||||||
result = mbstowcs(to, str, tolen);
|
result = mbstowcs(to, str, tolen);
|
||||||
@ -1228,7 +1228,7 @@ char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Use mbstowcs_l for nondefault locales */
|
/* Use mbstowcs_l for nondefault locales */
|
||||||
result = mbstowcs_l(to, str, tolen, locale->info.lt);
|
result = mbstowcs_l(to, str, tolen, loc);
|
||||||
}
|
}
|
||||||
|
|
||||||
pfree(str);
|
pfree(str);
|
||||||
|
@ -214,8 +214,8 @@ extern void report_newlocale_failure(const char *localename);
|
|||||||
|
|
||||||
/* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
|
/* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
|
||||||
extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
|
extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
|
||||||
pg_locale_t locale);
|
locale_t loc);
|
||||||
extern size_t char2wchar(wchar_t *to, size_t tolen,
|
extern size_t char2wchar(wchar_t *to, size_t tolen,
|
||||||
const char *from, size_t fromlen, pg_locale_t locale);
|
const char *from, size_t fromlen, locale_t loc);
|
||||||
|
|
||||||
#endif /* _PG_LOCALE_ */
|
#endif /* _PG_LOCALE_ */
|
||||||
|
Reference in New Issue
Block a user