From a51b81a970554e81455d26b8b1586805b5ef6c9f6ba56da0e0eb30c17f9c1293 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 17 Aug 2025 20:17:59 -0400 Subject: [PATCH] About text is now C++-ified. --- src/IO/IO.hh | 4 +++- src/IO/Makefile.am | 2 +- src/IO/{about.c => about.cc} | 10 ++++++++++ src/cache.cc | 13 ++++++------- 4 files changed, 20 insertions(+), 9 deletions(-) rename src/IO/{about.c => about.cc} (93%) diff --git a/src/IO/IO.hh b/src/IO/IO.hh index d67d28e..e5e4c19 100644 --- a/src/IO/IO.hh +++ b/src/IO/IO.hh @@ -1,6 +1,8 @@ #ifndef __IO_H__ #define __IO_H__ +#include + #include "d_size.h" #include "../../dlib/dlib.h" #include "../chain.hh" @@ -28,7 +30,7 @@ /* * Exported data */ -extern const char *AboutSplash; +const std::string_view getAboutSplash(); #endif /* __IO_H__ */ diff --git a/src/IO/Makefile.am b/src/IO/Makefile.am index 11796d7..446ca6c 100644 --- a/src/IO/Makefile.am +++ b/src/IO/Makefile.am @@ -25,7 +25,7 @@ endif libDiof_a_SOURCES = \ mime.cc \ mime.hh \ - about.c \ + about.cc \ Url.h \ http.cc \ tls.hh \ diff --git a/src/IO/about.c b/src/IO/about.cc similarity index 93% rename from src/IO/about.c rename to src/IO/about.cc index 33dae43..39b925f 100644 --- a/src/IO/about.c +++ b/src/IO/about.cc @@ -10,8 +10,12 @@ * (at your option) any later version. */ +#include + #include +namespace +{ /** * HTML text for startup screen */ @@ -52,4 +56,10 @@ const char *const AboutSplash= "\n" "\n" "\n"; +} +std::string_view +getAboutSplash() +{ + return AboutSplash; +} diff --git a/src/cache.cc b/src/cache.cc index c8e73d7..c79fce1 100644 --- a/src/cache.cc +++ b/src/cache.cc @@ -89,7 +89,7 @@ static uint_t DelayedQueueIdleId = 0; static CacheEntry_t *Cache_process_queue(CacheEntry_t *entry); static void Cache_delayed_process_queue(CacheEntry_t *entry); static void Cache_auth_entry(CacheEntry_t *entry, BrowserWindow *bw); -static void Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds); +static void Cache_entry_inject(const DilloUrl *Url, std::string_view data_ds); /** * Determine if two cache entries are equal (used by CachedURLs) @@ -124,9 +124,8 @@ void a_Cache_init(void) /* inject the splash screen in the cache */ { auto url = a_Url_new("about:splash", NULL); - Dstr *ds = dStr_new(AboutSplash); - Cache_entry_inject(url.get(), ds); - dStr_free(ds, 1); + const auto about = getAboutSplash(); + Cache_entry_inject(url.get(), about); } } @@ -265,17 +264,17 @@ static CacheEntry_t *Cache_entry_add(const DilloUrl *Url) * Inject full page content directly into the cache. * Used for "about:splash". May be used for "about:cache" too. */ -static void Cache_entry_inject(const DilloUrl *Url, Dstr *data_ds) +static void Cache_entry_inject(const DilloUrl *Url, const std::string_view data_ds) { CacheEntry_t *entry; if (!(entry = Cache_entry_search(Url))) entry = Cache_entry_add(Url); entry->Flags = CA_GotHeader + CA_GotLength + CA_InternalUrl; - if (data_ds->len) + if (data_ds.size()) entry->Flags &= ~CA_IsEmpty; dStr_truncate(entry->Data, 0); - dStr_append_l(entry->Data, data_ds->str, data_ds->len); + dStr_append_l(entry->Data, data_ds.data(), data_ds.size()); dStr_fit(entry->Data); entry->ExpectedSize = entry->TransferSize = entry->Data->len; }