1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-17 23:10:17 +02:00

Simplify iteration over tokens using std::array

This commit is contained in:
Maarten ter Huurne 2014-07-17 01:19:18 +02:00
parent 4474a42767
commit bb7a30d697

View File

@ -37,6 +37,7 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <array>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
@ -54,9 +55,7 @@
using namespace std; using namespace std;
static const char *tokens[] = { "%f", "%F", "%u", "%U", }; static array<const char *, 4> tokens = { "%f", "%F", "%u", "%U", };
#define ARRAY_SIZE(x) (!sizeof(x) ?: sizeof(x) / sizeof((x)[0]))
#ifdef HAVE_LIBOPK #ifdef HAVE_LIBOPK
LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile, LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile,
@ -145,10 +144,9 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, const char* linkfile)
} else if (!strncmp(key, "Exec", lkey)) { } else if (!strncmp(key, "Exec", lkey)) {
string tmp = buf; string tmp = buf;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(tokens); i++) { for (auto token : tokens) {
if (tmp.find(tokens[i]) != tmp.npos) { if (tmp.find(token) != tmp.npos) {
selectordir = CARD_ROOT; selectordir = CARD_ROOT;
break; break;
} }
@ -565,12 +563,13 @@ void LinkApp::launch(const string &selectedFile) {
if (params.empty()) { if (params.empty()) {
params = path; params = path;
} else { } else {
unsigned int i;
string::size_type pos; string::size_type pos;
for (i = 0; i < sizeof(tokens) / sizeof(tokens[0]); i++) for (auto token : tokens) {
while((pos = params.find(tokens[i])) != params.npos) while ((pos = params.find(token)) != params.npos) {
params.replace(pos, 2, path); params.replace(pos, 2, path);
}
}
} }
} }