@@ -1492,12 +1492,7 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
1492
1492
/* C/POSIX collations use this path regardless of database encoding */
1493
1493
if (lc_ctype_is_c (collid ))
1494
1494
{
1495
- char * p ;
1496
-
1497
- result = pnstrdup (buff , nbytes );
1498
-
1499
- for (p = result ; * p ; p ++ )
1500
- * p = pg_ascii_tolower ((unsigned char ) * p );
1495
+ result = asc_tolower (buff , nbytes );
1501
1496
}
1502
1497
#ifdef USE_WIDE_UPPER_LOWER
1503
1498
else if (pg_database_encoding_max_length () > 1 )
@@ -1617,12 +1612,7 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
1617
1612
/* C/POSIX collations use this path regardless of database encoding */
1618
1613
if (lc_ctype_is_c (collid ))
1619
1614
{
1620
- char * p ;
1621
-
1622
- result = pnstrdup (buff , nbytes );
1623
-
1624
- for (p = result ; * p ; p ++ )
1625
- * p = pg_ascii_toupper ((unsigned char ) * p );
1615
+ result = asc_toupper (buff , nbytes );
1626
1616
}
1627
1617
#ifdef USE_WIDE_UPPER_LOWER
1628
1618
else if (pg_database_encoding_max_length () > 1 )
@@ -1743,23 +1733,7 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
1743
1733
/* C/POSIX collations use this path regardless of database encoding */
1744
1734
if (lc_ctype_is_c (collid ))
1745
1735
{
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 ((unsigned char ) * p );
1756
- else
1757
- * p = c = pg_ascii_toupper ((unsigned char ) * 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 );
1763
1737
}
1764
1738
#ifdef USE_WIDE_UPPER_LOWER
1765
1739
else if (pg_database_encoding_max_length () > 1 )
@@ -1886,6 +1860,87 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
1886
1860
return result ;
1887
1861
}
1888
1862
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 ((unsigned char ) * 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 ((unsigned char ) * 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 ((unsigned char ) * p );
1933
+ else
1934
+ * p = c = pg_ascii_toupper ((unsigned char ) * 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
+
1889
1944
/* convenience routines for when the input is null-terminated */
1890
1945
1891
1946
static char *
@@ -1906,6 +1961,20 @@ str_initcap_z(const char *buff, Oid collid)
1906
1961
return str_initcap (buff , strlen (buff ), collid );
1907
1962
}
1908
1963
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
+
1909
1978
1910
1979
/* ----------
1911
1980
* Skip TM / th in FROM_CHAR
@@ -2418,7 +2487,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2418
2487
INVALID_FOR_INTERVAL ;
2419
2488
if (tmtcTzn (in ))
2420
2489
{
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 ));
2422
2492
2423
2493
strcpy (s , p );
2424
2494
pfree (p );
@@ -2465,7 +2535,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2465
2535
strcpy (s , str_toupper_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2466
2536
else
2467
2537
sprintf (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 ]));
2469
2539
s += strlen (s );
2470
2540
break ;
2471
2541
case DCH_Month :
@@ -2475,7 +2545,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2475
2545
if (S_TM (n -> suffix ))
2476
2546
strcpy (s , str_initcap_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2477
2547
else
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 ]);
2479
2550
s += strlen (s );
2480
2551
break ;
2481
2552
case DCH_month :
@@ -2485,10 +2556,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2485
2556
if (S_TM (n -> suffix ))
2486
2557
strcpy (s , str_tolower_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2487
2558
else
2488
- {
2489
- sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 , months_full [tm -> tm_mon - 1 ]);
2490
- * s = pg_tolower ((unsigned char ) * s );
2491
- }
2559
+ sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2560
+ asc_tolower_z (months_full [tm -> tm_mon - 1 ]));
2492
2561
s += strlen (s );
2493
2562
break ;
2494
2563
case DCH_MON :
@@ -2498,7 +2567,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2498
2567
if (S_TM (n -> suffix ))
2499
2568
strcpy (s , str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2500
2569
else
2501
- strcpy (s , str_toupper_z (months [tm -> tm_mon - 1 ], collid ));
2570
+ strcpy (s , asc_toupper_z (months [tm -> tm_mon - 1 ]));
2502
2571
s += strlen (s );
2503
2572
break ;
2504
2573
case DCH_Mon :
@@ -2518,10 +2587,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2518
2587
if (S_TM (n -> suffix ))
2519
2588
strcpy (s , str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2520
2589
else
2521
- {
2522
- strcpy (s , months [tm -> tm_mon - 1 ]);
2523
- * s = pg_tolower ((unsigned char ) * s );
2524
- }
2590
+ strcpy (s , asc_tolower_z (months [tm -> tm_mon - 1 ]));
2525
2591
s += strlen (s );
2526
2592
break ;
2527
2593
case DCH_MM :
@@ -2536,34 +2602,33 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2536
2602
strcpy (s , str_toupper_z (localized_full_days [tm -> tm_wday ], collid ));
2537
2603
else
2538
2604
sprintf (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 ]));
2540
2606
s += strlen (s );
2541
2607
break ;
2542
2608
case DCH_Day :
2543
2609
INVALID_FOR_INTERVAL ;
2544
2610
if (S_TM (n -> suffix ))
2545
2611
strcpy (s , str_initcap_z (localized_full_days [tm -> tm_wday ], collid ));
2546
2612
else
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 ]);
2548
2615
s += strlen (s );
2549
2616
break ;
2550
2617
case DCH_day :
2551
2618
INVALID_FOR_INTERVAL ;
2552
2619
if (S_TM (n -> suffix ))
2553
2620
strcpy (s , str_tolower_z (localized_full_days [tm -> tm_wday ], collid ));
2554
2621
else
2555
- {
2556
- sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 , days [tm -> tm_wday ]);
2557
- * s = pg_tolower ((unsigned char ) * s );
2558
- }
2622
+ sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2623
+ asc_tolower_z (days [tm -> tm_wday ]));
2559
2624
s += strlen (s );
2560
2625
break ;
2561
2626
case DCH_DY :
2562
2627
INVALID_FOR_INTERVAL ;
2563
2628
if (S_TM (n -> suffix ))
2564
2629
strcpy (s , str_toupper_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2565
2630
else
2566
- strcpy (s , str_toupper_z (days_short [tm -> tm_wday ], collid ));
2631
+ strcpy (s , asc_toupper_z (days_short [tm -> tm_wday ]));
2567
2632
s += strlen (s );
2568
2633
break ;
2569
2634
case DCH_Dy :
@@ -2579,10 +2644,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2579
2644
if (S_TM (n -> suffix ))
2580
2645
strcpy (s , str_tolower_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2581
2646
else
2582
- {
2583
- strcpy (s , days_short [tm -> tm_wday ]);
2584
- * s = pg_tolower ((unsigned char ) * s );
2585
- }
2647
+ strcpy (s , asc_tolower_z (days_short [tm -> tm_wday ]));
2586
2648
s += strlen (s );
2587
2649
break ;
2588
2650
case DCH_DDD :
@@ -4690,12 +4752,12 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
4690
4752
case NUM_rn :
4691
4753
if (IS_FILLMODE (Np -> Num ))
4692
4754
{
4693
- strcpy (Np -> inout_p , str_tolower_z (Np -> number_p , collid ));
4755
+ strcpy (Np -> inout_p , asc_tolower_z (Np -> number_p ));
4694
4756
Np -> inout_p += strlen (Np -> inout_p ) - 1 ;
4695
4757
}
4696
4758
else
4697
4759
{
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 ));
4699
4761
Np -> inout_p += strlen (Np -> inout_p ) - 1 ;
4700
4762
}
4701
4763
break ;
0 commit comments