1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-29 16:54:04 +02:00

Check for empty strings using empty() instead of comparing to ""

This commit is contained in:
Maarten ter Huurne 2013-08-16 09:16:04 +02:00
parent 8472acc26c
commit 6c80a663e1
9 changed files with 44 additions and 39 deletions

View File

@ -578,7 +578,7 @@ void GMenu2X::writeTmp(int selelem, const string &selectordir) {
inf << "link=" << menu->selLinkIndex() << endl; inf << "link=" << menu->selLinkIndex() << endl;
if (selelem>-1) if (selelem>-1)
inf << "selectorelem=" << selelem << endl; inf << "selectorelem=" << selelem << endl;
if (selectordir!="") if (!selectordir.empty())
inf << "selectordir=" << selectordir << endl; inf << "selectordir=" << selectordir << endl;
inf.close(); inf.close();
sync(); sync();

View File

@ -47,7 +47,7 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
, inputMgr(inputMgr_) , inputMgr(inputMgr_)
, ts(ts_) , ts(ts_)
{ {
if (title == "") { if (title.empty()) {
this->title = text; this->title = text;
this->text = ""; this->text = "";
} else { } else {
@ -55,7 +55,7 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
this->text = text; this->text = text;
} }
this->icon = ""; this->icon = "";
if (icon != "" && gmenu2x->sc[icon] != NULL) { if (!icon.empty() && gmenu2x->sc[icon] != NULL) {
this->icon = icon; this->icon = icon;
} }

View File

@ -202,7 +202,7 @@ LinkApp::LinkApp(GMenu2X *gmenu2x_, Touchscreen &ts, InputManager &inputMgr_,
ifstream infile (file.c_str(), ios_base::in); ifstream infile (file.c_str(), ios_base::in);
while (getline(infile, line, '\n')) { while (getline(infile, line, '\n')) {
line = trim(line); line = trim(line);
if (line=="") continue; if (line.empty()) continue;
if (line[0]=='#') continue; if (line[0]=='#') continue;
string::size_type position = line.find("="); string::size_type position = line.find("=");
@ -320,22 +320,22 @@ bool LinkApp::save() {
ofstream f(file.c_str()); ofstream f(file.c_str());
if (f.is_open()) { if (f.is_open()) {
if (!isOpk()) { if (!isOpk()) {
if (title!="" ) f << "title=" << title << endl; if (!title.empty() ) f << "title=" << title << endl;
if (description!="" ) f << "description=" << description << endl; if (!description.empty() ) f << "description=" << description << endl;
if (icon!="" ) f << "icon=" << icon << endl; if (!icon.empty() ) f << "icon=" << icon << endl;
if (exec!="" ) f << "exec=" << exec << endl; if (!exec.empty() ) f << "exec=" << exec << endl;
if (params!="" ) f << "params=" << params << endl; if (!params.empty() ) f << "params=" << params << endl;
if (manual!="" ) f << "manual=" << manual << endl; if (!manual.empty() ) f << "manual=" << manual << endl;
#if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
if (consoleApp ) f << "consoleapp=true" << endl; if (consoleApp ) f << "consoleapp=true" << endl;
#endif #endif
if (selectorfilter!="*" ) f << "selectorfilter=" << selectorfilter << endl; if (selectorfilter != "*") f << "selectorfilter=" << selectorfilter << endl;
} }
if (iclock!=0 ) f << "clock=" << iclock << endl; if (iclock != 0 ) f << "clock=" << iclock << endl;
if (selectordir!="" ) f << "selectordir=" << selectordir << endl; if (!selectordir.empty() ) f << "selectordir=" << selectordir << endl;
if (!selectorbrowser ) f << "selectorbrowser=false" << endl; if (!selectorbrowser ) f << "selectorbrowser=false" << endl;
if (selectorscreens!="") f << "selectorscreens=" << selectorscreens << endl; if (!selectorscreens.empty() ) f << "selectorscreens=" << selectorscreens << endl;
if (aliasfile!="" ) f << "selectoraliases=" << aliasfile << endl; if (!aliasfile.empty() ) f << "selectoraliases=" << aliasfile << endl;
f.close(); f.close();
sync(); sync();
return true; return true;
@ -359,7 +359,7 @@ void LinkApp::drawRun() {
gmenu2x->s->rectangle(gmenu2x->halfX-halfBoxW, gmenu2x->halfY-21, boxW, 42, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BORDER]); gmenu2x->s->rectangle(gmenu2x->halfX-halfBoxW, gmenu2x->halfY-21, boxW, 42, gmenu2x->skinConfColors[COLOR_MESSAGE_BOX_BORDER]);
int x = gmenu2x->halfX+10-halfBoxW; int x = gmenu2x->halfX+10-halfBoxW;
/*if (getIcon()!="") /*if (!getIcon().empty())
gmenu2x->sc[getIcon()]->blit(gmenu2x->s,x,104); gmenu2x->sc[getIcon()]->blit(gmenu2x->s,x,104);
else else
gmenu2x->sc["icons/generic.png"]->blit(gmenu2x->s,x,104);*/ gmenu2x->sc["icons/generic.png"]->blit(gmenu2x->s,x,104);*/
@ -369,7 +369,7 @@ void LinkApp::drawRun() {
} }
void LinkApp::start() { void LinkApp::start() {
if (selectordir!="") if (!selectordir.empty())
selector(); selector();
else else
launch(); launch();
@ -550,7 +550,7 @@ void LinkApp::selector(int startSelection, const string &selectorDir) {
void LinkApp::launch(const string &selectedFile, const string &selectedDir) { void LinkApp::launch(const string &selectedFile, const string &selectedDir) {
drawRun(); drawRun();
if (selectedDir == "") if (selectedDir.empty())
selectordir = getSelectorDir(); selectordir = getSelectorDir();
else else
selectordir = selectedDir; selectordir = selectedDir;
@ -591,10 +591,10 @@ void LinkApp::launch(const string &selectedFile, const string &selectedDir) {
} }
} }
if (selectedFile != "") { if (!selectedFile.empty()) {
string path = cmdclean(selectordir + selectedFile); string path = cmdclean(selectordir + selectedFile);
if (params == "") { if (params.empty()) {
params = path; params = path;
} else { } else {
unsigned int i; unsigned int i;
@ -623,7 +623,7 @@ void LinkApp::launch(const string &selectedFile, const string &selectedDir) {
chmod( command.c_str(), newstat.st_mode ); chmod( command.c_str(), newstat.st_mode );
} // else, well.. we are no worse off :) } // else, well.. we are no worse off :)
if (params!="") command += " " + params; if (!params.empty()) command += " " + params;
#if defined(PLATFORM_A320) || defined(PLATFORM_GCW0) #if defined(PLATFORM_A320) || defined(PLATFORM_GCW0)
if (gmenu2x->confInt["outputLogs"] && !consoleApp) if (gmenu2x->confInt["outputLogs"] && !consoleApp)
command += " &> " + cmdclean(gmenu2x->getHome()) + "/log.txt"; command += " &> " + cmdclean(gmenu2x->getHome()) + "/log.txt";
@ -638,7 +638,7 @@ void LinkApp::launch(const string &selectedFile, const string &selectedDir) {
gmenu2x->saveSelection(); gmenu2x->saveSelection();
if (selectedFile == "") { if (selectedFile.empty()) {
gmenu2x->writeTmp(); gmenu2x->writeTmp();
} }
#ifdef ENABLE_CPUFREQ #ifdef ENABLE_CPUFREQ
@ -729,7 +729,9 @@ const string &LinkApp::getSelectorDir() {
void LinkApp::setSelectorDir(const string &selectordir) { void LinkApp::setSelectorDir(const string &selectordir) {
this->selectordir = selectordir; this->selectordir = selectordir;
if (this->selectordir!="" && this->selectordir[this->selectordir.length()-1]!='/') this->selectordir += "/"; if (!selectordir.empty() && selectordir[selectordir.length() - 1] != '/') {
this->selectordir += "/";
}
edited = true; edited = true;
} }

View File

@ -411,9 +411,9 @@ bool Menu::addActionLink(uint section, const string &title, function_t action, c
} }
bool Menu::addLink(string path, string file, string section) { bool Menu::addLink(string path, string file, string section) {
if (section=="") if (section.empty()) {
section = selSection(); section = selSection();
else if (find(sections.begin(),sections.end(),section)==sections.end()) { } else if (find(sections.begin(),sections.end(),section)==sections.end()) {
//section directory doesn't exists //section directory doesn't exists
if (!addSection(section)) if (!addSection(section))
return false; return false;

View File

@ -82,7 +82,7 @@ int MessageBox::exec() {
int btnX = gmenu2x->halfX+box.w/2-6; int btnX = gmenu2x->halfX+box.w/2-6;
for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) { for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) {
if (buttons[i] != "") { if (!buttons[i].empty()) {
buttonPositions[i].y = box.y+box.h-4; buttonPositions[i].y = box.y+box.h-4;
buttonPositions[i].w = btnX; buttonPositions[i].w = btnX;
@ -101,8 +101,8 @@ int MessageBox::exec() {
while (result < 0) { while (result < 0) {
InputManager::ButtonEvent event; InputManager::ButtonEvent event;
if (gmenu2x->input.pollEvent(&event) if (gmenu2x->input.pollEvent(&event)
&& (event.state == InputManager::PRESSED) && event.state == InputManager::PRESSED
&& (buttons[event.button] != "")) { && !buttons[event.button].empty()) {
result = event.button; result = event.button;
} }

View File

@ -48,7 +48,7 @@ Selector::Selector(GMenu2X *gmenu2x, LinkApp *link, const string &selectorDir) :
this->link = link; this->link = link;
loadAliases(); loadAliases();
selRow = 0; selRow = 0;
if (selectorDir=="") if (selectorDir.empty())
dir = link->getSelectorDir(); dir = link->getSelectorDir();
else else
dir = selectorDir; dir = selectorDir;
@ -103,7 +103,8 @@ int Selector::exec(int startSelection) {
gmenu2x->s->box(1, iY, 309, 14, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); gmenu2x->s->box(1, iY, 309, 14, gmenu2x->skinConfColors[COLOR_SELECTION_BG]);
//Screenshot //Screenshot
if (selected-fl.dirCount()<screens.size() && screens[selected-fl.dirCount()]!="") { if (selected-fl.dirCount()<screens.size()
&& !screens[selected-fl.dirCount()].empty()) {
curTick = SDL_GetTicks(); curTick = SDL_GetTicks();
if (curTick - selTick > 200) { if (curTick - selTick > 200) {
gmenu2x->sc[screens[selected-fl.dirCount()]]->blitRight( gmenu2x->sc[screens[selected-fl.dirCount()]]->blitRight(
@ -262,7 +263,9 @@ void Selector::prepare(FileLister *fl, vector<string> *screens, vector<string> *
titles->resize(fl->getFiles().size()); titles->resize(fl->getFiles().size());
string screendir = link->getSelectorScreens(); string screendir = link->getSelectorScreens();
if (screendir != "" && screendir[screendir.length()-1]!='/') screendir += "/"; if (!screendir.empty() && screendir[screendir.length() - 1] != '/') {
screendir += "/";
}
string noext; string noext;
string::size_type pos; string::size_type pos;
@ -272,7 +275,7 @@ void Selector::prepare(FileLister *fl, vector<string> *screens, vector<string> *
if (pos!=string::npos && pos>0) if (pos!=string::npos && pos>0)
noext = noext.substr(0, pos); noext = noext.substr(0, pos);
titles->at(i) = getAlias(noext); titles->at(i) = getAlias(noext);
if (titles->at(i)=="") if (titles->at(i).empty())
titles->at(i) = noext; titles->at(i) = noext;
DEBUG("Searching for screen '%s%s.png'\n", screendir.c_str(), noext.c_str()); DEBUG("Searching for screen '%s%s.png'\n", screendir.c_str(), noext.c_str());
@ -286,7 +289,7 @@ void Selector::prepare(FileLister *fl, vector<string> *screens, vector<string> *
void Selector::freeScreenshots(vector<string> *screens) { void Selector::freeScreenshots(vector<string> *screens) {
for (uint i=0; i<screens->size(); i++) { for (uint i=0; i<screens->size(); i++) {
if (screens->at(i) != "") if (!screens->at(i).empty())
gmenu2x->sc.del(screens->at(i)); gmenu2x->sc.del(screens->at(i));
} }
} }

View File

@ -36,7 +36,7 @@ SettingsDialog::SettingsDialog(
, ts(ts_) , ts(ts_)
, text(text_) , text(text_)
{ {
if (icon != "" && gmenu2x->sc[icon] != NULL) { if (!icon.empty() && gmenu2x->sc[icon] != NULL) {
this->icon = icon; this->icon = icon;
} else { } else {
this->icon = "icons/generic.png"; this->icon = "icons/generic.png";

View File

@ -58,10 +58,10 @@ TextManualDialog::TextManualDialog(GMenu2X *gmenu2x, const string &title, const
for (uint page=0; page<pages.size(); page++) { for (uint page=0; page<pages.size(); page++) {
if (pages[page].text.size() > 0) { if (pages[page].text.size() > 0) {
//first lines //first lines
while (trim(pages[page].text[0])=="") while (trim(pages[page].text[0]).empty())
pages[page].text.erase(pages[page].text.begin()); pages[page].text.erase(pages[page].text.begin());
//last lines //last lines
while (trim(pages[page].text[pages[page].text.size()-1])=="") while (trim(pages[page].text[pages[page].text.size()-1]).empty())
pages[page].text.erase(pages[page].text.end()); pages[page].text.erase(pages[page].text.end());
} }
} }

View File

@ -54,7 +54,7 @@ void Translator::setLang(const string &lang) {
if (infile.is_open()) { if (infile.is_open()) {
while (getline(infile, line, '\n')) { while (getline(infile, line, '\n')) {
line = trim(line); line = trim(line);
if (line=="") continue; if (line.empty()) continue;
if (line[0]=='#') continue; if (line[0]=='#') continue;
string::size_type position = line.find("="); string::size_type position = line.find("=");