get rid of all mysterious numbers that meant length of string literals

This commit is contained in:
Andrzej Rybczak
2009-09-15 23:12:45 +00:00
parent 6e903f9fc8
commit 61a9d6a785
4 changed files with 18 additions and 13 deletions

View File

@@ -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)

View File

@@ -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 &);

View File

@@ -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);
}

View File

@@ -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("&lt;"); i != std::string::npos; i = result.find("&lt;"))
result.replace(i, 4, "<");
result.replace(i, static_strlen("&lt;"), "<");
for (size_t i = result.find("&gt;"); i != std::string::npos; i = result.find("&gt;"))
result.replace(i, 4, ">");
result.replace(i, static_strlen("&gt;"), ">");
EscapeHtml(result);
Trim(result);