summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Rybczak <electricityispower@gmail.com>2009-02-05 21:52:31 +0100
committerAndrzej Rybczak <electricityispower@gmail.com>2009-02-05 21:52:31 +0100
commitd68824f0f2064c2b33e8cd287ccf538cb3cfd1b0 (patch)
tree2686b6b611709ca0811372a74e6c7babdfd35a56
parente637d8f627bb50867e812a53f91c22dd36c47542 (diff)
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.
-rw-r--r--src/browser.cpp6
-rw-r--r--src/helpers.cpp2
-rw-r--r--src/ncmpcpp.cpp8
-rw-r--r--src/tag_editor.cpp10
4 files changed, 13 insertions, 13 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 73f8406c..6bf13f9d 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -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;
diff --git a/src/helpers.cpp b/src/helpers.cpp
index 37bdfc7d..830c3d38 100644
--- a/src/helpers.cpp
+++ b/src/helpers.cpp
@@ -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) : "/";
}
diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp
index 4d31f92e..8c292227 100644
--- a/src/ncmpcpp.cpp
+++ b/src/ncmpcpp.cpp
@@ -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();
diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp
index b36fae92..5b5d39ff 100644
--- a/src/tag_editor.cpp
+++ b/src/tag_editor.cpp
@@ -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));