gbranden pushed a commit to branch master
in repository groff.
commit 025d6604839dafe2d80cde94429d20edde0100a2
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Feb 21 03:56:49 2025 -0600
[troff]: Add member functions to `token` class.
...to assist with runtime character analysis.
* src/roff/troff/token.h (class charinfo): Declare new public member
functions `is_character()`, `is_indexed_character()`, and
`character_index()`.
(token::is_character): New function returns whether the object has
`type` of `TOKEN_CHAR`, `TOKEN_SPECIAL_CHAR`, or `TOKEN_INDEXED_CHAR`.
(token::is_indexed_character): New function returns whether the object
has `type` of `TOKEN_INDEXED_CHAR`.
(token::character_index): New function returns value of `val` private
member variable. Throws assertion if token's `type` is not
`TOKEN_INDEXED_CHAR`.
---
ChangeLog | 17 +++++++++++++++++
src/roff/troff/token.h | 25 +++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index 87278eaeb..afad02463 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2025-02-21 G. Branden Robinson <[email protected]>
+
+ [troff]: Add member functions to `token` class to assist with
+ runtime character analysis.
+
+ * src/roff/troff/token.h (class charinfo): Declare new public
+ member functions `is_character()`, `is_indexed_character()`, and
+ `character_index()`.
+ (token::is_character): New function returns whether the object
+ has `type` of `TOKEN_CHAR`, `TOKEN_SPECIAL_CHAR`, or
+ `TOKEN_INDEXED_CHAR`.
+ (token::is_indexed_character): New function returns whether the
+ object has `type` of `TOKEN_INDEXED_CHAR`.
+ (token::character_index): New function returns value of `val`
+ private member variable. Throws assertion if token's `type` is
+ not `TOKEN_INDEXED_CHAR`.
+
2025-02-21 G. Branden Robinson <[email protected]>
[libgroff]: Validate character indices in font description files
diff --git a/src/roff/troff/token.h b/src/roff/troff/token.h
index f6709e7e4..796d2b1bf 100644
--- a/src/roff/troff/token.h
+++ b/src/roff/troff/token.h
@@ -16,6 +16,11 @@ for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
class charinfo;
struct node;
@@ -74,7 +79,9 @@ public:
bool is_unstretchable_space();
bool is_horizontal_space();
bool is_white_space();
+ bool is_character();
bool is_special_character();
+ bool is_indexed_character();
bool is_newline();
bool is_tab();
bool is_leader();
@@ -91,6 +98,7 @@ public:
bool operator==(const token &); // for delimiters & conditional exprs
bool operator!=(const token &); // ditto
unsigned char ch();
+ int character_index();
charinfo *get_char(bool /* required */ = false);
bool add_to_zero_width_node_list(node **);
void make_space();
@@ -192,6 +200,23 @@ inline unsigned char token::ch()
return type == TOKEN_CHAR ? c : '\0';
}
+inline bool token::is_character()
+{
+ return (TOKEN_CHAR == type) || (TOKEN_SPECIAL_CHAR == type)
+ || (TOKEN_INDEXED_CHAR == type);
+}
+
+inline bool token::is_indexed_character()
+{
+ return TOKEN_INDEXED_CHAR == type;
+}
+
+inline int token::character_index()
+{
+ assert(TOKEN_INDEXED_CHAR == type);
+ return val;
+}
+
inline bool token::is_eof()
{
return type == TOKEN_EOF;
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit