move code responsible for replacing content in strings to Replace()
This commit is contained in:
@@ -199,12 +199,9 @@ void EscapeHtml(std::string &s)
|
||||
size_t j = s.find(">")+1;
|
||||
s.replace(i, j-i, "");
|
||||
}
|
||||
for (size_t i = s.find("'"); i != std::string::npos; i = s.find("'"))
|
||||
s.replace(i, static_strlen("'"), "'");
|
||||
for (size_t i = s.find("""); i != std::string::npos; i = s.find("""))
|
||||
s.replace(i, static_strlen("""), "\"");
|
||||
for (size_t i = s.find("&"); i != std::string::npos; i = s.find("&"))
|
||||
s.replace(i, static_strlen("&"), "&");
|
||||
Replace(s, "'", "'");
|
||||
Replace(s, """, "\"");
|
||||
Replace(s, "&", "&");
|
||||
for (size_t i = 0; i < s.length(); ++i)
|
||||
{
|
||||
if (erase)
|
||||
|
||||
@@ -31,6 +31,12 @@ template <size_t N> inline size_t static_strlen(const char (&)[N])
|
||||
return N-1;
|
||||
}
|
||||
|
||||
template <size_t N> void Replace(std::string &s, const char (&from)[N], const char *to)
|
||||
{
|
||||
for (size_t i = 0; (i = s.find(from, i)) != std::string::npos; i += N)
|
||||
s.replace(i, N-1, to);
|
||||
}
|
||||
|
||||
void ToLower(std::string &);
|
||||
|
||||
int StrToInt(const std::string &);
|
||||
|
||||
@@ -315,8 +315,7 @@ std::string GetLineValue(std::string &line, char a, char b, bool once)
|
||||
}
|
||||
pos[0]++;
|
||||
std::string result = pos[0] >= 0 && pos[1] >= 0 ? line.substr(pos[0], pos[1]-pos[0]) : "";
|
||||
for (i = result.find("\\\""); i != std::string::npos; i = result.find("\\\""))
|
||||
result.replace(i, 2, "\"");
|
||||
Replace(result, "\\\"", "\"");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -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%"), static_strlen("%artist%"), c_artist);
|
||||
url.replace(url.find("%title%"), static_strlen("%title%"), c_title);
|
||||
Replace(url, "%artist%", c_artist);
|
||||
Replace(url, "%title%", c_title);
|
||||
|
||||
CURLcode code;
|
||||
pthread_mutex_lock(&CurlLock);
|
||||
@@ -255,10 +255,8 @@ void *Lyrics::Get(void *screen_void_ptr)
|
||||
pthread_exit(0);
|
||||
}
|
||||
|
||||
for (size_t i = result.find("<"); i != std::string::npos; i = result.find("<"))
|
||||
result.replace(i, static_strlen("<"), "<");
|
||||
for (size_t i = result.find(">"); i != std::string::npos; i = result.find(">"))
|
||||
result.replace(i, static_strlen(">"), ">");
|
||||
Replace(result, "<", "<");
|
||||
Replace(result, ">", ">");
|
||||
|
||||
EscapeHtml(result);
|
||||
Trim(result);
|
||||
|
||||
@@ -415,7 +415,7 @@ std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char *
|
||||
std::string tag = GetTags(get);
|
||||
if (escape_chars) // prepend format escape character to all given chars to escape
|
||||
for (const char *ch = escape_chars; *ch; ++ch)
|
||||
for (size_t i = tag.find(*ch); i != std::string::npos; i = tag.find(*ch, i += 2))
|
||||
for (size_t i = 0; (i = tag.find(*ch), i) != std::string::npos; i += 2)
|
||||
tag.replace(i, 1, std::string(1, FormatEscapeCharacter) + ch);
|
||||
if (!tag.empty() && (get != &MPD::Song::GetLength || GetTotalLength()))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user