mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Massive commit to run PGINDENT on all *.c and *.h files.
This commit is contained in:
@ -1,13 +1,13 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* stringutils.c--
|
||||
* simple string manipulation routines
|
||||
* simple string manipulation routines
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.10 1997/08/25 19:41:52 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.11 1997/09/07 04:55:27 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -30,70 +30,82 @@
|
||||
/* MODIFIES the string passed in and returns the head of it */
|
||||
|
||||
#ifdef NOT_USED
|
||||
static char *leftTrim(char *s)
|
||||
static char *
|
||||
leftTrim(char *s)
|
||||
{
|
||||
char *s2 = s;
|
||||
int shift=0;
|
||||
int j=0;
|
||||
char *s2 = s;
|
||||
int shift = 0;
|
||||
int j = 0;
|
||||
|
||||
while (isspace(*s))
|
||||
{ s++; shift++;}
|
||||
if (shift > 0)
|
||||
{
|
||||
while ( (s2[j] = s2[j+shift]) !='\0')
|
||||
j++;
|
||||
}
|
||||
while (isspace(*s))
|
||||
{
|
||||
s++;
|
||||
shift++;
|
||||
}
|
||||
if (shift > 0)
|
||||
{
|
||||
while ((s2[j] = s2[j + shift]) != '\0')
|
||||
j++;
|
||||
}
|
||||
|
||||
return s2;
|
||||
return s2;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
char *rightTrim(char *s)
|
||||
char *
|
||||
rightTrim(char *s)
|
||||
{
|
||||
char *sEnd;
|
||||
sEnd = s+strlen(s)-1;
|
||||
while (sEnd >= s && isspace(*sEnd))
|
||||
sEnd--;
|
||||
if (sEnd < s)
|
||||
s[0]='\0';
|
||||
else
|
||||
s[sEnd-s+1]='\0';
|
||||
return s;
|
||||
char *sEnd;
|
||||
|
||||
sEnd = s + strlen(s) - 1;
|
||||
while (sEnd >= s && isspace(*sEnd))
|
||||
sEnd--;
|
||||
if (sEnd < s)
|
||||
s[0] = '\0';
|
||||
else
|
||||
s[sEnd - s + 1] = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
#ifdef NOT_USED
|
||||
static char *doubleTrim(char *s)
|
||||
static char *
|
||||
doubleTrim(char *s)
|
||||
{
|
||||
strcpy(s,leftTrim(rightTrim(s)));
|
||||
return s;
|
||||
strcpy(s, leftTrim(rightTrim(s)));
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef STRINGUTILS_TEST
|
||||
void testStringUtils()
|
||||
void
|
||||
testStringUtils()
|
||||
{
|
||||
static char *tests[] = {" goodbye \n", /* space on both ends */
|
||||
"hello world", /* no spaces to trim */
|
||||
"", /* empty string */
|
||||
"a", /* string with one char*/
|
||||
" ", /* string with one whitespace*/
|
||||
NULL_STR};
|
||||
static char *tests[] = {" goodbye \n", /* space on both ends */
|
||||
"hello world", /* no spaces to trim */
|
||||
"", /* empty string */
|
||||
"a", /* string with one char */
|
||||
" ", /* string with one whitespace */
|
||||
NULL_STR};
|
||||
|
||||
int i=0;
|
||||
while (tests[i]!=NULL_STR)
|
||||
{
|
||||
char *t;
|
||||
t = strdup(tests[i]);
|
||||
printf("leftTrim(%s) = ",t);
|
||||
printf("%sEND\n", leftTrim(t));
|
||||
t = strdup(tests[i]);
|
||||
printf("rightTrim(%s) = ",t);
|
||||
printf("%sEND\n", rightTrim(t));
|
||||
t = strdup(tests[i]);
|
||||
printf("doubleTrim(%s) = ",t);
|
||||
printf("%sEND\n", doubleTrim(t));
|
||||
i++;
|
||||
}
|
||||
int i = 0;
|
||||
|
||||
while (tests[i] != NULL_STR)
|
||||
{
|
||||
char *t;
|
||||
|
||||
t = strdup(tests[i]);
|
||||
printf("leftTrim(%s) = ", t);
|
||||
printf("%sEND\n", leftTrim(t));
|
||||
t = strdup(tests[i]);
|
||||
printf("rightTrim(%s) = ", t);
|
||||
printf("%sEND\n", rightTrim(t));
|
||||
t = strdup(tests[i]);
|
||||
printf("doubleTrim(%s) = ", t);
|
||||
printf("%sEND\n", doubleTrim(t));
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user