[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 12/13: [tbl]: Refactor table entry content validation.
From: |
G. Branden Robinson |
Subject: |
[groff] 12/13: [tbl]: Refactor table entry content validation. |
Date: |
Mon, 7 Oct 2024 08:00:16 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit be0488976d91cd18314ca68e285c8616ad7ce2a3
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Oct 6 12:40:15 2024 -0500
[tbl]: Refactor table entry content validation.
* src/preproc/tbl/table.cpp (table::add_entry): Refactor match attempts
for `\R` and `\z` in table entries to use new `find()` member function
of `string` class.
$ cat -n ./bad-escapes-in-tables.roff
1 This is my table.
2 .sp
3 .TS
4 L.
5 foo \" comment
6 bar\# another comment
7 baz\!qux
8 .\" This should produce no diagnostic.
9 T{
10 This is fine. \" fingers crossed\! [sic]
11 T}
12 \Rx
13 T{
14 \Rx \" this is bad trouble
15 T}
16 .\" as is the next line
17 qux\z
18 .TE
$ ./build/tbl ./bad-escapes-in-tables.roff >/dev/null
./build/tbl:./bad-escapes-in-tables.roff:5: warning: table entry contains
comment escape sequence '\"'
./build/tbl:./bad-escapes-in-tables.roff:5: warning: table entry contains
comment escape sequence '\#'
./build/tbl:./bad-escapes-in-tables.roff:7: warning: table entry contains
transparent throughput escape sequence '\!'
./build/tbl:./bad-escapes-in-tables.roff:14: warning: table entry contains
comment escape sequence '\"'
./build/tbl:./bad-escapes-in-tables.roff:14: warning: table entry contains
comment escape sequence '\#'
./build/tbl:./bad-escapes-in-tables.roff:14: error: repeating a glyph with
'\R' is not allowed in a text block
./build/tbl:./bad-escapes-in-tables.roff:17: error: table entry ends with
zero-motion escape sequence '\z'
---
ChangeLog | 6 ++++++
src/preproc/tbl/table.cpp | 12 ++++++------
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f7a91de07..7129aba6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-10-06 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/preproc/tbl/table.cpp (table::add_entry): Refactor match
+ attempts for `\R` and `\z` in table entries to use new `find()`
+ member function of `string` class.
+
2024-10-06 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/preproc/tbl/table.cpp (table::add_entry): Refactor to
diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp
index d0a19beca..3c4bd5a85 100644
--- a/src/preproc/tbl/table.cpp
+++ b/src/preproc/tbl/table.cpp
@@ -1558,17 +1558,17 @@ void table::add_entry(int r, int c, const string &str,
warning_with_file_and_line(fn, ln, "table entry contains"
" transparent throughput escape"
" sequence '\\!'");
- string last_two_chars = str.substring((len - 2), 2);
- if ("\\z" == last_two_chars)
+ // An incomplete \z sequence at the entry's end causes problems.
+ if (str.find("\\z") == (len - 2)) // max valid index is (len - 1)
error_with_file_and_line(fn, ln, "table entry ends with"
" zero-motion escape sequence '\\z'");
}
char *s = str.extract();
- if (str.search('\n') >= 0) {
+ if (str.search('\n') != -1) { // if it's a text block
bool was_changed = false;
- for (int i = 0; s[i] != '\0'; i++)
- if ((i > 0) && (s[(i - 1)] == '\\') && (s[i] == 'R')) {
- s[i] = '&';
+ int repeatpos = str.find("\\R");
+ if (repeatpos != -1) {
+ s[++repeatpos] = '&';
was_changed = true;
}
if (was_changed)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 12/13: [tbl]: Refactor table entry content validation.,
G. Branden Robinson <=