1997-03-04 06:32:26 +01:00
|
|
|
/*
|
|
|
|
* Edmund Mergl <E.Mergl@bawue.de>
|
|
|
|
*
|
1997-03-16 02:17:49 +01:00
|
|
|
* $Id: oracle_compat.c,v 1.4 1997/03/16 01:17:49 scrappy Exp $
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* LOWER
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* text *LOWER(text *string)
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string, with all letters forced to lowercase.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
1997-03-15 07:00:19 +01:00
|
|
|
LOWER(text *string)
|
1997-03-04 06:32:26 +01:00
|
|
|
{
|
1997-03-15 07:00:19 +01:00
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr_ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
int m;
|
|
|
|
|
|
|
|
m = VARSIZE(string) - VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
ret = (text *)malloc(VARSIZE(string));
|
|
|
|
VARSIZE(ret) = VARSIZE(string);
|
|
|
|
|
|
|
|
ptr = VARDATA(string);
|
|
|
|
ptr_ret = VARDATA(ret);
|
1997-03-04 06:32:26 +01:00
|
|
|
|
|
|
|
while (m--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = tolower(*ptr++);
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
return ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* UPPER
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* text *UPPER(text *string)
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string, with all letters forced to uppercase.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
1997-03-15 07:00:19 +01:00
|
|
|
UPPER(text *string)
|
1997-03-04 06:32:26 +01:00
|
|
|
{
|
1997-03-15 07:00:19 +01:00
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr_ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
int m;
|
|
|
|
|
|
|
|
m = VARSIZE(string) - VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
ret = (text *)malloc(VARSIZE(string));
|
|
|
|
VARSIZE(ret) = VARSIZE(string);
|
|
|
|
|
|
|
|
ptr = VARDATA(string);
|
|
|
|
ptr_ret = VARDATA(ret);
|
1997-03-04 06:32:26 +01:00
|
|
|
|
|
|
|
while (m--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = toupper(*ptr++);
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
return ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* INITCAP
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* text *INITCAP(text *string)
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string, with first letter of each word in uppercase,
|
|
|
|
* all other letters in lowercase. A word is delimited by white
|
|
|
|
* space.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
1997-03-15 07:00:19 +01:00
|
|
|
INITCAP(text *string)
|
1997-03-04 06:32:26 +01:00
|
|
|
{
|
1997-03-15 07:00:19 +01:00
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr_ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
int m;
|
|
|
|
|
|
|
|
m = VARSIZE(string) - VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
ret = (text *)malloc(VARSIZE(string));
|
|
|
|
VARSIZE(ret) = VARSIZE(string);
|
1997-03-04 06:32:26 +01:00
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
ptr = VARDATA(string);
|
|
|
|
ptr_ret = VARDATA(ret);
|
|
|
|
|
|
|
|
*ptr_ret++ = toupper(*ptr++);
|
1997-03-04 06:32:26 +01:00
|
|
|
--m;
|
|
|
|
|
|
|
|
while (m--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
if (*(ptr_ret - 1) == ' ' || *(ptr_ret - 1) == ' ') {
|
|
|
|
*ptr_ret++ = toupper(*ptr++);
|
1997-03-04 06:32:26 +01:00
|
|
|
} else {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = tolower(*ptr++);
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
return ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* LPAD
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* text *LPAD(text *string1, int4 len, text *string2)
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string1, left-padded to length len with the sequence of
|
|
|
|
* characters in string2.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
1997-03-15 07:00:19 +01:00
|
|
|
LPAD(text *string1, int4 len, text *string2)
|
1997-03-04 06:32:26 +01:00
|
|
|
{
|
|
|
|
text *ret;
|
1997-03-15 07:00:19 +01:00
|
|
|
char *ptr1, *ptr2, *ptr_ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
int m, n;
|
|
|
|
|
|
|
|
m = len - VARSIZE(string1) + VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0 || (VARSIZE(string2) - VARHDRSZ) <= 0) {
|
|
|
|
return string1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + len);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + len;
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
ptr2 = VARDATA(string2);
|
|
|
|
ptr_ret = VARDATA(ret);
|
1997-03-04 06:32:26 +01:00
|
|
|
|
|
|
|
while (m--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = *ptr2;
|
1997-03-04 06:32:26 +01:00
|
|
|
ptr2 = ptr2 == VARDATA(string2) + VARSIZE(string2) - VARHDRSZ - 1 ? VARDATA(string2) : ++ptr2;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = VARSIZE(string1) - VARHDRSZ;
|
|
|
|
ptr1 = VARDATA(string1);
|
|
|
|
|
|
|
|
while (n--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = *ptr1++;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* RPAD
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* text *RPAD(text *string1, int4 len, text *string2)
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string1, right-padded to length len with the sequence of
|
|
|
|
* characters in string2.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
1997-03-15 07:00:19 +01:00
|
|
|
RPAD(text *string1, int4 len, text *string2)
|
1997-03-04 06:32:26 +01:00
|
|
|
{
|
|
|
|
text *ret;
|
1997-03-15 07:00:19 +01:00
|
|
|
char *ptr1, *ptr2, *ptr_ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
int m, n;
|
|
|
|
|
|
|
|
m = len - VARSIZE(string1) + VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0 || (VARSIZE(string2) - VARHDRSZ) <= 0) {
|
|
|
|
return string1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + len);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + len;
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
n = VARSIZE(string1) - VARHDRSZ;
|
|
|
|
ptr1 = VARDATA(string1);
|
|
|
|
ptr_ret = VARDATA(ret);
|
1997-03-04 06:32:26 +01:00
|
|
|
|
|
|
|
while (n--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = *ptr1++;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr2 = VARDATA(string2);
|
|
|
|
|
|
|
|
while (m--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = *ptr2;
|
1997-03-04 06:32:26 +01:00
|
|
|
ptr2 = ptr2 == VARDATA(string2) + VARSIZE(string2) - VARHDRSZ - 1 ? VARDATA(string2) : ++ptr2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* LTRIM
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* text *LTRIM(text *string, text *set)
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string with initial characters removed up to the first
|
|
|
|
* character not in set.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
1997-03-15 07:00:19 +01:00
|
|
|
LTRIM(text *string, text *set)
|
1997-03-04 06:32:26 +01:00
|
|
|
{
|
1997-03-15 07:00:19 +01:00
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr2, *end2, *ptr_ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
int m;
|
|
|
|
|
|
|
|
m = VARSIZE(string) - VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0 || VARSIZE(set) - VARHDRSZ <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = VARDATA(string);
|
|
|
|
ptr2 = VARDATA(set);
|
|
|
|
end2 = VARDATA(set) + VARSIZE(set) - VARHDRSZ - 1;
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
while (ptr2 <= end2) {
|
|
|
|
if (*ptr == *ptr2) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++ptr2;
|
|
|
|
}
|
|
|
|
if (*ptr != *ptr2) {
|
|
|
|
break;
|
|
|
|
}
|
1997-03-15 07:00:19 +01:00
|
|
|
ptr++;
|
1997-03-04 06:32:26 +01:00
|
|
|
ptr2 = VARDATA(set);
|
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
++m;
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + m);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + m;
|
|
|
|
|
|
|
|
ptr_ret = VARDATA(ret);
|
1997-03-04 06:32:26 +01:00
|
|
|
|
|
|
|
while (m--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = *ptr++;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
return ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* RTRIM
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* text *RTRIM(text *string, text *set)
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string with final characters removed after the last
|
|
|
|
* character not in set.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
1997-03-15 07:00:19 +01:00
|
|
|
RTRIM(text *string, text *set)
|
1997-03-04 06:32:26 +01:00
|
|
|
{
|
1997-03-15 07:00:19 +01:00
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr2, *end2, *ptr_ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
int m;
|
|
|
|
|
|
|
|
m = VARSIZE(string) - VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0 || VARSIZE(set) - VARHDRSZ <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = VARDATA(string) + VARSIZE(string) - VARHDRSZ - 1;
|
|
|
|
ptr2 = VARDATA(set);
|
|
|
|
end2 = VARDATA(set) + VARSIZE(set) - VARHDRSZ - 1;
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
while (ptr2 <= end2) {
|
|
|
|
if (*ptr == *ptr2) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++ptr2;
|
|
|
|
}
|
|
|
|
if (*ptr != *ptr2) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--ptr;
|
|
|
|
ptr2 = VARDATA(set);
|
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
++m;
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + m);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + m;
|
|
|
|
|
|
|
|
ptr_ret = VARDATA(ret) + m - 1;
|
1997-03-04 06:32:26 +01:00
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
while (m--) {
|
|
|
|
*ptr_ret-- = *ptr--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* SUBSTR
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* text *SUBSTR(text *string, int4 m, int4 n)
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns a portion of string, beginning at character m, n
|
|
|
|
* characters long. The first position of string is 1.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
1997-03-15 07:00:19 +01:00
|
|
|
SUBSTR(text *string, int4 m, int4 n)
|
1997-03-04 06:32:26 +01:00
|
|
|
{
|
1997-03-15 07:00:19 +01:00
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr_ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = VARSIZE(string) - VARHDRSZ - m;
|
|
|
|
|
|
|
|
if (m <= 0 || n <= 0 || len <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
len = len + 1 < n ? len + 1 : n;
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + len);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + len;
|
|
|
|
|
|
|
|
ptr = VARDATA(string) + m - 1;
|
|
|
|
ptr_ret = VARDATA(ret);
|
1997-03-04 06:32:26 +01:00
|
|
|
|
|
|
|
while (len--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = *ptr++;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
return ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* TRANSLATE
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
1997-03-15 07:00:19 +01:00
|
|
|
* text *TRANSLATE(text *string, char from, char to)
|
1997-03-04 06:32:26 +01:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string after replacing all occurences of from with
|
|
|
|
* the corresponding character in to. TRANSLATE will not remove
|
|
|
|
* characters.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
1997-03-15 07:00:19 +01:00
|
|
|
TRANSLATE(text *string, char from, char to)
|
1997-03-04 06:32:26 +01:00
|
|
|
{
|
1997-03-15 07:00:19 +01:00
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr_ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
int m;
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
m = VARSIZE(string) - VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARSIZE(string));
|
|
|
|
VARSIZE(ret) = VARSIZE(string);
|
|
|
|
|
|
|
|
ptr = VARDATA(string);
|
|
|
|
ptr_ret = VARDATA(ret);
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
*ptr_ret++ = *ptr == from ? to : *ptr;
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1997-03-16 02:17:49 +01:00
|
|
|
#if 0
|
1997-03-15 07:00:19 +01:00
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* Functions in lower case are the equivalents with the last
|
|
|
|
* parameter beeing set to a reasonable default.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* lpad
|
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
|
|
|
* text *lpad(text *string1, int4 len)
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string1, left-padded to length len with blanks.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
|
|
|
lpad(text *string1, int4 len)
|
|
|
|
{
|
|
|
|
text *ret;
|
|
|
|
char *ptr1, *ptr_ret;
|
|
|
|
int m, n;
|
|
|
|
|
|
|
|
m = len - VARSIZE(string1) + VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0) {
|
|
|
|
return string1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + len);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + len;
|
|
|
|
|
|
|
|
ptr_ret = VARDATA(ret);
|
1997-03-04 06:32:26 +01:00
|
|
|
|
|
|
|
while (m--) {
|
1997-03-15 07:00:19 +01:00
|
|
|
*ptr_ret++ = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
n = VARSIZE(string1) - VARHDRSZ;
|
|
|
|
ptr1 = VARDATA(string1);
|
|
|
|
|
|
|
|
while (n--) {
|
|
|
|
*ptr_ret++ = *ptr1++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* rpad
|
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
|
|
|
* text *rpad(text *string1, int4 len)
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string1, right-padded to length len with blanks.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
|
|
|
rpad(text *string1, int4 len)
|
|
|
|
{
|
|
|
|
text *ret;
|
|
|
|
char *ptr1, *ptr_ret;
|
|
|
|
int m, n;
|
|
|
|
|
|
|
|
m = len - VARSIZE(string1) + VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0) {
|
|
|
|
return string1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + len);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + len;
|
|
|
|
|
|
|
|
n = VARSIZE(string1) - VARHDRSZ;
|
|
|
|
ptr1 = VARDATA(string1);
|
|
|
|
ptr_ret = VARDATA(ret);
|
|
|
|
|
|
|
|
while (n--) {
|
|
|
|
*ptr_ret++ = *ptr1++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
*ptr_ret++ = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* ltrim
|
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
|
|
|
* text *ltrim(text *string)
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string with initial blanks removed.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
|
|
|
ltrim(text *string)
|
|
|
|
{
|
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr_ret;
|
|
|
|
int m;
|
|
|
|
|
|
|
|
m = VARSIZE(string) - VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = VARDATA(string);
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
if (*ptr != ' ') {
|
|
|
|
break;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
++ptr;
|
|
|
|
}
|
|
|
|
|
1997-03-15 07:00:19 +01:00
|
|
|
++m;
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + m);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + m;
|
|
|
|
|
|
|
|
ptr_ret = VARDATA(ret);
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
*ptr_ret++ = *ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* rtrim
|
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
|
|
|
* text *rtrim(text *string)
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns string with final blanks removed.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
|
|
|
rtrim(text *string)
|
|
|
|
{
|
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr_ret;
|
|
|
|
int m;
|
|
|
|
|
|
|
|
m = VARSIZE(string) - VARHDRSZ;
|
|
|
|
|
|
|
|
if (m <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = VARDATA(string) + VARSIZE(string) - VARHDRSZ - 1;
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
if (*ptr != ' ') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
++m;
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + m);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + m;
|
|
|
|
|
|
|
|
ptr_ret = VARDATA(ret) + m - 1;
|
|
|
|
|
|
|
|
while (m--) {
|
|
|
|
*ptr_ret-- = *ptr--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* substr
|
|
|
|
*
|
|
|
|
* Syntax:
|
|
|
|
*
|
|
|
|
* text *substr(text *string, int4 m)
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Returns a portion of string, beginning at character m, up to
|
|
|
|
* the end of string. The first position of string is 1.
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
text *
|
|
|
|
substr(text *string, int4 m)
|
|
|
|
{
|
|
|
|
text *ret;
|
|
|
|
char *ptr, *ptr_ret;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = VARSIZE(string) - VARHDRSZ - m;
|
|
|
|
|
|
|
|
if (m <= 0 || len <= 0) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = len + 1;
|
|
|
|
|
|
|
|
ret = (text *)malloc(VARHDRSZ + len);
|
|
|
|
VARSIZE(ret) = VARHDRSZ + len;
|
|
|
|
|
|
|
|
ptr = VARDATA(string) + m - 1;
|
|
|
|
ptr_ret = VARDATA(ret);
|
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
*ptr_ret++ = *ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
1997-03-04 06:32:26 +01:00
|
|
|
}
|
|
|
|
|
1997-03-16 02:17:49 +01:00
|
|
|
#endif
|
1997-03-04 06:32:26 +01:00
|
|
|
|
|
|
|
/* EOF */
|