replace all string::find_last_of() with string::rfind()
find_last_of was working properly only because it was searching only for one character, string::rfind() is appropriate function for this job.
This commit is contained in:
@@ -51,7 +51,7 @@ namespace
|
|||||||
|
|
||||||
bool hasSupportedExtension(const string &file)
|
bool hasSupportedExtension(const string &file)
|
||||||
{
|
{
|
||||||
unsigned int last_dot = file.find_last_of(".");
|
size_t last_dot = file.rfind(".");
|
||||||
if (last_dot > file.length())
|
if (last_dot > file.length())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ void DisplayItem(const Item &item, void *, Menu<Item> *menu)
|
|||||||
*menu << "[..]";
|
*menu << "[..]";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
size_t slash = item.name.find_last_of("/");
|
size_t slash = item.name.rfind("/");
|
||||||
*menu << "[" << (slash != string::npos ? item.name.substr(slash+1) : item.name) << "]";
|
*menu << "[" << (slash != string::npos ? item.name.substr(slash+1) : item.name) << "]";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -180,7 +180,7 @@ void GetDirectory(string dir, string subdir)
|
|||||||
if (dir != "/")
|
if (dir != "/")
|
||||||
{
|
{
|
||||||
Item parent;
|
Item parent;
|
||||||
size_t slash = dir.find_last_of("/");
|
size_t slash = dir.rfind("/");
|
||||||
parent.song = (Song *) 1; // in that way we assume that's really parent dir
|
parent.song = (Song *) 1; // in that way we assume that's really parent dir
|
||||||
parent.name = slash != string::npos ? dir.substr(0, slash) : "/";
|
parent.name = slash != string::npos ? dir.substr(0, slash) : "/";
|
||||||
parent.type = itDirectory;
|
parent.type = itDirectory;
|
||||||
|
|||||||
@@ -364,7 +364,7 @@ string FindSharedDir(const string &one, const string &two)
|
|||||||
while (one.substr(0, i) == two.substr(0, i))
|
while (one.substr(0, i) == two.substr(0, i))
|
||||||
i++;
|
i++;
|
||||||
result = one.substr(0, i);
|
result = one.substr(0, i);
|
||||||
i = result.find_last_of("/");
|
i = result.rfind("/");
|
||||||
return i != string::npos ? result.substr(0, i) : "/";
|
return i != string::npos ? result.substr(0, i) : "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -716,7 +716,7 @@ int main(int argc, char *argv[])
|
|||||||
sort(list.begin(), list.end(), CaseInsensitiveSorting());
|
sort(list.begin(), list.end(), CaseInsensitiveSorting());
|
||||||
if (editor_browsed_dir != "/")
|
if (editor_browsed_dir != "/")
|
||||||
{
|
{
|
||||||
size_t slash = editor_browsed_dir.find_last_of("/");
|
size_t slash = editor_browsed_dir.rfind("/");
|
||||||
string parent = slash != string::npos ? editor_browsed_dir.substr(0, slash) : "/";
|
string parent = slash != string::npos ? editor_browsed_dir.substr(0, slash) : "/";
|
||||||
mEditorDirs->AddOption(make_pair("[..]", parent));
|
mEditorDirs->AddOption(make_pair("[..]", parent));
|
||||||
}
|
}
|
||||||
@@ -726,7 +726,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
for (TagList::const_iterator it = list.begin(); it != list.end(); it++)
|
for (TagList::const_iterator it = list.begin(); it != list.end(); it++)
|
||||||
{
|
{
|
||||||
size_t slash = it->find_last_of("/");
|
size_t slash = it->rfind("/");
|
||||||
string to_display = slash != string::npos ? it->substr(slash+1) : *it;
|
string to_display = slash != string::npos ? it->substr(slash+1) : *it;
|
||||||
utf_to_locale(to_display);
|
utf_to_locale(to_display);
|
||||||
mEditorDirs->AddOption(make_pair(to_display, *it));
|
mEditorDirs->AddOption(make_pair(to_display, *it));
|
||||||
@@ -1203,7 +1203,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
Statusbar() << fmtBold << "Filename: " << fmtBoldEnd;
|
Statusbar() << fmtBold << "Filename: " << fmtBoldEnd;
|
||||||
string filename = s.GetNewName().empty() ? s.GetName() : s.GetNewName();
|
string filename = s.GetNewName().empty() ? s.GetName() : s.GetNewName();
|
||||||
int dot = filename.find_last_of(".");
|
size_t dot = filename.rfind(".");
|
||||||
string extension = filename.substr(dot);
|
string extension = filename.substr(dot);
|
||||||
filename = filename.substr(0, dot);
|
filename = filename.substr(0, dot);
|
||||||
string new_name = wFooter->GetString(filename);
|
string new_name = wFooter->GetString(filename);
|
||||||
@@ -1732,7 +1732,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
Song &s = mEditorTags->Current();
|
Song &s = mEditorTags->Current();
|
||||||
string old_name = s.GetNewName().empty() ? s.GetName() : s.GetNewName();
|
string old_name = s.GetNewName().empty() ? s.GetName() : s.GetNewName();
|
||||||
int last_dot = old_name.find_last_of(".");
|
size_t last_dot = old_name.rfind(".");
|
||||||
string extension = old_name.substr(last_dot);
|
string extension = old_name.substr(last_dot);
|
||||||
old_name = old_name.substr(0, last_dot);
|
old_name = old_name.substr(0, last_dot);
|
||||||
LockStatusbar();
|
LockStatusbar();
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ namespace
|
|||||||
std::stringstream result;
|
std::stringstream result;
|
||||||
vector<string> separators;
|
vector<string> separators;
|
||||||
vector< std::pair<char, string> > tags;
|
vector< std::pair<char, string> > tags;
|
||||||
string file = s.GetName().substr(0, s.GetName().find_last_of("."));
|
string file = s.GetName().substr(0, s.GetName().rfind("."));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -231,7 +231,7 @@ string FindSharedDir(const SongList &v)
|
|||||||
i++;
|
i++;
|
||||||
result = result.substr(0, i);
|
result = result.substr(0, i);
|
||||||
}
|
}
|
||||||
size_t slash = result.find_last_of("/");
|
size_t slash = result.rfind("/");
|
||||||
result = slash != string::npos ? result.substr(0, slash) : "/";
|
result = slash != string::npos ? result.substr(0, slash) : "/";
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -332,7 +332,7 @@ bool GetSongTags(Song &s)
|
|||||||
s.SetComment(f.tag()->comment().to8Bit(1));
|
s.SetComment(f.tag()->comment().to8Bit(1));
|
||||||
|
|
||||||
string ext = s.GetFile();
|
string ext = s.GetFile();
|
||||||
ext = ext.substr(ext.find_last_of(".")+1);
|
ext = ext.substr(ext.rfind(".")+1);
|
||||||
ToLower(ext);
|
ToLower(ext);
|
||||||
|
|
||||||
mTagEditor->Clear();
|
mTagEditor->Clear();
|
||||||
@@ -401,7 +401,7 @@ bool WriteTags(Song &s)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
string ext = s.GetFile();
|
string ext = s.GetFile();
|
||||||
ext = ext.substr(ext.find_last_of(".")+1);
|
ext = ext.substr(ext.rfind(".")+1);
|
||||||
ToLower(ext);
|
ToLower(ext);
|
||||||
if (ext == "mp3")
|
if (ext == "mp3")
|
||||||
{
|
{
|
||||||
@@ -613,7 +613,7 @@ void __deal_with_filenames(SongList &v)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const string &file = s.GetName();
|
const string &file = s.GetName();
|
||||||
int last_dot = file.find_last_of(".");
|
size_t last_dot = file.rfind(".");
|
||||||
string extension = file.substr(last_dot);
|
string extension = file.substr(last_dot);
|
||||||
basic_buffer<my_char_t> new_file;
|
basic_buffer<my_char_t> new_file;
|
||||||
new_file << TO_WSTRING(GenerateFilename(s, Config.pattern));
|
new_file << TO_WSTRING(GenerateFilename(s, Config.pattern));
|
||||||
|
|||||||
Reference in New Issue
Block a user