@ -1448,9 +1448,15 @@ str_numth(char *dest, char *num, int type)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifdef USE_ICU
typedef int32_t ( * ICU_Convert_Func ) ( UChar * dest , int32_t destCapacity ,
const UChar * src , int32_t srcLength ,
const char * locale ,
UErrorCode * pErrorCode ) ;
static int32_t
icu_convert_case ( int32_t ( * func ) ( UChar * , int32_t , const UChar * , int32_t , const char * , UErrorCode * ) ,
pg_locale_t mylocale , UChar * * buff_dest , UChar * buff_source , int32_t len_source )
icu_convert_case ( ICU_Convert_Func func , pg_locale_t mylocale ,
UChar * * buff_dest , UChar * buff_source , int32_t len_source )
{
UErrorCode status ;
int32_t len_dest ;
@ -1458,14 +1464,16 @@ icu_convert_case(int32_t (*func)(UChar *, int32_t, const UChar *, int32_t, const
len_dest = len_source ; /* try first with same length */
* buff_dest = palloc ( len_dest * sizeof ( * * buff_dest ) ) ;
status = U_ZERO_ERROR ;
len_dest = func ( * buff_dest , len_dest , buff_source , len_source , mylocale - > info . icu . locale , & status ) ;
len_dest = func ( * buff_dest , len_dest , buff_source , len_source ,
mylocale - > info . icu . locale , & status ) ;
if ( status = = U_BUFFER_OVERFLOW_ERROR )
{
/* try again with adjusted length */
pfree ( buff_dest ) ;
buff_dest = palloc ( len_dest * sizeof ( * * buff_dest ) ) ;
pfree ( * buff_dest ) ;
* buff_dest = palloc ( len_dest * sizeof ( * * buff_dest ) ) ;
status = U_ZERO_ERROR ;
len_dest = func ( * buff_dest , len_dest , buff_source , len_source , mylocale - > info . icu . locale , & status ) ;
len_dest = func ( * buff_dest , len_dest , buff_source , len_source ,
mylocale - > info . icu . locale , & status ) ;
}
if ( U_FAILURE ( status ) )
ereport ( ERROR ,
@ -1479,9 +1487,11 @@ u_strToTitle_default_BI(UChar *dest, int32_t destCapacity,
const char * locale ,
UErrorCode * pErrorCode )
{
return u_strToTitle ( dest , destCapacity , src , srcLength , NULL , locale , pErrorCode ) ;
return u_strToTitle ( dest , destCapacity , src , srcLength ,
NULL , locale , pErrorCode ) ;
}
# endif
# endif /* USE_ICU */
/*
* If the system provides the needed functions for wide - character manipulation
@ -1548,7 +1558,8 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
UChar * buff_conv ;
len_uchar = icu_to_uchar ( & buff_uchar , buff , nbytes ) ;
len_conv = icu_convert_case ( u_strToLower , mylocale , & buff_conv , buff_uchar , len_uchar ) ;
len_conv = icu_convert_case ( u_strToLower , mylocale ,
& buff_conv , buff_uchar , len_uchar ) ;
icu_from_uchar ( & result , buff_conv , len_conv ) ;
}
else
@ -1666,7 +1677,8 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
UChar * buff_conv ;
len_uchar = icu_to_uchar ( & buff_uchar , buff , nbytes ) ;
len_conv = icu_convert_case ( u_strToUpper , mylocale , & buff_conv , buff_uchar , len_uchar ) ;
len_conv = icu_convert_case ( u_strToUpper , mylocale ,
& buff_conv , buff_uchar , len_uchar ) ;
icu_from_uchar ( & result , buff_conv , len_conv ) ;
}
else
@ -1785,7 +1797,8 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
UChar * buff_conv ;
len_uchar = icu_to_uchar ( & buff_uchar , buff , nbytes ) ;
len_conv = icu_convert_case ( u_strToTitle_default_BI , mylocale , & buff_conv , buff_uchar , len_uchar ) ;
len_conv = icu_convert_case ( u_strToTitle_default_BI , mylocale ,
& buff_conv , buff_uchar , len_uchar ) ;
icu_from_uchar ( & result , buff_conv , len_conv ) ;
}
else