1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <string.h>
#include "gis.h"
/*
* squeeze - edit superfluous white space out of strings
*
* char *G_squeeze (s)
* char *s;
*
* scan a string of text, converting tabs to spaces and
* compressing out leading spaces, redundant internal spaces,
* and trailing spaces.
* returns the address of the resulting compressed string.
*
* last modification: 12 aug 81, j w hamilton
*
* 1998-04-04 WBH
* Also squeezes out newlines -- easier to use with fgets()
*
* 1999-19-12 Werner Droege
* changed line 37, line 48ff. -- return (strip_NL(line))
*/
#include <ctype.h>
/*!
* \brief remove unnecessary white space
*
* Leading and trailing white space is removed from the string <b>s</b> and internal
* white space which is more than one character is reduced to a single space
* character. White space here means spaces, tabs, linefeeds, newlines, and
* formfeeds. Returns <b>s.</b>
*
* \param s
* \return char *
*/
char *G_squeeze (char *line)
{
register char *f = line, *t = line;
int l;
/* skip over space at the beginning of the line. */
while (isspace (*f))
f++;
while (*f)
if (! isspace (*f))
*t++ = *f++;
else
if (*++f)
if (! isspace (*f))
*t++ = ' ';
*t = '\0';
l=strlen(line)-1;
if(*(line+l)=='\n') *(line+l)='\0';
return line;
}
|