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:
Andrzej Rybczak
2009-02-05 21:52:31 +01:00
parent e637d8f627
commit d68824f0f2
4 changed files with 13 additions and 13 deletions

View File

@@ -51,7 +51,7 @@ namespace
bool hasSupportedExtension(const string &file)
{
unsigned int last_dot = file.find_last_of(".");
size_t last_dot = file.rfind(".");
if (last_dot > file.length())
return false;
@@ -138,7 +138,7 @@ void DisplayItem(const Item &item, void *, Menu<Item> *menu)
*menu << "[..]";
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) << "]";
return;
}
@@ -180,7 +180,7 @@ void GetDirectory(string dir, string subdir)
if (dir != "/")
{
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.name = slash != string::npos ? dir.substr(0, slash) : "/";
parent.type = itDirectory;

View File

@@ -364,7 +364,7 @@ string FindSharedDir(const string &one, const string &two)
while (one.substr(0, i) == two.substr(0, i))
i++;
result = one.substr(0, i);
i = result.find_last_of("/");
i = result.rfind("/");
return i != string::npos ? result.substr(0, i) : "/";
}

View File

@@ -716,7 +716,7 @@ int main(int argc, char *argv[])
sort(list.begin(), list.end(), CaseInsensitiveSorting());
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) : "/";
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++)
{
size_t slash = it->find_last_of("/");
size_t slash = it->rfind("/");
string to_display = slash != string::npos ? it->substr(slash+1) : *it;
utf_to_locale(to_display);
mEditorDirs->AddOption(make_pair(to_display, *it));
@@ -1203,7 +1203,7 @@ int main(int argc, char *argv[])
{
Statusbar() << fmtBold << "Filename: " << fmtBoldEnd;
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);
filename = filename.substr(0, dot);
string new_name = wFooter->GetString(filename);
@@ -1732,7 +1732,7 @@ int main(int argc, char *argv[])
{
Song &s = mEditorTags->Current();
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);
old_name = old_name.substr(0, last_dot);
LockStatusbar();

View File

@@ -118,7 +118,7 @@ namespace
std::stringstream result;
vector<string> separators;
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
{
@@ -231,7 +231,7 @@ string FindSharedDir(const SongList &v)
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) : "/";
}
return result;
@@ -332,7 +332,7 @@ bool GetSongTags(Song &s)
s.SetComment(f.tag()->comment().to8Bit(1));
string ext = s.GetFile();
ext = ext.substr(ext.find_last_of(".")+1);
ext = ext.substr(ext.rfind(".")+1);
ToLower(ext);
mTagEditor->Clear();
@@ -401,7 +401,7 @@ bool WriteTags(Song &s)
return false;
string ext = s.GetFile();
ext = ext.substr(ext.find_last_of(".")+1);
ext = ext.substr(ext.rfind(".")+1);
ToLower(ext);
if (ext == "mp3")
{
@@ -613,7 +613,7 @@ void __deal_with_filenames(SongList &v)
else
{
const string &file = s.GetName();
int last_dot = file.find_last_of(".");
size_t last_dot = file.rfind(".");
string extension = file.substr(last_dot);
basic_buffer<my_char_t> new_file;
new_file << TO_WSTRING(GenerateFilename(s, Config.pattern));