mirror of
https://github.com/postgres/postgres.git
synced 2025-08-21 10:42:50 +03:00
Non-decimal integer literals
Add support for hexadecimal, octal, and binary integer literals: 0x42F 0o273 0b100101 per SQL:202x draft. This adds support in the lexer as well as in the integer type input functions. Reviewed-by: John Naylor <john.naylor@enterprisedb.com> Reviewed-by: Zhihong Yu <zyu@yugabyte.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Reviewed-by: Dean Rasheed <dean.a.rasheed@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/b239564c-cad0-b23e-c57e-166d883cb97d@enterprisedb.com
This commit is contained in:
@@ -385,11 +385,46 @@ make_const(ParseState *pstate, A_Const *aconst)
|
||||
{
|
||||
/* could be an oversize integer as well as a float ... */
|
||||
|
||||
int base = 10;
|
||||
char *startptr;
|
||||
int sign;
|
||||
char *testvalue;
|
||||
int64 val64;
|
||||
char *endptr;
|
||||
|
||||
startptr = aconst->val.fval.fval;
|
||||
if (startptr[0] == '-')
|
||||
{
|
||||
sign = -1;
|
||||
startptr++;
|
||||
}
|
||||
else
|
||||
sign = +1;
|
||||
if (startptr[0] == '0')
|
||||
{
|
||||
if (startptr[1] == 'b' || startptr[1] == 'B')
|
||||
{
|
||||
base = 2;
|
||||
startptr += 2;
|
||||
}
|
||||
else if (startptr[1] == 'o' || startptr[1] == 'O')
|
||||
{
|
||||
base = 8;
|
||||
startptr += 2;
|
||||
}
|
||||
if (startptr[1] == 'x' || startptr[1] == 'X')
|
||||
{
|
||||
base = 16;
|
||||
startptr += 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (sign == +1)
|
||||
testvalue = startptr;
|
||||
else
|
||||
testvalue = psprintf("-%s", startptr);
|
||||
errno = 0;
|
||||
val64 = strtoi64(aconst->val.fval.fval, &endptr, 10);
|
||||
val64 = strtoi64(testvalue, &endptr, base);
|
||||
if (errno == 0 && *endptr == '\0')
|
||||
{
|
||||
/*
|
||||
|
Reference in New Issue
Block a user