summaryrefslogtreecommitdiffstats
path: root/contrib/groff/src/libs/libgroff/string.cc
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/groff/src/libs/libgroff/string.cc')
-rw-r--r--contrib/groff/src/libs/libgroff/string.cc38
1 files changed, 34 insertions, 4 deletions
diff --git a/contrib/groff/src/libs/libgroff/string.cc b/contrib/groff/src/libs/libgroff/string.cc
index 4bcd4cc..2ef547e 100644
--- a/contrib/groff/src/libs/libgroff/string.cc
+++ b/contrib/groff/src/libs/libgroff/string.cc
@@ -1,5 +1,6 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002
+ Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -18,10 +19,10 @@ You should have received a copy of the GNU General Public License along
with groff; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-#include <stdio.h>
-#include "stringclass.h"
#include "lib.h"
+#include "stringclass.h"
+
static char *salloc(int len, int *sizep);
static void sfree(char *ptr, int size);
static char *sfree_alloc(char *ptr, int size, int len, int *sizep);
@@ -290,10 +291,39 @@ char *string::extract() const
for (i = 0; i < n; i++)
if (p[i] != '\0')
*r++ = p[i];
- q[n] = '\0';
+ *r = '\0';
return q;
}
+void string::remove_spaces()
+{
+ int l = len - 1;
+ while (l >= 0 && ptr[l] == ' ')
+ l--;
+ char *p = ptr;
+ if (l > 0)
+ while (*p == ' ') {
+ p++;
+ l--;
+ }
+ if (len - 1 != l) {
+ if (l >= 0) {
+ len = l + 1;
+ char *tmp = new char[len];
+ memcpy(tmp, p, len);
+ a_delete ptr;
+ ptr = tmp;
+ }
+ else {
+ len = 0;
+ if (ptr) {
+ a_delete ptr;
+ ptr = 0;
+ }
+ }
+ }
+}
+
void put_string(const string &s, FILE *fp)
{
int len = s.length();
OpenPOWER on IntegriCloud