gnucash stable: [gnc-html.cpp] remove unused buggy string conversion functions

Christopher Lam clam at code.gnucash.org
Thu Apr 16 10:09:35 EDT 2026


Updated	 via  https://github.com/Gnucash/gnucash/commit/3da38203 (commit)
	from  https://github.com/Gnucash/gnucash/commit/9f8f4d9e (commit)



commit 3da38203ffbcb12fabd5dbcca1ea5758aa29141a
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Apr 16 21:46:41 2026 +0800

    [gnc-html.cpp] remove unused buggy string conversion functions
    
    they're not compliant RFC1738, buggy, and are unused.

diff --git a/gnucash/html/gnc-html.cpp b/gnucash/html/gnc-html.cpp
index 075ab3a330..198ab974cd 100644
--- a/gnucash/html/gnc-html.cpp
+++ b/gnucash/html/gnc-html.cpp
@@ -707,148 +707,6 @@ gnc_build_url( URLType type, const gchar* location, const gchar* label ) noexcep
     }
 }
 
-/********************************************************************
- * gnc_html_encode_string
- * RFC 1738 encoding of string for submission with an HTML form.
- * GPL code lifted from gtkhtml.  copyright notice:
- *
- * Copyright (C) 1997 Martin Jones (mjones at kde.org)
- * Copyright (C) 1997 Torben Weis (weis at kde.org)
- * Copyright (C) 1999 Helix Code, Inc.
- ********************************************************************/
-
-char *
-gnc_html_encode_string(const char * str_in) noexcept
-{
-    if (!str_in) return nullptr;
-
-    constexpr gchar safe[] = "$-._!*(),"; /* RFC 1738 */
-    std::string encoded;
-    constexpr size_t BUF_SIZE = 5;
-    gchar buffer[BUF_SIZE];
-    guchar c;
-    std::string str = str_in;
-
-    for (const char ch : str)
-    {
-        c = static_cast<guchar>(ch);
-        if ((( c >= 'A') && ( c <= 'Z')) ||
-                (( c >= 'a') && ( c <= 'z')) ||
-                (( c >= '0') && ( c <= '9')) ||
-                (std::strchr(safe, c)))
-        {
-            encoded.push_back(c);
-        }
-        else if ( c == ' ' )
-        {
-            encoded.push_back(' ');
-        }
-        else if ( c == '\n' )
-        {
-            encoded.append("%0D%0A");
-        }
-        else if ( c != '\r' )
-        {
-            std::snprintf( buffer, BUF_SIZE, "%%%02X", static_cast<int>(c) );
-            encoded.append(buffer, BUF_SIZE);
-        }
-    }
-
-    return strdup(encoded.c_str());
-}
-
-
-char *
-gnc_html_decode_string(const char * str) noexcept
-{
-    if (!str) return nullptr;
-
-    constexpr gchar safe[] = "$-._!*(),"; /* RFC 1738 */
-    std::string decoded;
-    guchar  c;
-    guint   hexval;
-    std::string_view sv = str;
-
-    for (size_t i = 0; i < sv.size(); i++)
-    {
-        c = static_cast<guchar>(sv[i]);
-        if ((( c >= 'A') && ( c <= 'Z')) ||
-                (( c >= 'a') && ( c <= 'z')) ||
-                (( c >= '0') && ( c <= '9')) ||
-                (std::strchr(safe, c)))
-        {
-            decoded.push_back(c);
-        }
-        else if ( c == '+' )
-        {
-            decoded.push_back(' ');
-        }
-        else if (sv.substr(i,5).compare("%0D0A") == 0)
-        {
-            decoded.push_back('\n');
-            i += 4;
-        }
-        else if (c == '%')
-        {
-            // this logic preassumes that the number after '%' is a single character ?
-            if (1 == std::sscanf(sv.substr(i+1).data(), "%02X", &hexval))
-                decoded.push_back(static_cast<char>(hexval));
-            else
-                decoded.push_back(' ');
-            i += 2;
-        }
-    }
-
-    return strdup(decoded.c_str());
-}
-
-/********************************************************************
- * escape/unescape_newlines : very simple string encoding for GPG
- * ASCII-armored text.
- ********************************************************************/
-
-char *
-gnc_html_unescape_newlines(const gchar * in) noexcept
-{
-    std::string rv;
-    std::string_view sv = in;
-
-    for (size_t i = 0; i < sv.size(); i++)
-    {
-        if (sv.substr(i,2).compare("\\n") == 0)
-        {
-            rv.push_back('\n');
-            i++;
-        }
-        else
-        {
-            rv.push_back(sv[i]);
-        }
-    }
-
-    return strdup(rv.c_str());
-}
-
-char *
-gnc_html_escape_newlines(const gchar * in) noexcept
-{
-    std::string escaped;
-    std::string_view sv = in;
-
-    for (const char c : sv)
-    {
-        if (c == '\012')
-        {
-            escaped.append("\\n");
-        }
-        else
-        {
-            escaped.push_back(c);
-        }
-    }
-    return strdup(escaped.c_str());
-}
-
 void
 gnc_html_register_object_handler( const char * classid,
                                   GncHTMLObjectCB hand ) noexcept



Summary of changes:
 gnucash/html/gnc-html.cpp | 142 ----------------------------------------------
 1 file changed, 142 deletions(-)



More information about the gnucash-changes mailing list