@@ -1493,12 +1493,7 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
1493
1493
/* C/POSIX collations use this path regardless of database encoding */
1494
1494
if (lc_ctype_is_c (collid ))
1495
1495
{
1496
- char * p ;
1497
-
1498
- result = pnstrdup (buff , nbytes );
1499
-
1500
- for (p = result ; * p ; p ++ )
1501
- * p = pg_ascii_tolower ((unsigned char ) * p );
1496
+ result = asc_tolower (buff , nbytes );
1502
1497
}
1503
1498
#ifdef USE_WIDE_UPPER_LOWER
1504
1499
else if (pg_database_encoding_max_length () > 1 )
@@ -1618,12 +1613,7 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
1618
1613
/* C/POSIX collations use this path regardless of database encoding */
1619
1614
if (lc_ctype_is_c (collid ))
1620
1615
{
1621
- char * p ;
1622
-
1623
- result = pnstrdup (buff , nbytes );
1624
-
1625
- for (p = result ; * p ; p ++ )
1626
- * p = pg_ascii_toupper ((unsigned char ) * p );
1616
+ result = asc_toupper (buff , nbytes );
1627
1617
}
1628
1618
#ifdef USE_WIDE_UPPER_LOWER
1629
1619
else if (pg_database_encoding_max_length () > 1 )
@@ -1744,23 +1734,7 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
1744
1734
/* C/POSIX collations use this path regardless of database encoding */
1745
1735
if (lc_ctype_is_c (collid ))
1746
1736
{
1747
- char * p ;
1748
-
1749
- result = pnstrdup (buff , nbytes );
1750
-
1751
- for (p = result ; * p ; p ++ )
1752
- {
1753
- char c ;
1754
-
1755
- if (wasalnum )
1756
- * p = c = pg_ascii_tolower ((unsigned char ) * p );
1757
- else
1758
- * p = c = pg_ascii_toupper ((unsigned char ) * p );
1759
- /* we don't trust isalnum() here */
1760
- wasalnum = ((c >= 'A' && c <= 'Z' ) ||
1761
- (c >= 'a' && c <= 'z' ) ||
1762
- (c >= '0' && c <= '9' ));
1763
- }
1737
+ result = asc_initcap (buff , nbytes );
1764
1738
}
1765
1739
#ifdef USE_WIDE_UPPER_LOWER
1766
1740
else if (pg_database_encoding_max_length () > 1 )
@@ -1887,6 +1861,87 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
1887
1861
return result ;
1888
1862
}
1889
1863
1864
+ /*
1865
+ * ASCII-only lower function
1866
+ *
1867
+ * We pass the number of bytes so we can pass varlena and char*
1868
+ * to this function. The result is a palloc'd, null-terminated string.
1869
+ */
1870
+ char *
1871
+ asc_tolower (const char * buff , size_t nbytes )
1872
+ {
1873
+ char * result ;
1874
+ char * p ;
1875
+
1876
+ if (!buff )
1877
+ return NULL ;
1878
+
1879
+ result = pnstrdup (buff , nbytes );
1880
+
1881
+ for (p = result ; * p ; p ++ )
1882
+ * p = pg_ascii_tolower ((unsigned char ) * p );
1883
+
1884
+ return result ;
1885
+ }
1886
+
1887
+ /*
1888
+ * ASCII-only upper function
1889
+ *
1890
+ * We pass the number of bytes so we can pass varlena and char*
1891
+ * to this function. The result is a palloc'd, null-terminated string.
1892
+ */
1893
+ char *
1894
+ asc_toupper (const char * buff , size_t nbytes )
1895
+ {
1896
+ char * result ;
1897
+ char * p ;
1898
+
1899
+ if (!buff )
1900
+ return NULL ;
1901
+
1902
+ result = pnstrdup (buff , nbytes );
1903
+
1904
+ for (p = result ; * p ; p ++ )
1905
+ * p = pg_ascii_toupper ((unsigned char ) * p );
1906
+
1907
+ return result ;
1908
+ }
1909
+
1910
+ /*
1911
+ * ASCII-only initcap function
1912
+ *
1913
+ * We pass the number of bytes so we can pass varlena and char*
1914
+ * to this function. The result is a palloc'd, null-terminated string.
1915
+ */
1916
+ char *
1917
+ asc_initcap (const char * buff , size_t nbytes )
1918
+ {
1919
+ char * result ;
1920
+ char * p ;
1921
+ int wasalnum = false;
1922
+
1923
+ if (!buff )
1924
+ return NULL ;
1925
+
1926
+ result = pnstrdup (buff , nbytes );
1927
+
1928
+ for (p = result ; * p ; p ++ )
1929
+ {
1930
+ char c ;
1931
+
1932
+ if (wasalnum )
1933
+ * p = c = pg_ascii_tolower ((unsigned char ) * p );
1934
+ else
1935
+ * p = c = pg_ascii_toupper ((unsigned char ) * p );
1936
+ /* we don't trust isalnum() here */
1937
+ wasalnum = ((c >= 'A' && c <= 'Z' ) ||
1938
+ (c >= 'a' && c <= 'z' ) ||
1939
+ (c >= '0' && c <= '9' ));
1940
+ }
1941
+
1942
+ return result ;
1943
+ }
1944
+
1890
1945
/* convenience routines for when the input is null-terminated */
1891
1946
1892
1947
static char *
@@ -1907,6 +1962,20 @@ str_initcap_z(const char *buff, Oid collid)
1907
1962
return str_initcap (buff , strlen (buff ), collid );
1908
1963
}
1909
1964
1965
+ static char *
1966
+ asc_tolower_z (const char * buff )
1967
+ {
1968
+ return asc_tolower (buff , strlen (buff ));
1969
+ }
1970
+
1971
+ static char *
1972
+ asc_toupper_z (const char * buff )
1973
+ {
1974
+ return asc_toupper (buff , strlen (buff ));
1975
+ }
1976
+
1977
+ /* asc_initcap_z is not currently needed */
1978
+
1910
1979
1911
1980
/* ----------
1912
1981
* Skip TM / th in FROM_CHAR
@@ -2419,7 +2488,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2419
2488
INVALID_FOR_INTERVAL ;
2420
2489
if (tmtcTzn (in ))
2421
2490
{
2422
- char * p = str_tolower_z (tmtcTzn (in ), collid );
2491
+ /* We assume here that timezone names aren't localized */
2492
+ char * p = asc_tolower_z (tmtcTzn (in ));
2423
2493
2424
2494
strcpy (s , p );
2425
2495
pfree (p );
@@ -2466,7 +2536,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2466
2536
strcpy (s , str_toupper_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2467
2537
else
2468
2538
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2469
- str_toupper_z (months_full [tm -> tm_mon - 1 ], collid ));
2539
+ asc_toupper_z (months_full [tm -> tm_mon - 1 ]));
2470
2540
s += strlen (s );
2471
2541
break ;
2472
2542
case DCH_Month :
@@ -2476,7 +2546,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2476
2546
if (S_TM (n -> suffix ))
2477
2547
strcpy (s , str_initcap_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2478
2548
else
2479
- sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 , months_full [tm -> tm_mon - 1 ]);
2549
+ sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2550
+ months_full [tm -> tm_mon - 1 ]);
2480
2551
s += strlen (s );
2481
2552
break ;
2482
2553
case DCH_month :
@@ -2486,10 +2557,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2486
2557
if (S_TM (n -> suffix ))
2487
2558
strcpy (s , str_tolower_z (localized_full_months [tm -> tm_mon - 1 ], collid ));
2488
2559
else
2489
- {
2490
- sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 , months_full [tm -> tm_mon - 1 ]);
2491
- * s = pg_tolower ((unsigned char ) * s );
2492
- }
2560
+ sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2561
+ asc_tolower_z (months_full [tm -> tm_mon - 1 ]));
2493
2562
s += strlen (s );
2494
2563
break ;
2495
2564
case DCH_MON :
@@ -2499,7 +2568,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2499
2568
if (S_TM (n -> suffix ))
2500
2569
strcpy (s , str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2501
2570
else
2502
- strcpy (s , str_toupper_z (months [tm -> tm_mon - 1 ], collid ));
2571
+ strcpy (s , asc_toupper_z (months [tm -> tm_mon - 1 ]));
2503
2572
s += strlen (s );
2504
2573
break ;
2505
2574
case DCH_Mon :
@@ -2519,10 +2588,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2519
2588
if (S_TM (n -> suffix ))
2520
2589
strcpy (s , str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ], collid ));
2521
2590
else
2522
- {
2523
- strcpy (s , months [tm -> tm_mon - 1 ]);
2524
- * s = pg_tolower ((unsigned char ) * s );
2525
- }
2591
+ strcpy (s , asc_tolower_z (months [tm -> tm_mon - 1 ]));
2526
2592
s += strlen (s );
2527
2593
break ;
2528
2594
case DCH_MM :
@@ -2537,34 +2603,33 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2537
2603
strcpy (s , str_toupper_z (localized_full_days [tm -> tm_wday ], collid ));
2538
2604
else
2539
2605
sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2540
- str_toupper_z (days [tm -> tm_wday ], collid ));
2606
+ asc_toupper_z (days [tm -> tm_wday ]));
2541
2607
s += strlen (s );
2542
2608
break ;
2543
2609
case DCH_Day :
2544
2610
INVALID_FOR_INTERVAL ;
2545
2611
if (S_TM (n -> suffix ))
2546
2612
strcpy (s , str_initcap_z (localized_full_days [tm -> tm_wday ], collid ));
2547
2613
else
2548
- sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 , days [tm -> tm_wday ]);
2614
+ sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2615
+ days [tm -> tm_wday ]);
2549
2616
s += strlen (s );
2550
2617
break ;
2551
2618
case DCH_day :
2552
2619
INVALID_FOR_INTERVAL ;
2553
2620
if (S_TM (n -> suffix ))
2554
2621
strcpy (s , str_tolower_z (localized_full_days [tm -> tm_wday ], collid ));
2555
2622
else
2556
- {
2557
- sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 , days [tm -> tm_wday ]);
2558
- * s = pg_tolower ((unsigned char ) * s );
2559
- }
2623
+ sprintf (s , "%*s" , S_FM (n -> suffix ) ? 0 : -9 ,
2624
+ asc_tolower_z (days [tm -> tm_wday ]));
2560
2625
s += strlen (s );
2561
2626
break ;
2562
2627
case DCH_DY :
2563
2628
INVALID_FOR_INTERVAL ;
2564
2629
if (S_TM (n -> suffix ))
2565
2630
strcpy (s , str_toupper_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2566
2631
else
2567
- strcpy (s , str_toupper_z (days_short [tm -> tm_wday ], collid ));
2632
+ strcpy (s , asc_toupper_z (days_short [tm -> tm_wday ]));
2568
2633
s += strlen (s );
2569
2634
break ;
2570
2635
case DCH_Dy :
@@ -2580,10 +2645,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
2580
2645
if (S_TM (n -> suffix ))
2581
2646
strcpy (s , str_tolower_z (localized_abbrev_days [tm -> tm_wday ], collid ));
2582
2647
else
2583
- {
2584
- strcpy (s , days_short [tm -> tm_wday ]);
2585
- * s = pg_tolower ((unsigned char ) * s );
2586
- }
2648
+ strcpy (s , asc_tolower_z (days_short [tm -> tm_wday ]));
2587
2649
s += strlen (s );
2588
2650
break ;
2589
2651
case DCH_DDD :
@@ -4670,12 +4732,12 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
4670
4732
case NUM_rn :
4671
4733
if (IS_FILLMODE (Np -> Num ))
4672
4734
{
4673
- strcpy (Np -> inout_p , str_tolower_z (Np -> number_p , collid ));
4735
+ strcpy (Np -> inout_p , asc_tolower_z (Np -> number_p ));
4674
4736
Np -> inout_p += strlen (Np -> inout_p ) - 1 ;
4675
4737
}
4676
4738
else
4677
4739
{
4678
- sprintf (Np -> inout_p , "%15s" , str_tolower_z (Np -> number_p , collid ));
4740
+ sprintf (Np -> inout_p , "%15s" , asc_tolower_z (Np -> number_p ));
4679
4741
Np -> inout_p += strlen (Np -> inout_p ) - 1 ;
4680
4742
}
4681
4743
break ;
0 commit comments