Skip to content

Commit a21c3e3

Browse files
author
Thomas G. Lockhart
committed
Allow 't', 'T', and even/odd ASCII characters to denote true/false
rather than just 't' and 'T'. This allows yes/no and 1/0 to be interpreted as one might expect. Clean up function declarations to use bool as the type for arguments and return values.
1 parent 8fe55ef commit a21c3e3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/backend/utils/adt/bool.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.6 1997/09/08 02:30:26 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/bool.c,v 1.7 1997/10/09 05:06:12 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -23,20 +23,23 @@
2323

2424
/*
2525
* boolin - converts "t" or "f" to 1 or 0
26+
*
27+
* Check explicitly for "true/TRUE" and allow any odd ASCII value to be "true".
28+
* This handles "true/false", "yes/no", "1/0". - thomas 1997-10-05
2629
*/
2730
bool
2831
boolin(char *b)
2932
{
3033
if (b == NULL)
3134
elog(WARN, "Bad input string for type bool");
32-
return ((bool) (*b == 't') || (*b == 'T'));
35+
return ((bool) (((*b) == 't') || ((*b) == 'T') || ((*b) & 1)));
3336
}
3437

3538
/*
3639
* boolout - converts 1 or 0 to "t" or "f"
3740
*/
38-
char *
39-
boolout(long b)
41+
char *
42+
boolout(bool b)
4043
{
4144
char *result = (char *) palloc(2);
4245

@@ -50,25 +53,25 @@ boolout(long b)
5053
*****************************************************************************/
5154

5255
bool
53-
booleq(int8 arg1, int8 arg2)
56+
booleq(bool arg1, bool arg2)
5457
{
5558
return (arg1 == arg2);
5659
}
5760

5861
bool
59-
boolne(int8 arg1, int8 arg2)
62+
boolne(bool arg1, bool arg2)
6063
{
6164
return (arg1 != arg2);
6265
}
6366

6467
bool
65-
boollt(int8 arg1, int8 arg2)
68+
boollt(bool arg1, bool arg2)
6669
{
6770
return (arg1 < arg2);
6871
}
6972

7073
bool
71-
boolgt(int8 arg1, int8 arg2)
74+
boolgt(bool arg1, bool arg2)
7275
{
7376
return (arg1 > arg2);
7477
}

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