Skip to content

Commit bd9d962

Browse files
committed
Modify input and output routines to print plain binary strings without any
'b' prefixes.
1 parent 0f3720e commit bd9d962

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

src/backend/utils/adt/varbit.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.12 2000/11/16 21:43:28 petere Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varbit.c,v 1.13 2000/11/18 16:18:41 petere Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -50,7 +50,7 @@
5050
Datum
5151
zpbit_in(PG_FUNCTION_ARGS)
5252
{
53-
char *s = PG_GETARG_CSTRING(0);
53+
char *input_string = PG_GETARG_CSTRING(0);
5454
#ifdef NOT_USED
5555
Oid typelem = PG_GETARG_OID(1);
5656
#endif
@@ -67,17 +67,27 @@ zpbit_in(PG_FUNCTION_ARGS)
6767
bits8 x = 0;
6868

6969
/* Check that the first character is a b or an x */
70-
if (s[0] == 'b' || s[0] == 'B')
70+
if (input_string[0] == 'b' || input_string[0] == 'B')
71+
{
7172
bit_not_hex = true;
72-
else if (s[0] == 'x' || s[0] == 'X')
73+
sp = input_string + 1;
74+
}
75+
else if (input_string[0] == 'x' || input_string[0] == 'X')
76+
{
7377
bit_not_hex = false;
78+
sp = input_string + 1;
79+
}
7480
else
7581
{
76-
elog(ERROR, "zpbit_in: %s is not a valid bitstring", s);
77-
bit_not_hex = false; /* keep compiler quiet */
82+
/*
83+
* Otherwise it's binary. This allows things like cast('1001'
84+
* as bit) to work transparently.
85+
*/
86+
bit_not_hex = true;
87+
sp = input_string;
7888
}
7989

80-
slen = strlen(s) - 1;
90+
slen = strlen(sp);
8191
/* Determine bitlength from input string */
8292
if (bit_not_hex)
8393
bitlen = slen;
@@ -104,7 +114,6 @@ zpbit_in(PG_FUNCTION_ARGS)
104114
VARATT_SIZEP(result) = len;
105115
VARBITLEN(result) = atttypmod;
106116

107-
sp = s + 1;
108117
r = VARBITS(result);
109118
if (bit_not_hex)
110119
{
@@ -283,7 +292,7 @@ _zpbit(PG_FUNCTION_ARGS)
283292
Datum
284293
varbit_in(PG_FUNCTION_ARGS)
285294
{
286-
char *s = PG_GETARG_CSTRING(0);
295+
char *input_string = PG_GETARG_CSTRING(0);
287296
#ifdef NOT_USED
288297
Oid typelem = PG_GETARG_OID(1);
289298
#endif
@@ -300,17 +309,23 @@ varbit_in(PG_FUNCTION_ARGS)
300309
bits8 x = 0;
301310

302311
/* Check that the first character is a b or an x */
303-
if (s[0] == 'b' || s[0] == 'B')
312+
if (input_string[0] == 'b' || input_string[0] == 'B')
313+
{
304314
bit_not_hex = true;
305-
else if (s[0] == 'x' || s[0] == 'X')
315+
sp = input_string + 1;
316+
}
317+
else if (input_string[0] == 'x' || input_string[0] == 'X')
318+
{
306319
bit_not_hex = false;
320+
sp = input_string + 1;
321+
}
307322
else
308323
{
309-
elog(ERROR, "varbit_in: %s is not a valid bitstring", s);
310-
bit_not_hex = false; /* keep compiler quiet */
324+
bit_not_hex = true;
325+
sp = input_string;
311326
}
312327

313-
slen = strlen(s) - 1;
328+
slen = strlen(sp);
314329
/* Determine bitlength from input string */
315330
if (bit_not_hex)
316331
bitlen = slen;
@@ -337,7 +352,6 @@ varbit_in(PG_FUNCTION_ARGS)
337352
VARATT_SIZEP(result) = len;
338353
VARBITLEN(result) = Min(bitlen, atttypmod);
339354

340-
sp = s + 1;
341355
r = VARBITS(result);
342356
if (bit_not_hex)
343357
{
@@ -418,10 +432,9 @@ varbit_out(PG_FUNCTION_ARGS)
418432
len;
419433

420434
len = VARBITLEN(s);
421-
result = (char *) palloc(len + 2);
435+
result = (char *) palloc(len + 1);
422436
sp = VARBITS(s);
423437
r = result;
424-
*r++ = 'B';
425438
for (i = 0; i < len - BITS_PER_BYTE; i += BITS_PER_BYTE, sp++)
426439
{
427440
x = *sp;
@@ -1224,8 +1237,10 @@ bitposition(PG_FUNCTION_ARGS)
12241237
if (p == VARBITEND(arg)) {
12251238
mask2 = end_mask << (BITS_PER_BYTE - is);
12261239
is_match = mask2 == 0;
1240+
#if 0
12271241
elog(NOTICE,"S. %d %d em=%2x sm=%2x r=%d",
12281242
i,is,end_mask,mask2,is_match);
1243+
#endif
12291244
break;
12301245
}
12311246
cmp = *s << (BITS_PER_BYTE - is);

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