Skip to content

Commit 9f19470

Browse files
committed
Simplify code in formatting.c now that to upper/lower/initcase do not
modify the passed string.
1 parent abb5fd8 commit 9f19470

File tree

1 file changed

+15
-65
lines changed

1 file changed

+15
-65
lines changed

src/backend/utils/adt/formatting.c

Lines changed: 15 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -----------------------------------------------------------------------
22
* formatting.c
33
*
4-
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.140 2008/05/19 18:08:15 tgl Exp $
4+
* $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.141 2008/05/20 01:41:02 momjian Exp $
55
*
66
*
77
* Portions Copyright (c) 1999-2008, PostgreSQL Global Development Group
@@ -1894,10 +1894,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
18941894
if (!tm->tm_mon)
18951895
break;
18961896
if (S_TM(n->suffix))
1897-
{
1898-
strcpy(workbuff, localized_full_months[tm->tm_mon - 1]);
1899-
sprintf(s, "%*s", 0, str_toupper(workbuff));
1900-
}
1897+
strcpy(s, str_toupper(localized_full_months[tm->tm_mon - 1]));
19011898
else
19021899
{
19031900
strcpy(workbuff, months_full[tm->tm_mon - 1]);
@@ -1910,25 +1907,17 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
19101907
if (!tm->tm_mon)
19111908
break;
19121909
if (S_TM(n->suffix))
1913-
{
1914-
strcpy(workbuff, localized_full_months[tm->tm_mon - 1]);
1915-
sprintf(s, "%*s", 0, str_initcap(workbuff));
1916-
}
1910+
strcpy(s, str_initcap(localized_full_months[tm->tm_mon - 1]));
19171911
else
1918-
{
19191912
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, months_full[tm->tm_mon - 1]);
1920-
}
19211913
s += strlen(s);
19221914
break;
19231915
case DCH_month:
19241916
INVALID_FOR_INTERVAL;
19251917
if (!tm->tm_mon)
19261918
break;
19271919
if (S_TM(n->suffix))
1928-
{
1929-
strcpy(workbuff, localized_full_months[tm->tm_mon - 1]);
1930-
sprintf(s, "%*s", 0, str_tolower(workbuff));
1931-
}
1920+
strcpy(s, str_tolower(localized_full_months[tm->tm_mon - 1]));
19321921
else
19331922
{
19341923
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, months_full[tm->tm_mon - 1]);
@@ -1941,41 +1930,27 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
19411930
if (!tm->tm_mon)
19421931
break;
19431932
if (S_TM(n->suffix))
1944-
{
1945-
strcpy(workbuff, localized_abbrev_months[tm->tm_mon - 1]);
1946-
sprintf(s, "%*s", 0, str_toupper(workbuff));
1947-
}
1933+
strcpy(s, str_toupper(localized_abbrev_months[tm->tm_mon - 1]));
19481934
else
1949-
{
1950-
strcpy(workbuff, months[tm->tm_mon - 1]);
1951-
sprintf(s, "%*s", 0, str_toupper(workbuff));
1952-
}
1935+
strcpy(s, str_toupper(months[tm->tm_mon - 1]));
19531936
s += strlen(s);
19541937
break;
19551938
case DCH_Mon:
19561939
INVALID_FOR_INTERVAL;
19571940
if (!tm->tm_mon)
19581941
break;
19591942
if (S_TM(n->suffix))
1960-
{
1961-
strcpy(workbuff, localized_abbrev_months[tm->tm_mon - 1]);
1962-
sprintf(s, "%*s", 0, str_initcap(workbuff));
1963-
}
1943+
strcpy(s, str_initcap(localized_abbrev_months[tm->tm_mon - 1]));
19641944
else
1965-
{
19661945
strcpy(s, months[tm->tm_mon - 1]);
1967-
}
19681946
s += strlen(s);
19691947
break;
19701948
case DCH_mon:
19711949
INVALID_FOR_INTERVAL;
19721950
if (!tm->tm_mon)
19731951
break;
19741952
if (S_TM(n->suffix))
1975-
{
1976-
strcpy(workbuff, localized_abbrev_months[tm->tm_mon - 1]);
1977-
sprintf(s, "%*s", 0, str_tolower(workbuff));
1978-
}
1953+
strcpy(s, str_tolower(localized_abbrev_months[tm->tm_mon - 1]));
19791954
else
19801955
{
19811956
strcpy(s, months[tm->tm_mon - 1]);
@@ -1992,10 +1967,7 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
19921967
case DCH_DAY:
19931968
INVALID_FOR_INTERVAL;
19941969
if (S_TM(n->suffix))
1995-
{
1996-
strcpy(workbuff, localized_full_days[tm->tm_wday]);
1997-
sprintf(s, "%*s", 0, str_toupper(workbuff));
1998-
}
1970+
strcpy(s, str_toupper(localized_full_days[tm->tm_wday]));
19991971
else
20001972
{
20011973
strcpy(workbuff, days[tm->tm_wday]);
@@ -2006,23 +1978,15 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
20061978
case DCH_Day:
20071979
INVALID_FOR_INTERVAL;
20081980
if (S_TM(n->suffix))
2009-
{
2010-
strcpy(workbuff, localized_full_days[tm->tm_wday]);
2011-
sprintf(s, "%*s", 0, str_initcap(workbuff));
2012-
}
1981+
strcpy(s, str_initcap(localized_full_days[tm->tm_wday]));
20131982
else
2014-
{
20151983
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, days[tm->tm_wday]);
2016-
}
20171984
s += strlen(s);
20181985
break;
20191986
case DCH_day:
20201987
INVALID_FOR_INTERVAL;
20211988
if (S_TM(n->suffix))
2022-
{
2023-
strcpy(workbuff, localized_full_days[tm->tm_wday]);
2024-
sprintf(s, "%*s", 0, str_tolower(workbuff));
2025-
}
1989+
strcpy(s, str_tolower(localized_full_days[tm->tm_wday]));
20261990
else
20271991
{
20281992
sprintf(s, "%*s", S_FM(n->suffix) ? 0 : -9, days[tm->tm_wday]);
@@ -2033,37 +1997,23 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out)
20331997
case DCH_DY:
20341998
INVALID_FOR_INTERVAL;
20351999
if (S_TM(n->suffix))
2036-
{
2037-
strcpy(workbuff, localized_abbrev_days[tm->tm_wday]);
2038-
sprintf(s, "%*s", 0, str_toupper(workbuff));
2039-
}
2000+
strcpy(s, str_toupper(localized_abbrev_days[tm->tm_wday]));
20402001
else
2041-
{
2042-
strcpy(workbuff, days_short[tm->tm_wday]);
2043-
sprintf(s, "%*s", 0, str_toupper(workbuff));
2044-
}
2002+
strcpy(s, str_toupper(days_short[tm->tm_wday]));
20452003
s += strlen(s);
20462004
break;
20472005
case DCH_Dy:
20482006
INVALID_FOR_INTERVAL;
20492007
if (S_TM(n->suffix))
2050-
{
2051-
strcpy(workbuff, localized_abbrev_days[tm->tm_wday]);
2052-
sprintf(s, "%*s", 0, str_initcap(workbuff));
2053-
}
2008+
strcpy(s, str_initcap(localized_abbrev_days[tm->tm_wday]));
20542009
else
2055-
{
20562010
strcpy(s, days_short[tm->tm_wday]);
2057-
}
20582011
s += strlen(s);
20592012
break;
20602013
case DCH_dy:
20612014
INVALID_FOR_INTERVAL;
20622015
if (S_TM(n->suffix))
2063-
{
2064-
strcpy(workbuff, localized_abbrev_days[tm->tm_wday]);
2065-
sprintf(s, "%*s", 0, str_tolower(workbuff));
2066-
}
2016+
strcpy(s, str_tolower(localized_abbrev_days[tm->tm_wday]));
20672017
else
20682018
{
20692019
strcpy(s, days_short[tm->tm_wday]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy