From daf6057d4853c69bcd9b0b6c4b0e127acab11aae Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 3 Oct 2021 18:06:37 +0100 Subject: [PATCH] Convert WSelectList to std::string --- vaudioselector.cc | 12 ++++++------ vserverselect.cc | 4 ++-- wremoteconfig.cc | 2 +- wselectlist.cc | 18 ++++++++---------- wselectlist.h | 5 +++-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/vaudioselector.cc b/vaudioselector.cc index f4bae22..0c25eef 100644 --- a/vaudioselector.cc +++ b/vaudioselector.cc @@ -221,7 +221,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, bool* availableMpegAudi { if (!ac.name.empty()) { - asl.addOption(ac.name.c_str(), &ac, (ac.pestype == currentAudioChannel)); + asl.addOption(ac.name, &ac, (ac.pestype == currentAudioChannel)); } else { @@ -231,7 +231,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, bool* availableMpegAudi else if (ac.type == 1) tempString = "ac3 " + std::to_string(ac.pestype - PES_AUDIO_AC3_START); else tempString = "unknown"; - asl.addOption(tempString.c_str(), &ac, (ac.pestype == currentAudioChannel)); + asl.addOption(tempString, &ac, (ac.pestype == currentAudioChannel)); } } } @@ -252,7 +252,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, bool* availableMpegAudi if (!sc.name.empty()) { - ssl.addOption(sc.name.c_str(), &sc, selected); + ssl.addOption(sc.name, &sc, selected); } else { @@ -261,7 +261,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, bool* availableMpegAudi if (sc.type == 0x10) tempString = std::to_string(sc.pestype - PES_DVBSUBTITLE_START); else tempString = "unknown"; - ssl.addOption(tempString.c_str(), &sc, selected); + ssl.addOption(tempString, &sc, selected); } } } @@ -365,7 +365,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, Channel* channel, int c { for (auto& ac : acl) { - asl.addOption(ac.name.c_str(), &ac, (ac.pestype == currentAudioChannel)); + asl.addOption(ac.name, &ac, (ac.pestype == currentAudioChannel)); } } else @@ -381,7 +381,7 @@ VAudioSelector::VAudioSelector(MessageReceiver* tparent, Channel* channel, int c { bool selected = false; if ((sc.type == currentSubtitletype) && (sc.pestype == currentSubtitleChannel)) selected = true; - ssl.addOption(sc.name.c_str(), &sc, selected); + ssl.addOption(sc.name, &sc, selected); } } diff --git a/vserverselect.cc b/vserverselect.cc index 0f01528..99a8961 100644 --- a/vserverselect.cc +++ b/vserverselect.cc @@ -48,10 +48,10 @@ VServerSelect::VServerSelect(const VDPC& servers, MessageReceiver* treplyTo) sl.setSize(area.w - 20, area.h - 30 - 15); add(&sl); - sl.addOption(servers[0].name.c_str(), 0, 1); + sl.addOption(servers[0].name, 0, 1); for(UINT k = 1; k < servers.numServers(); k++) { - sl.addOption(servers[k].name.c_str(), 0, 0); + sl.addOption(servers[k].name, 0, 0); } replyTo = treplyTo; diff --git a/wremoteconfig.cc b/wremoteconfig.cc index 5377d61..06029d8 100644 --- a/wremoteconfig.cc +++ b/wremoteconfig.cc @@ -75,7 +75,7 @@ void WRemoteConfig::initSelectList(bool startup) line += inputMan->getHardCodedHardwareKeyNamesForVompKey(static_cast(i)); line += " \t"; // FIXME extra spaces for braindead strtok. Ditch strtok. line += inputMan->getAllHardwareKeyNamesAssignedToVompKey(static_cast(i)); - sl.addOption(line.c_str(), reinterpret_cast(i), 0); + sl.addOption(line, reinterpret_cast(i), 0); } } diff --git a/wselectlist.cc b/wselectlist.cc index ba34cf7..21381fe 100644 --- a/wselectlist.cc +++ b/wselectlist.cc @@ -39,7 +39,6 @@ void WSelectList::clear() int vsize = options.size(); for (int i = 0; i < vsize; i++) { - delete[] options[i].text; if (options[i].pict) delete options[i].pict; } options.clear(); @@ -76,8 +75,7 @@ int WSelectList::addOption(const char* text, void* data, int selected, TVMediaIn int thisNewOption = options.size(); wsloption wslo; - wslo.text = new char[strlen(text) + 1]; - strcpy(wslo.text, text); + wslo.text = text; wslo.data = data; wslo.pict = pict; options.push_back(wslo); @@ -85,13 +83,12 @@ int WSelectList::addOption(const char* text, void* data, int selected, TVMediaIn return thisNewOption; } -int WSelectList::addOption(const std::string& text, void* data, int selected, TVMediaInfo* pict) // FIXME convert WSelectList wslo to use std::string +int WSelectList::addOption(const std::string& text, void* data, int selected, TVMediaInfo* pict) { int thisNewOption = options.size(); wsloption wslo; - wslo.text = new char[text.length() + 1]; - strcpy(wslo.text, text.c_str()); + wslo.text = text; wslo.data = data; wslo.pict = pict; options.push_back(wslo); @@ -150,7 +147,7 @@ int WSelectList::getColumn(int x) return columns[x]; } -void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict) +void WSelectList::drawOptionLine(const std::string& text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict) { UINT curline = 0; UINT taboffset = 0; @@ -170,12 +167,13 @@ void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, cons if (!numColumns && linesPerOption == 1) { - drawText(text, xpos, ypos, width, colour); + drawText(text.c_str(), xpos, ypos, width, colour); } else { + const char* ctext = text.c_str(); char buffer[200]; - strncpy(buffer, text, 199); + strncpy(buffer, ctext, 199); int currentColumn = taboffset; char* pointer; char* savepointer; @@ -188,7 +186,7 @@ void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, cons pointer = STRTOKR(NULL, "\t\n", &savepointer); if (pointer) { - char delimiter = text[pointer - buffer - 1]; + char delimiter = ctext[pointer - buffer - 1]; if (delimiter == '\t') currentColumn++; else if (delimiter == '\n') { diff --git a/wselectlist.h b/wselectlist.h index f59775d..a76a9a1 100644 --- a/wselectlist.h +++ b/wselectlist.h @@ -20,6 +20,7 @@ #ifndef WSELECTLIST_H #define WSELECTLIST_H +#include #include #include "defines.h" @@ -27,7 +28,7 @@ typedef struct { - char* text; + std::string text; void* data; TVMediaInfo* pict; } wsloption; @@ -70,7 +71,7 @@ class WSelectList : public Boxx virtual bool mouseAndroidScroll(int x, int y, int sx, int sy); private: - void drawOptionLine(char* text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict); + void drawOptionLine(const std::string& text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict); int getMouseLine(int x, int y); DrawStyle backgroundColour; -- 2.39.5