From a63a3e3ce39fac9f9e4bfd7c6acd09fb36324d03 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Fri, 5 Dec 2025 16:38:53 +0800 Subject: [PATCH] [sixtp-dom-parsers.cpp] introduce dom_node_to_text for solo text node allocation-free returns const char* or nullptr --- libgnucash/backend/xml/sixtp-dom-parsers.cpp | 9 +++++++++ libgnucash/backend/xml/sixtp-dom-parsers.h | 1 + 2 files changed, 10 insertions(+) diff --git a/libgnucash/backend/xml/sixtp-dom-parsers.cpp b/libgnucash/backend/xml/sixtp-dom-parsers.cpp index bd2f4ed9b4..2619858462 100644 --- a/libgnucash/backend/xml/sixtp-dom-parsers.cpp +++ b/libgnucash/backend/xml/sixtp-dom-parsers.cpp @@ -35,6 +35,15 @@ static QofLogModule log_module = GNC_MOD_IO; +const char* +dom_node_to_text (xmlNodePtr node) noexcept +{ + if (node && node->children && node->children->type == XML_TEXT_NODE + && !node->children->next) + return reinterpret_cast(node->children->content); + return nullptr; +} + std::optional dom_tree_to_guid (xmlNodePtr node) { diff --git a/libgnucash/backend/xml/sixtp-dom-parsers.h b/libgnucash/backend/xml/sixtp-dom-parsers.h index d23ae63606..37083438d9 100644 --- a/libgnucash/backend/xml/sixtp-dom-parsers.h +++ b/libgnucash/backend/xml/sixtp-dom-parsers.h @@ -45,6 +45,7 @@ gboolean dom_tree_valid_time64 (time64 ts, const xmlChar* name); GDate* dom_tree_to_gdate (xmlNodePtr node); gnc_numeric dom_tree_to_gnc_numeric (xmlNodePtr node); gchar* dom_tree_to_text (xmlNodePtr tree); +const char* dom_node_to_text (xmlNodePtr node) noexcept; gboolean string_to_binary (const gchar* str, void** v, guint64* data_len); gboolean dom_tree_create_instance_slots (xmlNodePtr node, QofInstance* inst);