Skip to content

Commit 239564e

Browse files
author
Thomas G. Lockhart
committed
Add routines to help with single-byte (internal) character type support.
1 parent f9f4004 commit 239564e

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

src/backend/utils/adt/char.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.19 1998/09/01 03:25:50 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.20 1998/12/13 23:35:48 thomas Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -29,7 +29,7 @@ int32
2929
charin(char *ch)
3030
{
3131
if (ch == NULL)
32-
return (int32) NULL;
32+
return (int32) '\0';
3333
return (int32) *ch;
3434
}
3535

@@ -153,3 +153,21 @@ cideq(int8 arg1, int8 arg2)
153153
{
154154
return arg1 == arg2;
155155
}
156+
157+
int8
158+
text_char(text *arg1)
159+
{
160+
return ((int8) *(VARDATA(arg1)));
161+
}
162+
163+
text *
164+
char_text(int8 arg1)
165+
{
166+
text *result;
167+
168+
result = palloc(VARHDRSZ+1);
169+
VARSIZE(result) = VARHDRSZ+1;
170+
*(VARDATA(result)) = arg1;
171+
172+
return result;
173+
}

src/backend/utils/adt/varlena.c

Lines changed: 19 additions & 11 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/varlena.c,v 1.45 1998/12/08 06:19:15 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.46 1998/12/13 23:35:48 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -313,16 +313,18 @@ textcat(text *t1, text *t2)
313313
* - starting position (is one-based)
314314
* - string length
315315
*
316-
* If the starting position is zero or less, then return the entire string.
317-
* XXX Note that this may not be the right behavior:
318-
* if we are calculating the starting position we might want it to start at one.
316+
* If the starting position is zero or less, then return from the start of the string
317+
* adjusting the length to be consistant with the "negative start" per SQL92.
319318
* If the length is less than zero, return the remaining string.
320319
*
321320
* Note that the arguments operate on octet length,
322321
* so not aware of multi-byte character sets.
323322
*
324323
* Added multi-byte support.
325324
* - Tatsuo Ishii 1998-4-21
325+
* Changed behavior if starting position is less than one to conform to SQL92 behavior.
326+
* Formerly returned the entire string; now returns a portion.
327+
* - Thomas Lockhart 1998-12-10
326328
*/
327329
text *
328330
text_substr(text *string, int32 m, int32 n)
@@ -336,27 +338,33 @@ text_substr(text *string, int32 m, int32 n)
336338

337339
#endif
338340

339-
if ((string == (text *) NULL) || (m <= 0))
341+
if (string == (text *) NULL)
340342
return string;
341343

342344
len = VARSIZE(string) - VARHDRSZ;
343345
#ifdef MULTIBYTE
344346
len = pg_mbstrlen_with_len(VARDATA(string), len);
345347
#endif
346348

347-
/* m will now become a zero-based starting position */
349+
/* starting position after the end of the string? */
348350
if (m > len)
349351
{
350-
m = 0;
352+
m = 1;
351353
n = 0;
352354
}
353-
else
355+
/* starting position before the start of the string?
356+
* then offset into the string per SQL92 spec... */
357+
else if (m < 1)
354358
{
355-
m--;
356-
if (((m + n) > len) || (n < 0))
357-
n = (len - m);
359+
n += (m-1);
360+
m = 1;
358361
}
359362

363+
/* m will now become a zero-based starting position */
364+
m--;
365+
if (((m + n) > len) || (n < 0))
366+
n = (len - m);
367+
360368
#ifdef MULTIBYTE
361369
p = VARDATA(string);
362370
for (i = 0; i < m; i++)

src/include/utils/builtins.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: builtins.h,v 1.71 1998/12/08 06:18:34 thomas Exp $
9+
* $Id: builtins.h,v 1.72 1998/12/13 23:36:48 thomas Exp $
1010
*
1111
* NOTES
1212
* This should normally only be included by fmgr.h.
@@ -60,6 +60,8 @@ extern int8 charmi(int8 arg1, int8 arg2);
6060
extern int8 charmul(int8 arg1, int8 arg2);
6161
extern int8 chardiv(int8 arg1, int8 arg2);
6262
extern bool cideq(int8 arg1, int8 arg2);
63+
extern int8 text_char(text *arg1);
64+
extern text* char_text(int8 arg1);
6365

6466
/* int.c */
6567
extern int32 int2in(char *num);

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