@@ -1644,6 +1644,87 @@ str_initcap(const char *buff, size_t nbytes)
1644
1644
return result ;
1645
1645
}
1646
1646
1647
+ /*
1648
+ * ASCII-only lower function
1649
+ *
1650
+ * We pass the number of bytes so we can pass varlena and char*
1651
+ * to this function. The result is a palloc'd, null-terminated string.
1652
+ */
1653
+ char *
1654
+ asc_tolower (const char * buff ,size_t nbytes )
1655
+ {
1656
+ char * result ;
1657
+ char * p ;
1658
+
1659
+ if (!buff )
1660
+ return NULL ;
1661
+
1662
+ result = pnstrdup (buff ,nbytes );
1663
+
1664
+ for (p = result ;* p ;p ++ )
1665
+ * p = pg_tolower ((unsignedchar )* p );
1666
+
1667
+ return result ;
1668
+ }
1669
+
1670
+ /*
1671
+ * ASCII-only upper function
1672
+ *
1673
+ * We pass the number of bytes so we can pass varlena and char*
1674
+ * to this function. The result is a palloc'd, null-terminated string.
1675
+ */
1676
+ char *
1677
+ asc_toupper (const char * buff ,size_t nbytes )
1678
+ {
1679
+ char * result ;
1680
+ char * p ;
1681
+
1682
+ if (!buff )
1683
+ return NULL ;
1684
+
1685
+ result = pnstrdup (buff ,nbytes );
1686
+
1687
+ for (p = result ;* p ;p ++ )
1688
+ * p = pg_toupper ((unsignedchar )* p );
1689
+
1690
+ return result ;
1691
+ }
1692
+
1693
+ /*
1694
+ * ASCII-only initcap function
1695
+ *
1696
+ * We pass the number of bytes so we can pass varlena and char*
1697
+ * to this function. The result is a palloc'd, null-terminated string.
1698
+ */
1699
+ char *
1700
+ asc_initcap (const char * buff ,size_t nbytes )
1701
+ {
1702
+ char * result ;
1703
+ char * p ;
1704
+ int wasalnum = false;
1705
+
1706
+ if (!buff )
1707
+ return NULL ;
1708
+
1709
+ result = pnstrdup (buff ,nbytes );
1710
+
1711
+ for (p = result ;* p ;p ++ )
1712
+ {
1713
+ char c ;
1714
+
1715
+ if (wasalnum )
1716
+ * p = c = pg_tolower ((unsignedchar )* p );
1717
+ else
1718
+ * p = c = pg_toupper ((unsignedchar )* p );
1719
+ /* we don't trust isalnum() here */
1720
+ wasalnum = ((c >='A' && c <='Z' )||
1721
+ (c >='a' && c <='z' )||
1722
+ (c >='0' && c <='9' ));
1723
+ }
1724
+
1725
+ return result ;
1726
+ }
1727
+
1647
1728
/* convenience routines for when the input is null-terminated */
1648
1729
1649
1730
static char *
@@ -1664,6 +1745,20 @@ str_initcap_z(const char *buff)
1664
1745
return str_initcap (buff ,strlen (buff ));
1665
1746
}
1666
1747
1748
+ static char *
1749
+ asc_tolower_z (const char * buff )
1750
+ {
1751
+ return asc_tolower (buff ,strlen (buff ));
1752
+ }
1753
+
1754
+ static char *
1755
+ asc_toupper_z (const char * buff )
1756
+ {
1757
+ return asc_toupper (buff ,strlen (buff ));
1758
+ }
1759
+
1760
+ /* asc_initcap_z is not currently needed */
1761
+
1667
1762
1668
1763
/* ----------
1669
1764
* Skip TM / th in FROM_CHAR
@@ -2151,7 +2246,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
2151
2246
INVALID_FOR_INTERVAL ;
2152
2247
if (tmtcTzn (in ))
2153
2248
{
2154
- char * p = str_tolower_z (tmtcTzn (in ));
2249
+ /* We assume here that timezone names aren't localized */
2250
+ char * p = asc_tolower_z (tmtcTzn (in ));
2155
2251
2156
2252
strcpy (s ,p );
2157
2253
pfree (p );
@@ -2198,7 +2294,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
2198
2294
strcpy (s ,str_toupper_z (localized_full_months [tm -> tm_mon - 1 ]));
2199
2295
else
2200
2296
sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2201
- str_toupper_z (months_full [tm -> tm_mon - 1 ]));
2297
+ asc_toupper_z (months_full [tm -> tm_mon - 1 ]));
2202
2298
s += strlen (s );
2203
2299
break ;
2204
2300
case DCH_Month :
@@ -2208,7 +2304,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
2208
2304
if (S_TM (n -> suffix ))
2209
2305
strcpy (s ,str_initcap_z (localized_full_months [tm -> tm_mon - 1 ]));
2210
2306
else
2211
- sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,months_full [tm -> tm_mon - 1 ]);
2307
+ sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2308
+ months_full [tm -> tm_mon - 1 ]);
2212
2309
s += strlen (s );
2213
2310
break ;
2214
2311
case DCH_month :
@@ -2218,10 +2315,8 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
2218
2315
if (S_TM (n -> suffix ))
2219
2316
strcpy (s ,str_tolower_z (localized_full_months [tm -> tm_mon - 1 ]));
2220
2317
else
2221
- {
2222
- sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,months_full [tm -> tm_mon - 1 ]);
2223
- * s = pg_tolower ((unsignedchar )* s );
2224
- }
2318
+ sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2319
+ asc_tolower_z (months_full [tm -> tm_mon - 1 ]));
2225
2320
s += strlen (s );
2226
2321
break ;
2227
2322
case DCH_MON :
@@ -2231,7 +2326,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
2231
2326
if (S_TM (n -> suffix ))
2232
2327
strcpy (s ,str_toupper_z (localized_abbrev_months [tm -> tm_mon - 1 ]));
2233
2328
else
2234
- strcpy (s ,str_toupper_z (months [tm -> tm_mon - 1 ]));
2329
+ strcpy (s ,asc_toupper_z (months [tm -> tm_mon - 1 ]));
2235
2330
s += strlen (s );
2236
2331
break ;
2237
2332
case DCH_Mon :
@@ -2251,10 +2346,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
2251
2346
if (S_TM (n -> suffix ))
2252
2347
strcpy (s ,str_tolower_z (localized_abbrev_months [tm -> tm_mon - 1 ]));
2253
2348
else
2254
- {
2255
- strcpy (s ,months [tm -> tm_mon - 1 ]);
2256
- * s = pg_tolower ((unsignedchar )* s );
2257
- }
2349
+ strcpy (s ,asc_tolower_z (months [tm -> tm_mon - 1 ]));
2258
2350
s += strlen (s );
2259
2351
break ;
2260
2352
case DCH_MM :
@@ -2269,34 +2361,33 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
2269
2361
strcpy (s ,str_toupper_z (localized_full_days [tm -> tm_wday ]));
2270
2362
else
2271
2363
sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2272
- str_toupper_z (days [tm -> tm_wday ]));
2364
+ asc_toupper_z (days [tm -> tm_wday ]));
2273
2365
s += strlen (s );
2274
2366
break ;
2275
2367
case DCH_Day :
2276
2368
INVALID_FOR_INTERVAL ;
2277
2369
if (S_TM (n -> suffix ))
2278
2370
strcpy (s ,str_initcap_z (localized_full_days [tm -> tm_wday ]));
2279
2371
else
2280
- sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,days [tm -> tm_wday ]);
2372
+ sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2373
+ days [tm -> tm_wday ]);
2281
2374
s += strlen (s );
2282
2375
break ;
2283
2376
case DCH_day :
2284
2377
INVALID_FOR_INTERVAL ;
2285
2378
if (S_TM (n -> suffix ))
2286
2379
strcpy (s ,str_tolower_z (localized_full_days [tm -> tm_wday ]));
2287
2380
else
2288
- {
2289
- sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,days [tm -> tm_wday ]);
2290
- * s = pg_tolower ((unsignedchar )* s );
2291
- }
2381
+ sprintf (s ,"%*s" ,S_FM (n -> suffix ) ?0 :-9 ,
2382
+ asc_tolower_z (days [tm -> tm_wday ]));
2292
2383
s += strlen (s );
2293
2384
break ;
2294
2385
case DCH_DY :
2295
2386
INVALID_FOR_INTERVAL ;
2296
2387
if (S_TM (n -> suffix ))
2297
2388
strcpy (s ,str_toupper_z (localized_abbrev_days [tm -> tm_wday ]));
2298
2389
else
2299
- strcpy (s ,str_toupper_z (days_short [tm -> tm_wday ]));
2390
+ strcpy (s ,asc_toupper_z (days_short [tm -> tm_wday ]));
2300
2391
s += strlen (s );
2301
2392
break ;
2302
2393
case DCH_Dy :
@@ -2312,10 +2403,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
2312
2403
if (S_TM (n -> suffix ))
2313
2404
strcpy (s ,str_tolower_z (localized_abbrev_days [tm -> tm_wday ]));
2314
2405
else
2315
- {
2316
- strcpy (s ,days_short [tm -> tm_wday ]);
2317
- * s = pg_tolower ((unsignedchar )* s );
2318
- }
2406
+ strcpy (s ,asc_tolower_z (days_short [tm -> tm_wday ]));
2319
2407
s += strlen (s );
2320
2408
break ;
2321
2409
case DCH_DDD :
@@ -4422,12 +4510,12 @@ NUM_processor(FormatNode *node, NUMDesc *Num, char *inout, char *number,
4422
4510
case NUM_rn :
4423
4511
if (IS_FILLMODE (Np -> Num ))
4424
4512
{
4425
- strcpy (Np -> inout_p ,str_tolower_z (Np -> number_p ));
4513
+ strcpy (Np -> inout_p ,asc_tolower_z (Np -> number_p ));
4426
4514
Np -> inout_p += strlen (Np -> inout_p )- 1 ;
4427
4515
}
4428
4516
else
4429
4517
{
4430
- sprintf (Np -> inout_p ,"%15s" ,str_tolower_z (Np -> number_p ));
4518
+ sprintf (Np -> inout_p ,"%15s" ,asc_tolower_z (Np -> number_p ));
4431
4519
Np -> inout_p += strlen (Np -> inout_p )- 1 ;
4432
4520
}
4433
4521
break ;