Hello,

it's more correct patch and more short.

Regards
Pavel Stehule




Would you please modify this patch to use the functions in
oracle_compat.c?

---------------------------------------------------------------------------

Pavel Stehule wrote:
> Hello,
>
> this patch correct bug in to_char function with incorrect uppercased month's
> or day's name.
>
> Regards
> Pavel Stehule
>
> _________________________________________________________________
> Najdete si svou lasku a nove pratele na Match.com. http://www.msn.cz/

[ Attachment, skipping... ]

>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>                http://archives.postgresql.org

--
  Bruce Momjian   [EMAIL PROTECTED]
  EnterpriseDB    http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

_________________________________________________________________
Citite se osamele? Poznejte nekoho vyjmecneho diky Match.com. http://www.msn.cz/
*** ./adt/formatting.c.orig	2007-02-04 13:09:09.000000000 +0100
--- ./adt/formatting.c	2007-02-04 13:08:05.000000000 +0100
***************
*** 82,87 ****
--- 82,88 ----
  #include "utils/int8.h"
  #include "utils/numeric.h"
  #include "utils/pg_locale.h"
+ #include "mb/pg_wchar.h"
  
  #define _(x)	gettext((x))
  
***************
*** 113,118 ****
--- 114,127 ----
  #define MAXFLOATWIDTH	64
  #define MAXDOUBLEWIDTH	128
  
+ /*
+  * External (defined in oracle_compat.c 
+  */
+ #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)                                                                     
+ #define USE_WIDE_UPPER_LOWER                                                                                             
+ extern int upper_str(char *str);                                                                                                
+ #endif  
+ 
  /* ----------
   * External (defined in PgSQL datetime.c (timestamp utils))
   * ----------
***************
*** 1490,1505 ****
  static char *
  str_toupper(char *buff)
  {
- 	char	   *p_buff = buff;
- 
  	if (!buff)
  		return NULL;
  
! 	while (*p_buff)
  	{
! 		*p_buff = pg_toupper((unsigned char) *p_buff);
! 		++p_buff;
  	}
  	return buff;
  }
  
--- 1499,1522 ----
  static char *
  str_toupper(char *buff)
  {
  	if (!buff)
  		return NULL;
  
! #ifdef USE_WIDE_UPPER_LOWER
! 	if (pg_database_encoding_max_length() > 1 && !lc_ctype_is_c())
! 		upper_str(buff);
! 	else
! #endif /* USE_WIDE_UPPER_LOWER */
  	{
! 		char	   *p_buff = buff;
! 
! 		while (*p_buff)
! 		{
! 			*p_buff = pg_toupper((unsigned char) *p_buff);
! 			++p_buff;
! 		}
  	}
+ 
  	return buff;
  }
  
*** ./adt/oracle_compat.c.orig	2007-02-04 12:35:14.000000000 +0100
--- ./adt/oracle_compat.c	2007-02-04 13:02:55.000000000 +0100
***************
*** 46,51 ****
--- 46,52 ----
   */
  #if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
  #define USE_WIDE_UPPER_LOWER
+ int upper_str(char *str);
  #endif
  
  static text *dotrim(const char *string, int stringlen,
***************
*** 258,263 ****
--- 259,302 ----
  #define wcstotext	win32_wcstotext
  #endif   /* WIN32 */
  
+ #ifdef USE_WIDE_UPPER_LOWER
+ /* 
+  * upper_text is used for correct multibyte upper function str_toupper.
+  * Expected safety long buffer (used only for internal purpouse). 
+  * Returns length of converted string.
+  */
+ int
+ upper_str(char *str)
+ {
+ 	wchar_t	  *workspace;
+ 	text 	  *txt;
+ 	text	  *result;
+ 	int 		nbytes = strlen(str);
+ 	int	   	i;
+ 	
+ 	txt = palloc(nbytes + VARHDRSZ);
+ 	memcpy(VARDATA(txt), str, nbytes);
+ 	VARATT_SIZEP(txt) = nbytes + VARHDRSZ;
+ 
+ 	workspace = texttowcs(txt);
+ 
+ 	for (i = 0; workspace[i] != 0; i++)
+ 		workspace[i] = towupper(workspace[i]);
+ 
+ 	result = wcstotext(workspace, i);
+ 
+ 	/* copy back result */	
+ 	nbytes = VARSIZE(result) - VARHDRSZ;
+ 	memcpy(str, VARDATA(result), nbytes);
+ 	str[nbytes] = '\0';
+ 
+ 	pfree(workspace);
+ 	pfree(result);
+ 	
+ 	return nbytes;
+ }
+ #endif	/* USE_WIDE_UPPER_LOWER */
+ 
  
  /********************************************************************
   *

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to [EMAIL PROTECTED] so that your
       message can get through to the mailing list cleanly

Reply via email to