refactor(strhelpers): extract shared strReplaceAll helper (#7711)

Co-authored-by: philmoz <philmoz@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Peter Feerick
2026-08-27 09:39:10 +10:00
committed by GitHub
co-authored by philmoz Claude Sonnet 5
parent 2b9b8fd479
commit 8347285abe
9 changed files with 95 additions and 52 deletions
@@ -317,7 +317,8 @@ ScreenAddPage::ScreenAddPage(const PageDef& pageDef) : PageGroupItem(pageDef)
void ScreenAddPage::build(Window* window)
{
std::string s = replaceAll(STR_QM_ADD_SCREEN, "\n", " ");
std::string s(STR_QM_ADD_SCREEN);
strReplaceAll(s, "\n", " ");
new TextButton(window,
rect_t{LCD_W / 2 - ADD_TXT_W / 2, window->height() / 2 - EdgeTxStyles::UI_ELEMENT_HEIGHT, ADD_TXT_W, EdgeTxStyles::UI_ELEMENT_HEIGHT},
@@ -193,7 +193,8 @@ void PageGroupHeaderBase::setTitle(const char* title)
{
if (titleLabel) {
#if VERSION_MAJOR == 2
std::string s = replaceAll(title, "\n", " ");
std::string s(title);
strReplaceAll(s, "\n", " ");
lv_label_set_text(titleLabel, s.c_str());
#else
lv_label_set_text(titleLabel, title);
@@ -452,18 +452,6 @@ int QuickMenu::pageIndex(QMPage page)
return 0;
}
std::string replaceAll(std::string str, const std::string& from, const std::string& to)
{
auto&& pos = str.find(from, size_t{});
while (pos != std::string::npos)
{
str.replace(pos, from.length(), to);
// easy to forget to add to.length()
pos = str.find(from, pos + to.length());
}
return str;
}
std::vector<std::string>& QuickMenu::menuPageNames(bool forFavorites)
{
static std::vector<std::string> qmPages;
@@ -484,7 +472,7 @@ std::vector<std::string>& QuickMenu::menuPageNames(bool forFavorites)
s += STR_CURRENT_SCREEN;
else
s += STR_VAL(sub[j].title);
s = replaceAll(s, "\n", " ");
strReplaceAll(s, "\n", " ");
qmPages.emplace_back(s);
}
}
@@ -61,10 +61,6 @@ extern const QMMainDef qmTopItems[];
//-----------------------------------------------------------------------------
std::string replaceAll(std::string str, const std::string& from, const std::string& to);
//-----------------------------------------------------------------------------
#define GRP_W(n) ((QuickMenu::QM_BUTTON_WIDTH + QuickMenu::QM_HPAD) * n - QuickMenu::QM_HPAD + PAD_OUTLINE * 2)
#define GRP_H(n) ((QuickMenu::QM_BUTTON_HEIGHT + QuickMenu::QM_VPAD) * n - QuickMenu::QM_VPAD + PAD_OUTLINE * 2)