diff options
author | wlemb <wlemb> | 2002-09-08 14:34:44 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2002-09-08 14:34:44 +0000 |
commit | b249406e25561c519a93a0f5f9a36ffa24fc8f27 (patch) | |
tree | 65c70eeb33a32e441de700dd576a57e5f643fa07 /src/libs/libgroff | |
parent | c6cc41386e05bffef2798977a691cd6655593942 (diff) | |
download | groff-b249406e25561c519a93a0f5f9a36ffa24fc8f27.tar.gz |
Add global option `nospaces' to tbl so that leading and trailing
spaces in data items are ignored.
* src/libs/libgroff/string.cc (string::remove_spaces): New member
function to remove leading and trailing spaces.
* src/include/stringclass.h: Updated.
* src/preproc/tbl/table.h (table): Add flag `NOSPACES'.
* src/preproc/tbl/main.cc (process_options): Handle `nospaces'
option.
Fix typo in error messages.
(process_data): Implement `nospaces' option.
* src/preproc/tbl/tbl.man, NEWS, doc/webpage.ms: Updated.
Diffstat (limited to 'src/libs/libgroff')
-rw-r--r-- | src/libs/libgroff/string.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/libs/libgroff/string.cc b/src/libs/libgroff/string.cc index ef1dbb20..97cf50e5 100644 --- a/src/libs/libgroff/string.cc +++ b/src/libs/libgroff/string.cc @@ -1,5 +1,6 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001 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. @@ -294,6 +295,35 @@ char *string::extract() const 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(); |