From 143f1f7d2debb9f00eb9f0cf165dcabd5b1e3f986528910451d947153ddb9eda Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Sun, 10 Aug 2025 23:14:32 -0400 Subject: [PATCH] Some string cleanup --- dw/fltkui.cc | 18 +++++++++--------- dw/fltkui.hh | 8 ++++---- dw/ui.hh | 2 +- src/form.cc | 16 +++++----------- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/dw/fltkui.cc b/dw/fltkui.cc index 014a911..0fa0f87 100644 --- a/dw/fltkui.cc +++ b/dw/fltkui.cc @@ -1502,11 +1502,11 @@ void FltkOptionMenuResource::setItem (int index, bool selected) ((Fl_Choice *)widget)->value(menu+index); } -void FltkOptionMenuResource::pushGroup (const char *name, bool enabled) +void FltkOptionMenuResource::pushGroup (const std::string &name, bool enabled) { Fl_Menu_Item *item = newItem(); - item->text = dStrdup(name); + item->text = dStrdup( name.c_str() ); if (enabled == false) item->flags = FL_MENU_INACTIVE; @@ -1628,11 +1628,11 @@ void FltkListResource::widgetCallback (Fl_Widget *widget, void *data) } } -void *FltkListResource::newItem (const char *str, bool enabled, bool selected) +void *FltkListResource::newItem (const std::string &str, bool enabled, bool selected) { Fl_Browser *b = (Fl_Browser *) widget; int index = b->size() + 1; - char *label = (char *)malloc(strlen(str) + 1 + currDepth + 4), + char *label = (char *)malloc(str.size() + 1 + currDepth + 4), *s = label; memset(s, '\a', currDepth); @@ -1646,7 +1646,7 @@ void *FltkListResource::newItem (const char *str, bool enabled, bool selected) *s++ = '@'; *s++ = '.'; - strcpy(s, str); + strcpy(s, str.c_str()); b->add(label); free(label); @@ -1689,18 +1689,18 @@ void FltkListResource::setItem (int index, bool selected) b->select(index + 1, selected); } -void FltkListResource::pushGroup (const char *name, bool enabled) +void FltkListResource::pushGroup (const std::string &name_, bool enabled) { bool en = false; bool selected = false; + auto name= name_; // Fl_Browser_::incr_height() for item height won't do the right thing if // the first item doesn't have anything to it. - if (!name || !*name) - name = " "; + if( name.empty() ) name= " "; // TODO: Proper disabling of item groups - newItem(name, en, selected); + newItem(name.c_str(), en, selected); if (currDepth < 3) currDepth++; diff --git a/dw/fltkui.hh b/dw/fltkui.hh index d630219..030e9fc 100644 --- a/dw/fltkui.hh +++ b/dw/fltkui.hh @@ -456,7 +456,7 @@ protected: virtual bool setSelectedItems() { return false; } virtual void addItem (const char *str, bool enabled, bool selected) = 0; virtual void setItem (int index, bool selected) = 0; - virtual void pushGroup (const char *name, bool enabled) = 0; + virtual void pushGroup( const std::string &name, bool enabled ) = 0; virtual void popGroup () = 0; public: FltkSelectionResource (FltkPlatform *platform) : @@ -486,7 +486,7 @@ public: void addItem (const char *str, bool enabled, bool selected); void setItem (int index, bool selected); - void pushGroup (const char *name, bool enabled); + void pushGroup( const std::string &name, bool enabled ) override; void popGroup (); void sizeRequest (core::Requisition *requisition); @@ -503,7 +503,7 @@ protected: int getMaxItemWidth (); private: static void widgetCallback (Fl_Widget *widget, void *data); - void *newItem (const char *str, bool enabled, bool selected); + void *newItem (const std::string &str, bool enabled, bool selected); int currDepth; int colWidths[4]; int showRows; @@ -516,7 +516,7 @@ public: void addItem (const char *str, bool enabled, bool selected); void setItem (int index, bool selected); - void pushGroup (const char *name, bool enabled); + void pushGroup( const std::string &name, bool enabled ) override; void popGroup (); void sizeRequest (core::Requisition *requisition); diff --git a/dw/ui.hh b/dw/ui.hh index 79e7de0..cba534e 100644 --- a/dw/ui.hh +++ b/dw/ui.hh @@ -468,7 +468,7 @@ class SelectionResource: public Resource public: virtual void addItem (const char *str, bool enabled, bool selected) = 0; virtual void setItem (int index, bool selected) = 0; - virtual void pushGroup (const char *name, bool enabled) = 0; + virtual void pushGroup( const std::string &name, bool enabled ) = 0; virtual void popGroup () = 0; virtual int getNumberOfItems () = 0; diff --git a/src/form.cc b/src/form.cc index a6736e0..a4251e3 100644 --- a/src/form.cc +++ b/src/form.cc @@ -168,7 +168,7 @@ public: class DilloHtmlOptbase { public: - virtual ~DilloHtmlOptbase () {}; + virtual ~DilloHtmlOptbase ()= default; virtual bool isSelected() {return false;} virtual bool select() {return false;} virtual const char *getValue() {return NULL;} @@ -179,11 +179,10 @@ public: class DilloHtmlOptgroup : public DilloHtmlOptbase { private: - char *label; + std::string label; bool enabled; public: - DilloHtmlOptgroup (char *label, bool enabled); - virtual ~DilloHtmlOptgroup (); + DilloHtmlOptgroup (const std::string &label, bool enabled); void addSelf (SelectionResource *res) {res->pushGroup(label, enabled);} }; @@ -813,7 +812,7 @@ void Html_tag_open_optgroup(DilloHtml *html, const char *tag, int tagsize) label = ""; } - auto opt= std::make_unique< DilloHtmlOptgroup >( dStrdup( label.value().c_str() ), enabled ); + auto opt= std::make_unique< DilloHtmlOptgroup >( label.value(), enabled ); input->select->addOpt( std::move( opt ) ); } @@ -1897,17 +1896,12 @@ void DilloHtmlSelect::appendValuesTo (std::vector< std::string > &values, Select } } -DilloHtmlOptgroup::DilloHtmlOptgroup (char *label, bool enabled) +DilloHtmlOptgroup::DilloHtmlOptgroup (const std::string &label, bool enabled) { this->label = label; this->enabled = enabled; } -DilloHtmlOptgroup::~DilloHtmlOptgroup () -{ - dFree(label); -} - /* * DilloHtmlOption */