added stripTrailingBlanksStringBuf()
authorroot <devnull@localhost>
Tue, 2 Jul 1996 19:16:06 +0000 (19:16 +0000)
committerroot <devnull@localhost>
Tue, 2 Jul 1996 19:16:06 +0000 (19:16 +0000)
CVS patchset: 717
CVS date: 1996/07/02 19:16:06

lib/stringbuf.c
lib/stringbuf.h

index 5025f7f..57009b1 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdlib.h>
+#include <ctype.h>
 #include "stringbuf.h"
 
 #define BUF_CHUNK 1024
@@ -36,6 +37,18 @@ void truncStringBuf(StringBuf sb)
     sb->free = sb->allocated;
 }
 
+void stripTrailingBlanksStringBuf(StringBuf sb)
+{
+    while (sb->free != sb->allocated) {
+       if (! isspace(*(sb->tail - 1))) {
+           break;
+       }
+       sb->free++;
+       sb->tail--;
+    }
+    sb->tail[0] = '\0';
+}
+
 char *getStringBuf(StringBuf sb)
 {
     return sb->buf;
index bd93705..fa7da5c 100644 (file)
@@ -7,6 +7,7 @@ StringBuf newStringBuf(void);
 void freeStringBuf(StringBuf sb);
 void truncStringBuf(StringBuf sb);
 char *getStringBuf(StringBuf sb);
+void stripTrailingBlanksStringBuf(StringBuf sb);
 
 #define appendStringBuf(sb, s)     appendStringBufAux(sb, s, 0)
 #define appendLineStringBuf(sb, s) appendStringBufAux(sb, s, 1)