commit e4564ce976e4e06adcd24bf80885e13cbb45aa34
parent f583fe2e40bbb9a68b8d6bb2b06a76a9aba46eb7
Author: cfillion <cfillion@users.noreply.github.com>
Date: Thu, 14 Sep 2017 00:59:08 -0400
use String::format more for dynamically allocated strings
Diffstat:
4 files changed, 13 insertions(+), 27 deletions(-)
diff --git a/src/about.cpp b/src/about.cpp
@@ -170,9 +170,7 @@ void About::setDelegate(const DelegatePtr &delegate, const bool focus)
void About::setTitle(const string &what)
{
- char title[255];
- snprintf(title, sizeof(title), "About %s", what.c_str());
- Win32::setWindowText(handle(), title);
+ Win32::setWindowText(handle(), String::format("About %s", what.c_str()).c_str());
}
void About::setMetadata(const Metadata *metadata, const bool substitution)
diff --git a/src/browser_entry.cpp b/src/browser_entry.cpp
@@ -21,6 +21,7 @@
#include "index.hpp"
#include "menu.hpp"
#include "reapack.hpp"
+#include "string.hpp"
#include <boost/range/adaptor/reversed.hpp>
@@ -170,31 +171,24 @@ void Browser::Entry::fillMenu(Menu &menu) const
{
if(test(InstalledFlag)) {
if(test(OutOfDateFlag)) {
- char installLabel[32];
- snprintf(installLabel, sizeof(installLabel),
- "U&pdate to v%s", latest->name().toString().c_str());
+ const UINT actionIndex = menu.addAction(String::format("U&pdate to v%s",
+ latest->name().toString().c_str()), ACTION_LATEST);
- const UINT actionIndex = menu.addAction(installLabel, ACTION_LATEST);
if(target && *target == latest)
menu.check(actionIndex);
}
- char reinstallLabel[32];
- snprintf(reinstallLabel, sizeof(reinstallLabel),
- "&Reinstall v%s", regEntry.version.toString().c_str());
+ const UINT actionIndex = menu.addAction(String::format("&Reinstall v%s",
+ regEntry.version.toString().c_str()), ACTION_REINSTALL);
- const UINT actionIndex = menu.addAction(reinstallLabel, ACTION_REINSTALL);
if(!current || test(ObsoleteFlag))
menu.disable(actionIndex);
else if(target && *target == current)
menu.check(actionIndex);
}
else {
- char installLabel[32];
- snprintf(installLabel, sizeof(installLabel),
- "&Install v%s", latest->name().toString().c_str());
-
- const UINT actionIndex = menu.addAction(installLabel, ACTION_LATEST);
+ const UINT actionIndex = menu.addAction(String::format("&Install v%s",
+ latest->name().toString().c_str()), ACTION_LATEST);
if(target && *target == latest)
menu.check(actionIndex);
}
@@ -236,9 +230,7 @@ void Browser::Entry::fillMenu(Menu &menu) const
menu.setEnabled(!test(ObsoleteFlag),
menu.addAction("About this &package", ACTION_ABOUT_PKG));
- char aboutLabel[64];
- snprintf(aboutLabel, sizeof(aboutLabel), "&About %s", indexName().c_str());
- menu.addAction(aboutLabel, ACTION_ABOUT_REMOTE);
+ menu.addAction(String::format("&About %s", indexName().c_str()), ACTION_ABOUT_REMOTE);
}
bool Browser::Entry::operator==(const Entry &o) const
diff --git a/src/main.cpp b/src/main.cpp
@@ -93,10 +93,8 @@ static void menuHook(const char *name, HMENU handle, int f)
menu.addSeparator();
- char aboutLabel[32];
- snprintf(aboutLabel, sizeof(aboutLabel),
- "&About ReaPack v%s", ReaPack::VERSION);
- menu.addAction(aboutLabel, NamedCommandLookup("_REAPACK_ABOUT"));
+ menu.addAction(String::format("&About ReaPack v%s", ReaPack::VERSION),
+ NamedCommandLookup("_REAPACK_ABOUT"));
}
static bool checkLocation(REAPER_PLUGIN_HINSTANCE module)
diff --git a/src/manager.cpp b/src/manager.cpp
@@ -239,10 +239,8 @@ bool Manager::fillContextMenu(Menu &menu, const int index) const
menu.addSeparator();
- char aboutLabel[64];
- snprintf(aboutLabel, sizeof(aboutLabel),
- "&About %s", remote.name().c_str());
- menu.addAction(aboutLabel, index | (ACTION_ABOUT << 8));
+ menu.addAction(String::format("&About %s", remote.name().c_str()),
+ index | (ACTION_ABOUT << 8));
bool allEnabled = true;
bool allDisabled = true;