use size_t instead of int where it's appropriate

This commit is contained in:
Andrzej Rybczak
2008-11-06 20:07:42 +01:00
parent 2fcd43dd3b
commit c64e3a9b3b
9 changed files with 38 additions and 37 deletions

View File

@@ -131,7 +131,7 @@ string DisplayItem(const Item &item, void *, const Menu<Item> *menu)
{
if (item.song)
return "[..]";
int slash = item.name.find_last_of("/");
size_t slash = item.name.find_last_of("/");
return "[" + (slash != string::npos ? item.name.substr(slash+1) : item.name) + "]";
}
case itSong:
@@ -159,7 +159,7 @@ void GetDirectory(string dir, string subdir)
if (dir != "/")
{
Item parent;
int slash = dir.find_last_of("/");
size_t slash = dir.find_last_of("/");
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

@@ -265,7 +265,7 @@ void EscapeUnallowedChars(string &s)
const string unallowed_chars = "\"*/:<>?\\|";
for (string::const_iterator it = unallowed_chars.begin(); it != unallowed_chars.end(); it++)
{
for (int i = 0; i < s.length(); i++)
for (size_t i = 0; i < s.length(); i++)
{
if (s[i] == *it)
{
@@ -312,7 +312,7 @@ string FindSharedDir(const string &one, const string &two)
if (one == two)
return one;
string result;
int i = 1;
size_t i = 1;
while (one.substr(0, i) == two.substr(0, i))
i++;
result = one.substr(0, i);
@@ -381,7 +381,7 @@ string DisplayStringPair(const StringPair &pair, void *, const Menu<StringPair>
string DisplayColumns(string song_template)
{
vector<string> cols;
for (int i = song_template.find(" "); i != string::npos; i = song_template.find(" "))
for (size_t i = song_template.find(" "); i != string::npos; i = song_template.find(" "))
{
cols.push_back(song_template.substr(0, i));
song_template = song_template.substr(i+1);
@@ -455,7 +455,7 @@ string DisplaySongInColumns(const Song &s, void *s_template, const Menu<Song> *)
string song_template = s_template ? *static_cast<string *>(s_template) : "";
vector<string> cols;
for (int i = song_template.find(" "); i != string::npos; i = song_template.find(" "))
for (size_t i = song_template.find(" "); i != string::npos; i = song_template.find(" "))
{
cols.push_back(song_template.substr(0, i));
song_template = song_template.substr(i+1);

View File

@@ -48,16 +48,16 @@ namespace
void EscapeHtml(string &str)
{
for (int i = str.find("<"); i != string::npos; i = str.find("<"))
for (size_t i = str.find("<"); i != string::npos; i = str.find("<"))
{
int j = str.find(">")+1;
str.replace(i, j-i, "");
}
for (int i = str.find("&#039;"); i != string::npos; i = str.find("&#039;"))
for (size_t i = str.find("&#039;"); i != string::npos; i = str.find("&#039;"))
str.replace(i, 6, "'");
for (int i = str.find("&quot;"); i != string::npos; i = str.find("&quot;"))
for (size_t i = str.find("&quot;"); i != string::npos; i = str.find("&quot;"))
str.replace(i, 6, "\"");
for (int i = str.find("&amp;"); i != string::npos; i = str.find("&amp;"))
for (size_t i = str.find("&amp;"); i != string::npos; i = str.find("&amp;"))
str.replace(i, 5, "&");
}
}
@@ -115,7 +115,7 @@ void * GetArtistInfo(void *ptr)
pthread_exit(result);
}
int a, b;
size_t a, b;
bool erase = 0;
bool save = 1;
@@ -130,20 +130,20 @@ void * GetArtistInfo(void *ptr)
}
vector<string> similar;
for (int i = result->find("<name>"); i != string::npos; i = result->find("<name>"))
for (size_t i = result->find("<name>"); i != string::npos; i = result->find("<name>"))
{
(*result)[i] = '.';
int j = result->find("</name>");
size_t j = result->find("</name>");
(*result)[j] = '.';
i += 6;
similar.push_back(result->substr(i, j-i));
EscapeHtml(similar.back());
}
vector<string> urls;
for (int i = result->find("<url>"); i != string::npos; i = result->find("<url>"))
for (size_t i = result->find("<url>"); i != string::npos; i = result->find("<url>"))
{
(*result)[i] = '.';
int j = result->find("</url>");
size_t j = result->find("</url>");
(*result)[j] = '.';
i += 5;
urls.push_back(result->substr(i, j-i));
@@ -165,7 +165,7 @@ void * GetArtistInfo(void *ptr)
}
EscapeHtml(*result);
for (int i = 0; i < result->length(); i++)
for (size_t i = 0; i < result->length(); i++)
{
if (erase)
{
@@ -189,7 +189,7 @@ void * GetArtistInfo(void *ptr)
}
*result += "\n\n[.b]Similar artists:[/b]\n";
for (int i = 1; i < similar.size(); i++)
for (size_t i = 1; i < similar.size(); i++)
*result += "\n [." + Config.color2 + "]*[/" + Config.color2 + "] " + similar[i] + " (" + urls[i] + ")";
*result += "\n\n" + urls.front();
@@ -277,9 +277,9 @@ void * GetLyrics(void *song)
pthread_exit(result);
}
for (int i = result->find("&lt;"); i != string::npos; i = result->find("&lt;"))
for (size_t i = result->find("&lt;"); i != string::npos; i = result->find("&lt;"))
result->replace(i, 4, "<");
for (int i = result->find("&gt;"); i != string::npos; i = result->find("&gt;"))
for (size_t i = result->find("&gt;"); i != string::npos; i = result->find("&gt;"))
result->replace(i, 4, ">");
EscapeHtml(*result);

View File

@@ -98,7 +98,7 @@ void MPDConnection::Disconnect()
void MPDConnection::SetHostname(const string &host)
{
int at = host.find("@");
size_t at = host.find("@");
if (at != string::npos)
{
MPD_PASSWORD = host.substr(0, at);

View File

@@ -182,7 +182,7 @@ class MPDConnection
string itsErrorMessage;
int itsErrorCode;
unsigned int itsMaxPlaylistLength;
int itsMaxPlaylistLength;
string MPD_HOST;
int MPD_PORT;

View File

@@ -112,13 +112,13 @@ Window *wFooter;
MPDConnection *Mpd;
time_t timer;
int now_playing = -1;
int browsed_dir_scroll_begin = 0;
int lock_statusbar_delay = -1;
size_t browsed_dir_scroll_begin = 0;
time_t timer;
string browsed_dir = "/";
string editor_browsed_dir = "/";
string editor_highlighted_dir;
@@ -370,7 +370,7 @@ int main(int argc, char *argv[])
messages_allowed = 1;
// header stuff
const int max_allowed_title_length = wHeader ? wHeader->GetWidth()-volume_state.length() : 0;
const size_t max_allowed_title_length = wHeader ? wHeader->GetWidth()-volume_state.length() : 0;
if (current_screen == csBrowser && input == ERR && browsed_dir.length() > max_allowed_title_length)
redraw_header = 1;
if (Config.header_visibility && redraw_header)
@@ -421,7 +421,7 @@ int main(int argc, char *argv[])
wHeader->WriteXY(title.length(), 0, max_allowed_title_length-title.length(), playlist_stats);
else if (current_screen == csBrowser)
{
int max_length_without_scroll = wHeader->GetWidth()-volume_state.length()-title.length();
size_t max_length_without_scroll = wHeader->GetWidth()-volume_state.length()-title.length();
my_string_t wbrowseddir = TO_WSTRING(browsed_dir);
wHeader->Bold(1);
if (browsed_dir.length() > max_length_without_scroll)
@@ -431,7 +431,7 @@ int main(int argc, char *argv[])
# else
wbrowseddir += " ** ";
# endif
const int scrollsize = max_length_without_scroll;
const size_t scrollsize = max_length_without_scroll;
my_string_t part = wbrowseddir.substr(browsed_dir_scroll_begin++, scrollsize);
if (part.length() < scrollsize)
part += wbrowseddir.substr(0, scrollsize-part.length());
@@ -650,13 +650,13 @@ int main(int argc, char *argv[])
sort(list.begin(), list.end(), CaseInsensitiveSorting());
if (editor_browsed_dir != "/")
{
int slash = editor_browsed_dir.find_last_of("/");
size_t slash = editor_browsed_dir.find_last_of("/");
string parent = slash != string::npos ? editor_browsed_dir.substr(0, slash) : "/";
mEditorDirs->AddOption(make_pair("[..]", parent));
}
for (TagList::const_iterator it = list.begin(); it != list.end(); it++)
{
int slash = it->find_last_of("/");
size_t slash = it->find_last_of("/");
string to_display = slash != string::npos ? it->substr(slash+1) : *it;
mEditorDirs->AddOption(make_pair(to_display, *it));
if (*it == editor_highlighted_dir)
@@ -2172,7 +2172,7 @@ int main(int argc, char *argv[])
mPlaylist->Refresh();
mPlaylist->ReadKey(input);
}
for (int i = 0; i < list.size(); i++)
for (size_t i = 0; i < list.size(); i++)
Mpd->QueueMove(origs[i], list[i]);
Mpd->CommitQueue();
}
@@ -2220,7 +2220,7 @@ int main(int argc, char *argv[])
mPlaylistEditor->Refresh();
mPlaylistEditor->ReadKey(input);
}
for (int i = 0; i < list.size(); i++)
for (size_t i = 0; i < list.size(); i++)
if (origs[i] != list[i])
Mpd->QueueMove(mPlaylistList->GetOption(), origs[i], list[i]);
Mpd->CommitQueue();

View File

@@ -32,7 +32,7 @@ namespace
{
void GetKeys(string line, int *key)
{
int i = line.find("=")+1;
size_t i = line.find("=")+1;
line = line.substr(i, line.length()-i);
i = 0;
if (line[i] == ' ')

View File

@@ -61,7 +61,7 @@ Song::Song(mpd_Song *s, bool copy_ptr) : itsSong(s),
isStream = 1;
// generate pseudo-hash
for (int i = 0; i < itsFile.length(); i++)
for (size_t i = 0; i < itsFile.length(); i++)
{
itsHash += itsFile[i];
if (i%3)

View File

@@ -70,7 +70,8 @@ bool repeat_one_allowed = 0;
long long playlist_old_id = -1;
int old_playing;
int playing_song_scroll_begin = 0;
size_t playing_song_scroll_begin = 0;
time_t time_of_statusbar_lock;
time_t now;
@@ -336,7 +337,7 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *)
tracklength = " [" + Song::ShowTime(elapsed) + "]";
my_string_t playing_song = TO_WSTRING(DisplaySong(s, &Config.song_status_format));
int max_length_without_scroll = wFooter->GetWidth()-player_state.length()-tracklength.length();
const size_t max_length_without_scroll = wFooter->GetWidth()-player_state.length()-tracklength.length();
wFooter->WriteXY(0, 1, player_state);
wFooter->Bold(0);
@@ -347,7 +348,7 @@ void NcmpcppStatusChanged(MPDConnection *Mpd, MPDStatusChanges changed, void *)
# else
playing_song += " ** ";
# endif
const int scrollsize = max_length_without_scroll+playing_song.length();
const size_t scrollsize = max_length_without_scroll+playing_song.length();
my_string_t part = playing_song.substr(playing_song_scroll_begin++, scrollsize);
if (part.length() < scrollsize)
part += playing_song.substr(0, scrollsize-part.length());