mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Accept 'on' and 'off' as input for boolean data type, unifying the syntax
that the data type and GUC accepts. ITAGAKI Takahiro
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
* Written by Peter Eisentraut <peter_e@gmx.net>.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.496 2009/02/28 00:10:51 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.497 2009/03/09 14:34:34 petere Exp $
|
||||
*
|
||||
*--------------------------------------------------------------------
|
||||
*/
|
||||
@ -4086,74 +4086,6 @@ ReportGUCOption(struct config_generic * record)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Try to interpret value as boolean value. Valid values are: true,
|
||||
* false, yes, no, on, off, 1, 0; as well as unique prefixes thereof.
|
||||
* If the string parses okay, return true, else false.
|
||||
* If okay and result is not NULL, return the value in *result.
|
||||
*/
|
||||
bool
|
||||
parse_bool(const char *value, bool *result)
|
||||
{
|
||||
size_t len = strlen(value);
|
||||
|
||||
if (pg_strncasecmp(value, "true", len) == 0)
|
||||
{
|
||||
if (result)
|
||||
*result = true;
|
||||
}
|
||||
else if (pg_strncasecmp(value, "false", len) == 0)
|
||||
{
|
||||
if (result)
|
||||
*result = false;
|
||||
}
|
||||
|
||||
else if (pg_strncasecmp(value, "yes", len) == 0)
|
||||
{
|
||||
if (result)
|
||||
*result = true;
|
||||
}
|
||||
else if (pg_strncasecmp(value, "no", len) == 0)
|
||||
{
|
||||
if (result)
|
||||
*result = false;
|
||||
}
|
||||
|
||||
/* 'o' is not unique enough */
|
||||
else if (pg_strncasecmp(value, "on", (len > 2 ? len : 2)) == 0)
|
||||
{
|
||||
if (result)
|
||||
*result = true;
|
||||
}
|
||||
else if (pg_strncasecmp(value, "off", (len > 2 ? len : 2)) == 0)
|
||||
{
|
||||
if (result)
|
||||
*result = false;
|
||||
}
|
||||
|
||||
else if (pg_strcasecmp(value, "1") == 0)
|
||||
{
|
||||
if (result)
|
||||
*result = true;
|
||||
}
|
||||
else if (pg_strcasecmp(value, "0") == 0)
|
||||
{
|
||||
if (result)
|
||||
*result = false;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (result)
|
||||
*result = false; /* suppress compiler warning */
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Try to parse value as an integer. The accepted formats are the
|
||||
* usual decimal, octal, or hexadecimal formats, optionally followed by
|
||||
|
Reference in New Issue
Block a user