get rid of all mysterious numbers that meant length of string literals
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -26,6 +26,11 @@
|
||||
#include "window.h"
|
||||
#include "song.h"
|
||||
|
||||
template <size_t N> inline size_t static_strlen(const char (&)[N])
|
||||
{
|
||||
return N-1;
|
||||
}
|
||||
|
||||
void ToLower(std::string &);
|
||||
|
||||
int StrToInt(const std::string &);
|
||||
|
||||
12
src/info.cpp
12
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("</name>");
|
||||
result[j] = '.';
|
||||
i += 6;
|
||||
i += static_strlen("<name>");
|
||||
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("</url>");
|
||||
result[j] = '.';
|
||||
i += 5;
|
||||
i += static_strlen("<url>");
|
||||
urls.push_back(result.substr(i, j-i));
|
||||
}
|
||||
|
||||
a = result.find("<content>")+9;
|
||||
a = result.find("<content>")+static_strlen("<content>");
|
||||
b = result.find("</content>");
|
||||
|
||||
if (a == b)
|
||||
@@ -287,8 +287,8 @@ void *Info::PrepareArtist(void *screen_void_ptr)
|
||||
}
|
||||
else
|
||||
{
|
||||
a += 9; // for <![CDATA[
|
||||
b -= 3; // for ]]>
|
||||
a += static_strlen("<![CDATA[");
|
||||
b -= static_strlen("]]>");
|
||||
result = result.substr(a, b-a);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user