summaryrefslogtreecommitdiff
path: root/pith/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'pith/string.c')
-rw-r--r--pith/string.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/pith/string.c b/pith/string.c
index d2d0d75..a349c3f 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
@@ -131,6 +132,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';
+}
/*----------------------------------------------------------------------
@@ -2997,3 +3023,35 @@ convert_decimal_to_alpha (char *rn, size_t len, long n, char l)
if(i < len) rn[i] = '\0';
rn[len-1] = '\0';
}
+
+
+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++;
+ }
+}
+