1
1
/* -----------------------------------------------------------------------
2
2
* formatting.c
3
3
*
4
- * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.119 2007/02/08 03:22:28 momjian Exp $
4
+ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.120 2007/02/08 18:19:33 momjian Exp $
5
5
*
6
6
*
7
7
* Portions Copyright (c) 1999-2007, PostgreSQL Global Development Group
82
82
#include "utils/int8.h"
83
83
#include "utils/numeric.h"
84
84
#include "utils/pg_locale.h"
85
+ #include "mb/pg_wchar.h"
85
86
86
87
#define _ (x ) gettext((x))
87
88
113
114
#define MAXFLOATWIDTH 64
114
115
#define MAXDOUBLEWIDTH 128
115
116
117
+
116
118
/* ----------
117
119
* External (defined in PgSQL datetime.c (timestamp utils))
118
120
* ----------
@@ -946,6 +948,20 @@ static char *localize_month(int index);
946
948
static char * localize_day_full (int index );
947
949
static char * localize_day (int index );
948
950
951
+ /*
952
+ * External (defined in oracle_compat.c
953
+ */
954
+ #if defined(HAVE_WCSTOMBS ) && defined(HAVE_TOWLOWER )
955
+ #define USE_WIDE_UPPER_LOWER
956
+ extern char * wstring_upper (char * str );
957
+ extern char * wstring_lower (char * str );
958
+ static char * localized_str_toupper (char * buff );
959
+ static char * localized_str_tolower (char * buff );
960
+ #else
961
+ #define localized_str_toupper str_toupper
962
+ #define localized_str_tolower str_tolower
963
+ #endif
964
+
949
965
/* ----------
950
966
* Fast sequential search, use index for data selection which
951
967
* go to seq. cycle (it is very fast for unwanted strings)
@@ -1500,6 +1516,7 @@ str_toupper(char *buff)
1500
1516
* p_buff = pg_toupper ((unsigned char ) * p_buff );
1501
1517
++ p_buff ;
1502
1518
}
1519
+
1503
1520
return buff ;
1504
1521
}
1505
1522
@@ -1523,6 +1540,61 @@ str_tolower(char *buff)
1523
1540
return buff ;
1524
1541
}
1525
1542
1543
+
1544
+ #ifdef USE_WIDE_UPPER_LOWER
1545
+ /* ----------
1546
+ * Convert localized string to upper string. Input string is modified in place.
1547
+ * ----------
1548
+ */
1549
+ static char *
1550
+ localized_str_toupper (char * buff )
1551
+ {
1552
+ if (!buff )
1553
+ return NULL ;
1554
+
1555
+ if (pg_database_encoding_max_length () > 1 && !lc_ctype_is_c ())
1556
+ return wstring_upper (buff );
1557
+ else
1558
+ {
1559
+ char * p_buff = buff ;
1560
+
1561
+ while (* p_buff )
1562
+ {
1563
+ * p_buff = pg_toupper ((unsigned char ) * p_buff );
1564
+ ++ p_buff ;
1565
+ }
1566
+ }
1567
+
1568
+ return buff ;
1569
+ }
1570
+
1571
+ /* ----------
1572
+ * Convert localized string to upper string. Input string is modified in place.
1573
+ * ----------
1574
+ */
1575
+ static char *
1576
+ localized_str_tolower (char * buff )
1577
+ {
1578
+ if (!buff )
1579
+ return NULL ;
1580
+
1581
+ if (pg_database_encoding_max_length () > 1 && !lc_ctype_is_c ())
1582
+ return wstring_lower (buff );
1583
+ else
1584
+ {
1585
+ char * p_buff = buff ;
1586
+
1587
+ while (* p_buff )
1588
+ {
1589
+ * p_buff = pg_tolower ((unsigned char ) * p_buff );
1590
+ ++ p_buff ;
1591
+ }
1592
+ }
1593
+
1594
+ return buff ;
1595
+ }
1596
+ #endif /* USE_WIDE_UPPER_LOWER */
1597
+
1526
1598
/* ----------
1527
1599
* Sequential search with to upper/lower conversion
1528
1600
* ----------
@@ -2182,10 +2254,15 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
2182
2254
if (!tm -> tm_mon )
2183
2255
return -1 ;
2184
2256
if (S_TM (suf ))
2257
+ {
2185
2258
strcpy (workbuff , localize_month_full (tm -> tm_mon - 1 ));
2259
+ sprintf (inout , "%*s" , 0 , localized_str_toupper (workbuff ));
2260
+ }
2186
2261
else
2262
+ {
2187
2263
strcpy (workbuff , months_full [tm -> tm_mon - 1 ]);
2188
- sprintf (inout , "%*s" , (S_FM (suf ) || S_TM (suf )) ? 0 : -9 , str_toupper (workbuff ));
2264
+ sprintf (inout , "%*s" , S_FM (suf ) ? 0 : -9 , str_toupper (workbuff ));
2265
+ }
2189
2266
return strlen (p_inout );
2190
2267
2191
2268
case DCH_Month :
@@ -2203,21 +2280,31 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
2203
2280
if (!tm -> tm_mon )
2204
2281
return -1 ;
2205
2282
if (S_TM (suf ))
2206
- sprintf (inout , "%*s" , 0 , localize_month_full (tm -> tm_mon - 1 ));
2283
+ {
2284
+ strcpy (workbuff , localize_month_full (tm -> tm_mon - 1 ));
2285
+ sprintf (inout , "%*s" , 0 , localized_str_tolower (workbuff ));
2286
+ }
2207
2287
else
2288
+ {
2208
2289
sprintf (inout , "%*s" , S_FM (suf ) ? 0 : -9 , months_full [tm -> tm_mon - 1 ]);
2209
- * inout = pg_tolower ((unsigned char ) * inout );
2290
+ * inout = pg_tolower ((unsigned char ) * inout );
2291
+ }
2210
2292
return strlen (p_inout );
2211
2293
2212
2294
case DCH_MON :
2213
2295
INVALID_FOR_INTERVAL ;
2214
2296
if (!tm -> tm_mon )
2215
2297
return -1 ;
2216
2298
if (S_TM (suf ))
2217
- strcpy (inout , localize_month (tm -> tm_mon - 1 ));
2299
+ {
2300
+ strcpy (workbuff , localize_month (tm -> tm_mon - 1 ));
2301
+ strcpy (inout , localized_str_toupper (workbuff ));
2302
+ }
2218
2303
else
2304
+ {
2219
2305
strcpy (inout , months [tm -> tm_mon - 1 ]);
2220
- str_toupper (inout );
2306
+ str_toupper (inout );
2307
+ }
2221
2308
return strlen (p_inout );
2222
2309
2223
2310
case DCH_Mon :
@@ -2235,10 +2322,15 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
2235
2322
if (!tm -> tm_mon )
2236
2323
return -1 ;
2237
2324
if (S_TM (suf ))
2238
- strcpy (inout , localize_month (tm -> tm_mon - 1 ));
2325
+ {
2326
+ strcpy (workbuff , localize_month (tm -> tm_mon - 1 ));
2327
+ strcpy (inout , localized_str_tolower (workbuff ));
2328
+ }
2239
2329
else
2330
+ {
2240
2331
strcpy (inout , months [tm -> tm_mon - 1 ]);
2241
- * inout = pg_tolower ((unsigned char ) * inout );
2332
+ * inout = pg_tolower ((unsigned char ) * inout );
2333
+ }
2242
2334
return strlen (p_inout );
2243
2335
2244
2336
case DCH_MM :
@@ -2266,36 +2358,52 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
2266
2358
case DCH_DAY :
2267
2359
INVALID_FOR_INTERVAL ;
2268
2360
if (S_TM (suf ))
2361
+ {
2269
2362
strcpy (workbuff , localize_day_full (tm -> tm_wday ));
2363
+ sprintf (inout , "%*s" , 0 , localized_str_toupper (workbuff ));
2364
+ }
2270
2365
else
2366
+ {
2271
2367
strcpy (workbuff , days [tm -> tm_wday ]);
2272
- sprintf (inout , "%*s" , (S_FM (suf ) || S_TM (suf )) ? 0 : -9 , str_toupper (workbuff ));
2368
+ sprintf (inout , "%*s" , S_FM (suf ) ? 0 : -9 , str_toupper (workbuff ));
2369
+ }
2273
2370
return strlen (p_inout );
2274
2371
2275
2372
case DCH_Day :
2276
2373
INVALID_FOR_INTERVAL ;
2277
2374
if (S_TM (suf ))
2278
- sprintf (inout , "%*s" , 0 , localize_day_full (tm -> tm_wday ));
2375
+ sprintf (inout , "%*s" , 0 , localize_day_full (tm -> tm_wday ));
2279
2376
else
2280
2377
sprintf (inout , "%*s" , S_FM (suf ) ? 0 : -9 , days [tm -> tm_wday ]);
2281
2378
return strlen (p_inout );
2282
2379
2283
2380
case DCH_day :
2284
2381
INVALID_FOR_INTERVAL ;
2285
2382
if (S_TM (suf ))
2286
- sprintf (inout , "%*s" , 0 , localize_day_full (tm -> tm_wday ));
2383
+ {
2384
+ strcpy (workbuff , localize_day_full (tm -> tm_wday ));
2385
+ sprintf (inout , "%*s" , 0 , localized_str_tolower (workbuff ));
2386
+ }
2287
2387
else
2388
+ {
2288
2389
sprintf (inout , "%*s" , S_FM (suf ) ? 0 : -9 , days [tm -> tm_wday ]);
2289
- * inout = pg_tolower ((unsigned char ) * inout );
2390
+ * inout = pg_tolower ((unsigned char ) * inout );
2391
+ }
2290
2392
return strlen (p_inout );
2291
2393
2292
2394
case DCH_DY :
2293
2395
INVALID_FOR_INTERVAL ;
2294
2396
if (S_TM (suf ))
2295
- strcpy (inout , localize_day (tm -> tm_wday ));
2397
+ {
2398
+ strcpy (workbuff , localize_day (tm -> tm_wday ));
2399
+ strcpy (inout , localized_str_toupper (workbuff ));
2400
+ }
2296
2401
else
2402
+ {
2297
2403
strcpy (inout , days_short [tm -> tm_wday ]);
2298
- str_toupper (inout );
2404
+ str_toupper (inout );
2405
+ }
2406
+
2299
2407
return strlen (p_inout );
2300
2408
2301
2409
case DCH_Dy :
@@ -2309,10 +2417,15 @@ dch_date(int arg, char *inout, int suf, bool is_to_char, bool is_interval,
2309
2417
case DCH_dy :
2310
2418
INVALID_FOR_INTERVAL ;
2311
2419
if (S_TM (suf ))
2312
- strcpy (inout , localize_day (tm -> tm_wday ));
2420
+ {
2421
+ strcpy (workbuff , localize_day (tm -> tm_wday ));
2422
+ strcpy (inout , localized_str_tolower (workbuff ));
2423
+ }
2313
2424
else
2425
+ {
2314
2426
strcpy (inout , days_short [tm -> tm_wday ]);
2315
- * inout = pg_tolower ((unsigned char ) * inout );
2427
+ * inout = pg_tolower ((unsigned char ) * inout );
2428
+ }
2316
2429
return strlen (p_inout );
2317
2430
2318
2431
case DCH_DDD :
0 commit comments