diff options
Diffstat (limited to 'pith/string.c')
-rw-r--r-- | pith/string.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/pith/string.c b/pith/string.c index 84717c3e..2cd43d7d 100644 --- a/pith/string.c +++ b/pith/string.c @@ -20,6 +20,7 @@ static char rcsid[] = "$Id: string.c 910 2008-01-14 22:28:38Z hubert@u.washingto string.c Misc extra and useful string functions - rplstr replace a substring with another string + - collspaces consecutive spaces are reduced to one space. - sqzspaces Squeeze out the extra blanks in a string - sqznewlines Squeeze out \n and \r. - removing_trailing_white_space @@ -132,6 +133,31 @@ rplstr(char *os, size_t oslen, int dl, char *is) return(x3); } +/*---------------------------------------------------------------------- + collapse blank space + ----------------------------------------------------------------------*/ +void +collspaces(char *string) +{ + char *p = string; + int only_one_space = 0; + + if(!string) + return; + + for(;isspace(*p); p++); + + while(*string = *p++) + if(!isspace((unsigned char)*string)){ + only_one_space = 0; + string++; + } + else if(!only_one_space){ + string++; + only_one_space++; + } + *string = '\0'; +} /*---------------------------------------------------------------------- @@ -2860,3 +2886,35 @@ free_strlist(STRLIST_S **strp) fs_give((void **) strp); } } + + +void +removing_extra_stuff(string) + char *string; +{ + char *p = NULL; + int change = 0, length = 0; + + + if(!string) + return; + + for(; *string; string++, length++) + p = ((unsigned char)*string != ',') ? NULL : (!p) ? string : p; + + if(p) + *p = '\0'; + + string -= length; + for (; *string; string++){ + if (change){ + *string = ' '; + change = 0; + } + if ((((unsigned char)*string == ' ') || + ((unsigned char)*string == ',')) && + ((unsigned char)*(string + 1) == ',')) + change++; + } +} + |