@@ -1492,12 +1492,7 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
14921492/* C/POSIX collations use this path regardless of database encoding */
14931493if (lc_ctype_is_c (collid ))
14941494{
1495- char * p ;
1496-
1497- result = pnstrdup (buff ,nbytes );
1498-
1499- for (p = result ;* p ;p ++ )
1500- * p = pg_ascii_tolower ((unsignedchar )* p );
1495+ result = asc_tolower (buff ,nbytes );
15011496}
15021497#ifdef USE_WIDE_UPPER_LOWER
15031498else if (pg_database_encoding_max_length ()> 1 )
@@ -1617,12 +1612,7 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
16171612/* C/POSIX collations use this path regardless of database encoding */
16181613if (lc_ctype_is_c (collid ))
16191614{
1620- char * p ;
1621-
1622- result = pnstrdup (buff ,nbytes );
1623-
1624- for (p = result ;* p ;p ++ )
1625- * p = pg_ascii_toupper ((unsignedchar )* p );
1615+ result = asc_toupper (buff ,nbytes );
16261616}
16271617#ifdef USE_WIDE_UPPER_LOWER
16281618else if (pg_database_encoding_max_length ()> 1 )
@@ -1743,23 +1733,7 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
17431733/* C/POSIX collations use this path regardless of database encoding */
17441734if (lc_ctype_is_c (collid ))
17451735{
1746- char * p ;
1747-
1748- result = pnstrdup (buff ,nbytes );
1749-
1750- for (p = result ;* p ;p ++ )
1751- {
1752- char c ;
1753-
1754- if (wasalnum )
1755- * p = c = pg_ascii_tolower ((unsignedchar )* p );
1756- else
1757- * p = c = pg_ascii_toupper ((unsignedchar )* p );
1758- /* we don't trust isalnum() here */
1759- wasalnum = ((c >='A' && c <='Z' )||
1760- (c >='a' && c <='z' )||
1761- (c >='0' && c <='9' ));
1762- }
1736+ result = asc_initcap (buff ,nbytes );
17631737}
17641738#ifdef USE_WIDE_UPPER_LOWER
17651739else if (pg_database_encoding_max_length ()> 1 )
@@ -1886,6 +1860,87 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
18861860return result ;
18871861}
18881862
1863+ /*
1864+ * ASCII-only lower function
1865+ *
1866+ * We pass the number of bytes so we can pass varlena and char*
1867+ * to this function. The result is a palloc'd, null-terminated string.
1868+ */
1869+ char *
1870+ asc_tolower (const char * buff ,size_t nbytes )
1871+ {
1872+ char * result ;
1873+ char * p ;
1874+
1875+ if (!buff )
1876+ return NULL ;
1877+
1878+ result = pnstrdup (buff ,nbytes );
1879+
1880+ for (p = result ;* p ;p ++ )
1881+ * p = pg_ascii_tolower ((unsignedchar )* p );
1882+
1883+ return result ;
1884+ }
1885+
1886+ /*
1887+ * ASCII-only upper function
1888+ *
1889+ * We pass the number of bytes so we can pass varlena and char*
1890+ * to this function. The result is a palloc'd, null-terminated string.
1891+ */
1892+ char *
1893+ asc_toupper (const char * buff ,size_t nbytes )
1894+ {
1895+ char * result ;
1896+ char * p ;
1897+
1898+ if (!buff )
1899+ return NULL ;
1900+
1901+ result = pnstrdup (buff ,nbytes );
1902+
1903+ for (p = result ;* p ;p ++ )
1904+ * p = pg_ascii_toupper ((unsignedchar )* p );
1905+
1906+ return result ;
1907+ }
1908+
1909+ /*
1910+ * ASCII-only initcap function
1911+ *
1912+ * We pass the number of bytes so we can pass varlena and char*
1913+ * to this function. The result is a palloc'd, null-terminated string.
1914+ */
1915+ char *
1916+ asc_initcap (const char * buff ,size_t nbytes )
1917+ {
1918+ char * result ;
1919+ char * p ;
1920+ int wasalnum = false;
1921+
1922+ if (!buff )
1923+ return NULL ;
1924+
1925+ result = pnstrdup (buff ,nbytes );
1926+
1927+ for (p = result ;* p ;p ++ )
1928+ {
1929+ char c ;
1930+
1931+ if (wasalnum )
1932+ * p = c = pg_ascii_tolower ((unsignedchar )* p );
1933+ else
1934+ * p = c = pg_ascii_toupper ((unsignedchar )* p );
1935+ /* we don't trust isalnum() here */
1936+ wasalnum = ((c >='A' && c <='Z' )||
1937+ (c >='a' && c <='z' )||
1938+ (c >='0' && c <='9' ));
1939+ }
1940+
1941+ return result ;
1942+ }
1943+
18891944/* convenience routines for when the input is null-terminated */
18901945
18911946static char *
@@ -1906,6 +1961,20 @@ str_initcap_z(const char *buff, Oid collid)
19061961return str_initcap (buff ,strlen (buff ),collid );
19071962}
19081963
1964+ static char *
1965+ asc_tolower_z (const char * buff )
1966+ {
1967+ return asc_tolower (buff ,strlen (buff ));
1968+ }
1969+
1970+ static char *
1971+ asc_toupper_z (const char * buff )
1972+ {
1973+ return asc_toupper (buff ,strlen (buff ));
1974+ }
1975+
1976+ /* asc_initcap_z is not currently needed */
1977+
19091978
19101979/* ----------
19111980 * Skip TM / th in FROM_CHAR
@@ -2418,7 +2487,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
24182487INVALID_FOR_INTERVAL ;
24192488if (tmtcTzn (in ))
24202489{
2421- char * p = str_tolower_z (tmtcTzn (in ),collid );
2490+ /* We assume here that timezone names aren't localized */
2491+ char * p = asc_tolower_z (tmtcTzn (in ));
24222492
24232493strcpy (s ,p );
24242494pfree (p );
@@ -2465,7 +2535,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
24652535strcpy (s ,str_toupper_z (localized_full_months [tm -> tm_mon - 1 ],collid ));
24662536else
24672537sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2468- str_toupper_z (months_full [tm -> tm_mon - 1 ], collid ));
2538+ asc_toupper_z (months_full [tm -> tm_mon - 1 ]));
24692539s += strlen (s );
24702540break ;
24712541case DCH_Month :
@@ -2475,7 +2545,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
24752545if (S_TM (n -> suffix ))
24762546strcpy (s ,str_initcap_z (localized_full_months [tm -> tm_mon - 1 ],collid ));
24772547else
2478- sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,months_full [tm -> tm_mon - 1 ]);
2548+ sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2549+ months_full [tm -> tm_mon - 1 ]);
24792550s += strlen (s );
24802551break ;
24812552case DCH_month :
@@ -2485,10 +2556,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
24852556if (S_TM (n -> suffix ))
24862557strcpy (s ,str_tolower_z (localized_full_months [tm -> tm_mon - 1 ],collid ));
24872558else
2488- {
2489- sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,months_full [tm -> tm_mon - 1 ]);
2490- * s = pg_tolower ((unsignedchar )* s );
2491- }
2559+ sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2560+ asc_tolower_z (months_full [tm -> tm_mon - 1 ]));
24922561s += strlen (s );
24932562break ;
24942563case DCH_MON :
@@ -2498,7 +2567,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
24982567if (S_TM (n -> suffix ))
24992568strcpy (s ,str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ],collid ));
25002569else
2501- strcpy (s ,str_toupper_z (months [tm -> tm_mon - 1 ], collid ));
2570+ strcpy (s ,asc_toupper_z (months [tm -> tm_mon - 1 ]));
25022571s += strlen (s );
25032572break ;
25042573case DCH_Mon :
@@ -2518,10 +2587,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
25182587if (S_TM (n -> suffix ))
25192588strcpy (s ,str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ],collid ));
25202589else
2521- {
2522- strcpy (s ,months [tm -> tm_mon - 1 ]);
2523- * s = pg_tolower ((unsignedchar )* s );
2524- }
2590+ strcpy (s ,asc_tolower_z (months [tm -> tm_mon - 1 ]));
25252591s += strlen (s );
25262592break ;
25272593case DCH_MM :
@@ -2536,34 +2602,33 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
25362602strcpy (s ,str_toupper_z (localized_full_days [tm -> tm_wday ],collid ));
25372603else
25382604sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2539- str_toupper_z (days [tm -> tm_wday ], collid ));
2605+ asc_toupper_z (days [tm -> tm_wday ]));
25402606s += strlen (s );
25412607break ;
25422608case DCH_Day :
25432609INVALID_FOR_INTERVAL ;
25442610if (S_TM (n -> suffix ))
25452611strcpy (s ,str_initcap_z (localized_full_days [tm -> tm_wday ],collid ));
25462612else
2547- sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,days [tm -> tm_wday ]);
2613+ sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2614+ days [tm -> tm_wday ]);
25482615s += strlen (s );
25492616break ;
25502617case DCH_day :
25512618INVALID_FOR_INTERVAL ;
25522619if (S_TM (n -> suffix ))
25532620strcpy (s ,str_tolower_z (localized_full_days [tm -> tm_wday ],collid ));
25542621else
2555- {
2556- sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,days [tm -> tm_wday ]);
2557- * s = pg_tolower ((unsignedchar )* s );
2558- }
2622+ sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2623+ asc_tolower_z (days [tm -> tm_wday ]));
25592624s += strlen (s );
25602625break ;
25612626case DCH_DY :
25622627INVALID_FOR_INTERVAL ;
25632628if (S_TM (n -> suffix ))
25642629strcpy (s ,str_toupper_z (localized_abbrev_days [tm -> tm_wday ],collid ));
25652630else
2566- strcpy (s ,str_toupper_z (days_short [tm -> tm_wday ], collid ));
2631+ strcpy (s ,asc_toupper_z (days_short [tm -> tm_wday ]));
25672632s += strlen (s );
25682633break ;
25692634case DCH_Dy :
@@ -2579,10 +2644,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
25792644if (S_TM (n -> suffix ))
25802645strcpy (s ,str_tolower_z (localized_abbrev_days [tm -> tm_wday ],collid ));
25812646else
2582- {
2583- strcpy (s ,days_short [tm -> tm_wday ]);
2584- * s = pg_tolower ((unsignedchar )* s );
2585- }
2647+ strcpy (s ,asc_tolower_z (days_short [tm -> tm_wday ]));
25862648s += strlen (s );
25872649break ;
25882650case DCH_DDD :
@@ -4690,12 +4752,12 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
46904752case NUM_rn :
46914753if (IS_FILLMODE (Np -> Num ))
46924754{
4693- strcpy (Np -> inout_p ,str_tolower_z (Np -> number_p , collid ));
4755+ strcpy (Np -> inout_p ,asc_tolower_z (Np -> number_p ));
46944756Np -> inout_p += strlen (Np -> inout_p )- 1 ;
46954757}
46964758else
46974759{
4698- sprintf (Np -> inout_p ,"%15s" ,str_tolower_z (Np -> number_p , collid ));
4760+ sprintf (Np -> inout_p ,"%15s" ,asc_tolower_z (Np -> number_p ));
46994761Np -> inout_p += strlen (Np -> inout_p )- 1 ;
47004762}
47014763break ;