gbranden pushed a commit to branch master
in repository groff.
commit b2ee401f25ddc39783c648b22a16c9be563ba7bb
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Jul 1 23:48:15 2026 -0500
[tbl]: Refactor.
* src/preproc/tbl/main.cpp: ...to use our own string-trimming function
instead of the `remove_spaces()` member function of groff's bespoke
`string` class.
(trim_spaces): New function updates string parameter to remove leading
and trailing spaces.
(process_data): Call new function instead of member function.
---
ChangeLog | 9 +++++++++
src/preproc/tbl/main.cpp | 23 ++++++++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 3be419189..12137b9ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -34,6 +34,15 @@
Arrange equality comparisons to avoid inadvertent assignment to
lvalue (GBR style).
+2026-07-01 G. Branden Robinson <[email protected]>
+
+ * src/preproc/tbl/main.cpp: Refactor to use our own
+ string-trimming function instead of the `remove_spaces()` member
+ function of groff's bespoke `string` class.
+ (trim_spaces): New function updates string parameter to remove
+ leading and trailing spaces.
+ (process_data): Call new function instead of member function.
+
2026-07-01 G. Branden Robinson <[email protected]>
[tbl]: Test "nospaces" region option behavior.
diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp
index 8a751bf32..9487d9fe0 100644
--- a/src/preproc/tbl/main.cpp
+++ b/src/preproc/tbl/main.cpp
@@ -1315,6 +1315,27 @@ static format *process_format(table_input &in, options
*opt,
return f;
}
+// Update string `s` to remove leading and trailing spaces.
+static void trim_spaces(string &s)
+{
+ // Hand an empty string back as-is.
+ if (s.length() == 0)
+ return;
+ size_t len = s.length();
+ size_t beg = 0; // index of substring start
+ while ((beg < len) && (' ' == s[beg]))
+ beg++;
+ if (beg == len) {
+ // `s` contained only spaces.
+ s.clear();
+ return;
+ }
+ size_t end = len - 1;
+ while ((end > 0) && (' ' == s[end]))
+ end--;
+ s = s.substring(beg, (end - beg + 1));
+}
+
static table *process_data(table_input &in, format *f, options *opt)
{
char tab_char = opt->tab_char;
@@ -1399,7 +1420,7 @@ static table *process_data(table_input &in, format *f,
options *opt)
if (c == '\n')
--ln;
if ((opt->flags & table::NOSPACES))
- input_entry.remove_spaces();
+ trim_spaces(input_entry);
if (col >= ncolumns) {
// 1-based indices are more familiar to non-programmers.
// Those wishing to hack or debug register names used by
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit