From 61a9d6a7858f326ae97c1444021f9b14c2aa8631 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 15 Sep 2009 23:12:45 +0000 Subject: [PATCH] get rid of all mysterious numbers that meant length of string literals --- src/conv.cpp | 6 +++--- src/conv.h | 5 +++++ src/info.cpp | 12 ++++++------ src/lyrics.cpp | 8 ++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/conv.cpp b/src/conv.cpp index 3a406c11..a5996386 100644 --- a/src/conv.cpp +++ b/src/conv.cpp @@ -204,11 +204,11 @@ void EscapeHtml(std::string &s) s.replace(i, j-i, ""); } for (size_t i = s.find("'"); i != std::string::npos; i = s.find("'")) - s.replace(i, 6, "'"); + s.replace(i, static_strlen("'"), "'"); for (size_t i = s.find("""); i != std::string::npos; i = s.find(""")) - s.replace(i, 6, "\""); + s.replace(i, static_strlen("""), "\""); for (size_t i = s.find("&"); i != std::string::npos; i = s.find("&")) - s.replace(i, 5, "&"); + s.replace(i, static_strlen("&"), "&"); for (size_t i = 0; i < s.length(); ++i) { if (erase) diff --git a/src/conv.h b/src/conv.h index b2fdfec8..1c1af989 100644 --- a/src/conv.h +++ b/src/conv.h @@ -26,6 +26,11 @@ #include "window.h" #include "song.h" +template inline size_t static_strlen(const char (&)[N]) +{ + return N-1; +} + void ToLower(std::string &); int StrToInt(const std::string &); diff --git a/src/info.cpp b/src/info.cpp index 6f984c1e..6f355cc2 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -134,7 +134,7 @@ void Info::GetArtist() # ifdef HAVE_PTHREAD_H if (Downloader && !ArtistReady) { - ShowMessage("Artist's info is being downloaded..."); + ShowMessage("Artist info is being downloaded..."); return; } else if (ArtistReady) @@ -263,7 +263,7 @@ void *Info::PrepareArtist(void *screen_void_ptr) result[i] = '.'; size_t j = result.find(""); result[j] = '.'; - i += 6; + i += static_strlen(""); similar.push_back(result.substr(i, j-i)); EscapeHtml(similar.back()); } @@ -273,11 +273,11 @@ void *Info::PrepareArtist(void *screen_void_ptr) result[i] = '.'; size_t j = result.find(""); result[j] = '.'; - i += 5; + i += static_strlen(""); urls.push_back(result.substr(i, j-i)); } - a = result.find("")+9; + a = result.find("")+static_strlen(""); b = result.find(""); if (a == b) @@ -287,8 +287,8 @@ void *Info::PrepareArtist(void *screen_void_ptr) } else { - a += 9; // for + a += static_strlen(""); result = result.substr(a, b-a); } diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 30982cd8..67974314 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -209,8 +209,8 @@ void *Lyrics::Get(void *screen_void_ptr) char *c_title = curl_easy_escape(0, title.c_str(), title.length()); std::string url = my_lyrics->url; - url.replace(url.find("%artist%"), 8, c_artist); - url.replace(url.find("%title%"), 7, c_title); + url.replace(url.find("%artist%"), static_strlen("%artist%"), c_artist); + url.replace(url.find("%title%"), static_strlen("%title%"), c_title); CURLcode code; pthread_mutex_lock(&CurlLock); @@ -247,9 +247,9 @@ void *Lyrics::Get(void *screen_void_ptr) } for (size_t i = result.find("<"); i != std::string::npos; i = result.find("<")) - result.replace(i, 4, "<"); + result.replace(i, static_strlen("<"), "<"); for (size_t i = result.find(">"); i != std::string::npos; i = result.find(">")) - result.replace(i, 4, ">"); + result.replace(i, static_strlen(">"), ">"); EscapeHtml(result); Trim(result);