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

Moved code to remove a file name extension into utilities module

This commit is contained in:
Maarten ter Huurne 2014-08-12 09:07:37 +02:00
parent aa5d8faeb6
commit 1e50dff746
2 changed files with 6 additions and 8 deletions

View File

@ -217,7 +217,6 @@ int Selector::exec(int startSelection) {
void Selector::prepare(FileLister *fl, vector<string> *titles) { void Selector::prepare(FileLister *fl, vector<string> *titles) {
fl->setPath(dir); fl->setPath(dir);
titles->resize(fl->getFiles().size());
screendir = dir; screendir = dir;
if (!screendir.empty() && screendir[screendir.length() - 1] != '/') { if (!screendir.empty() && screendir[screendir.length() - 1] != '/') {
@ -225,13 +224,8 @@ void Selector::prepare(FileLister *fl, vector<string> *titles) {
} }
screendir += "previews/"; screendir += "previews/";
string noext; titles->resize(fl->getFiles().size());
string::size_type pos;
for (uint i=0; i<fl->getFiles().size(); i++) { for (uint i=0; i<fl->getFiles().size(); i++) {
noext = fl->getFiles()[i]; titles->at(i) = trimExtension(fl->getFiles()[i]);
pos = noext.rfind(".");
if (pos!=string::npos && pos>0)
noext = noext.substr(0, pos);
titles->at(i) = noext;
} }
} }

View File

@ -52,6 +52,10 @@ std::string readFileAsString(const char *filename);
std::string strreplace(std::string orig, const std::string &search, const std::string &replace); std::string strreplace(std::string orig, const std::string &search, const std::string &replace);
std::string cmdclean(std::string cmdline); std::string cmdclean(std::string cmdline);
inline std::string trimExtension(std::string const& filename) {
return filename.substr(0, filename.rfind('.'));
}
bool fileExists(const std::string &file); bool fileExists(const std::string &file);
bool rmtree(std::string path); bool rmtree(std::string path);