1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* char.c--
|
1997-09-07 07:04:48 +02:00
|
|
|
* Functions for the built-in type "char".
|
|
|
|
* Functions for the built-in type "cid".
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
1998-12-14 00:36:48 +01:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/utils/adt/char.c,v 1.20 1998/12/13 23:35:48 thomas Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
#include <stdio.h> /* for sprintf() */
|
1996-07-09 08:22:35 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include "postgres.h"
|
|
|
|
#include "utils/palloc.h"
|
|
|
|
#include "utils/builtins.h" /* where the declarations go */
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* USER I/O ROUTINES *
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* charin - converts "x" to 'x'
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
int32
|
|
|
|
charin(char *ch)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
if (ch == NULL)
|
1998-12-14 00:36:48 +01:00
|
|
|
return (int32) '\0';
|
1998-09-01 05:29:17 +02:00
|
|
|
return (int32) *ch;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* charout - converts 'x' to "x"
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
char *
|
1997-09-07 07:04:48 +02:00
|
|
|
charout(int32 ch)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *result = (char *) palloc(2);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
result[0] = (char) ch;
|
|
|
|
result[1] = '\0';
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* cidin - converts "..." to internal representation.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* NOTE: we must not use 'charin' because cid might be a non
|
|
|
|
* printable character...
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
int32
|
|
|
|
cidin(char *s)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
CommandId c;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (s == NULL)
|
|
|
|
c = 0;
|
|
|
|
else
|
|
|
|
c = atoi(s);
|
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
return (int32) c;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-09-07 07:04:48 +02:00
|
|
|
* cidout - converts a cid to "..."
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* NOTE: we must no use 'charout' because cid might be a non
|
|
|
|
* printable character...
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
char *
|
1997-09-07 07:04:48 +02:00
|
|
|
cidout(int32 c)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *result;
|
|
|
|
CommandId c2;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-11-02 16:27:14 +01:00
|
|
|
result = palloc(12);
|
1997-09-07 07:04:48 +02:00
|
|
|
c2 = (CommandId) c;
|
|
|
|
sprintf(result, "%u", (unsigned) (c2));
|
1998-09-01 05:29:17 +02:00
|
|
|
return result;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* PUBLIC ROUTINES *
|
1996-07-09 08:22:35 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
bool
|
|
|
|
chareq(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 == arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 22:59:27 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
bool
|
|
|
|
charne(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 != arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 22:59:27 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
bool
|
|
|
|
charlt(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return (uint8) arg1 < (uint8) arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 22:59:27 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
bool
|
|
|
|
charle(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return (uint8) arg1 <= (uint8) arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 22:59:27 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
bool
|
|
|
|
chargt(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return (uint8) arg1 > (uint8) arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 22:59:27 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
bool
|
|
|
|
charge(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return (uint8) arg1 >= (uint8) arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 22:59:27 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
int8
|
|
|
|
charpl(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 + arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 22:59:27 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
int8
|
|
|
|
charmi(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 - arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 22:59:27 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
int8
|
|
|
|
charmul(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 * arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 22:59:27 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
int8
|
|
|
|
chardiv(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 / arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
bool
|
|
|
|
cideq(int8 arg1, int8 arg2)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1998-09-01 05:29:17 +02:00
|
|
|
return arg1 == arg2;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1998-12-14 00:36:48 +01:00
|
|
|
|
|
|
|
int8
|
|
|
|
text_char(text *arg1)
|
|
|
|
{
|
|
|
|
return ((int8) *(VARDATA(arg1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
text *
|
|
|
|
char_text(int8 arg1)
|
|
|
|
{
|
|
|
|
text *result;
|
|
|
|
|
|
|
|
result = palloc(VARHDRSZ+1);
|
|
|
|
VARSIZE(result) = VARHDRSZ+1;
|
|
|
|
*(VARDATA(result)) = arg1;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|