Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitafa71c7

Browse files
author
Thomas G. Lockhart
committed
Add routines to help with single-byte (internal) character type support.
1 parentb5b5f0d commitafa71c7

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
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.19.2.1 1998/12/14 00:13:55 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
returnarg1==arg2;
155155
}
156+
157+
int8
158+
text_char(text*arg1)
159+
{
160+
return ((int8)*(VARDATA(arg1)));
161+
}
162+
163+
text*
164+
char_text(int8arg1)
165+
{
166+
text*result;
167+
168+
result=palloc(VARHDRSZ+1);
169+
VARSIZE(result)=VARHDRSZ+1;
170+
*(VARDATA(result))=arg1;
171+
172+
returnresult;
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.44 1998/10/08 18:30:12 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.44.2.1 1998/12/14 00:13:56 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,int32m,int32n)
@@ -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
returnstring;
341343

342344
len=VARSIZE(string)-VARHDRSZ;
343345
#ifdefMULTIBYTE
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+
elseif (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
#ifdefMULTIBYTE
361369
p=VARDATA(string);
362370
for (i=0;i<m;i++)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp