perform one more check on song formats
it detects something like this: %. (where . doesn't stand for a valid tag type).
This commit is contained in:
@@ -147,13 +147,15 @@ void ParseArgv(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
if (argc > ++i)
|
if (argc > ++i)
|
||||||
{
|
{
|
||||||
// apply additional pair of braces
|
if (MPD::Song::isFormatOk("now-playing format", now_playing_format))
|
||||||
now_playing_format = "{";
|
{
|
||||||
now_playing_format += argv[i];
|
// apply additional pair of braces
|
||||||
now_playing_format += "}";
|
now_playing_format = "{";
|
||||||
Replace(now_playing_format, "\\n", "\n");
|
now_playing_format += argv[i];
|
||||||
Replace(now_playing_format, "\\t", "\t");
|
now_playing_format += "}";
|
||||||
MPD::Song::ValidateFormat("now-playing format", now_playing_format);
|
Replace(now_playing_format, "\\n", "\n");
|
||||||
|
Replace(now_playing_format, "\\t", "\t");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::cout << utf_to_locale_cpy(Mpd.GetCurrentSong().toString(now_playing_format)) << "\n";
|
std::cout << utf_to_locale_cpy(Mpd.GetCurrentSong().toString(now_playing_format)) << "\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -691,9 +691,8 @@ void NcmpcppConfig::Read()
|
|||||||
}
|
}
|
||||||
else if (cl.find("song_list_format") != std::string::npos)
|
else if (cl.find("song_list_format") != std::string::npos)
|
||||||
{
|
{
|
||||||
if (!v.empty())
|
if (!v.empty() && MPD::Song::isFormatOk("song_list_format", v))
|
||||||
{
|
{
|
||||||
MPD::Song::ValidateFormat("song_list_format", v);
|
|
||||||
song_list_format = '{';
|
song_list_format = '{';
|
||||||
song_list_format += v;
|
song_list_format += v;
|
||||||
song_list_format += '}';
|
song_list_format += '}';
|
||||||
@@ -706,9 +705,8 @@ void NcmpcppConfig::Read()
|
|||||||
}
|
}
|
||||||
else if (cl.find("song_status_format") != std::string::npos)
|
else if (cl.find("song_status_format") != std::string::npos)
|
||||||
{
|
{
|
||||||
if (!v.empty())
|
if (!v.empty() && MPD::Song::isFormatOk("song_status_format", v))
|
||||||
{
|
{
|
||||||
MPD::Song::ValidateFormat("song_status_format", v);
|
|
||||||
song_status_format = '{';
|
song_status_format = '{';
|
||||||
song_status_format += v;
|
song_status_format += v;
|
||||||
song_status_format += '}';
|
song_status_format += '}';
|
||||||
@@ -725,9 +723,8 @@ void NcmpcppConfig::Read()
|
|||||||
}
|
}
|
||||||
else if (cl.find("song_library_format") != std::string::npos)
|
else if (cl.find("song_library_format") != std::string::npos)
|
||||||
{
|
{
|
||||||
if (!v.empty())
|
if (!v.empty() && MPD::Song::isFormatOk("song_library_format", v))
|
||||||
{
|
{
|
||||||
MPD::Song::ValidateFormat("song_library_format", v);
|
|
||||||
song_library_format = '{';
|
song_library_format = '{';
|
||||||
song_library_format += v;
|
song_library_format += v;
|
||||||
song_library_format += '}';
|
song_library_format += '}';
|
||||||
@@ -735,9 +732,8 @@ void NcmpcppConfig::Read()
|
|||||||
}
|
}
|
||||||
else if (cl.find("tag_editor_album_format") != std::string::npos)
|
else if (cl.find("tag_editor_album_format") != std::string::npos)
|
||||||
{
|
{
|
||||||
if (!v.empty())
|
if (!v.empty() && MPD::Song::isFormatOk("tag_editor_album_format", v))
|
||||||
{
|
{
|
||||||
MPD::Song::ValidateFormat("tag_editor_album_format", v);
|
|
||||||
tag_editor_album_format = '{';
|
tag_editor_album_format = '{';
|
||||||
tag_editor_album_format += v;
|
tag_editor_album_format += v;
|
||||||
tag_editor_album_format += '}';
|
tag_editor_album_format += '}';
|
||||||
@@ -760,9 +756,8 @@ void NcmpcppConfig::Read()
|
|||||||
}
|
}
|
||||||
else if (cl.find("alternative_header_first_line_format") != std::string::npos)
|
else if (cl.find("alternative_header_first_line_format") != std::string::npos)
|
||||||
{
|
{
|
||||||
if (!v.empty())
|
if (!v.empty() && MPD::Song::isFormatOk("alternative_header_first_line_format", v))
|
||||||
{
|
{
|
||||||
MPD::Song::ValidateFormat("alternative_header_first_line_format", v);
|
|
||||||
new_header_first_line = '{';
|
new_header_first_line = '{';
|
||||||
new_header_first_line += v;
|
new_header_first_line += v;
|
||||||
new_header_first_line += '}';
|
new_header_first_line += '}';
|
||||||
@@ -770,9 +765,8 @@ void NcmpcppConfig::Read()
|
|||||||
}
|
}
|
||||||
else if (cl.find("alternative_header_second_line_format") != std::string::npos)
|
else if (cl.find("alternative_header_second_line_format") != std::string::npos)
|
||||||
{
|
{
|
||||||
if (!v.empty())
|
if (!v.empty() && MPD::Song::isFormatOk("alternative_header_second_line_format", v))
|
||||||
{
|
{
|
||||||
MPD::Song::ValidateFormat("alternative_header_second_line_format", v);
|
|
||||||
new_header_second_line = '{';
|
new_header_second_line = '{';
|
||||||
new_header_second_line += v;
|
new_header_second_line += v;
|
||||||
new_header_second_line += '}';
|
new_header_second_line += '}';
|
||||||
@@ -1096,9 +1090,8 @@ void NcmpcppConfig::Read()
|
|||||||
}
|
}
|
||||||
else if (cl.find("song_window_title_format") != std::string::npos)
|
else if (cl.find("song_window_title_format") != std::string::npos)
|
||||||
{
|
{
|
||||||
if (!v.empty())
|
if (!v.empty() && MPD::Song::isFormatOk("song_window_title_format", v))
|
||||||
{
|
{
|
||||||
MPD::Song::ValidateFormat("song_window_title_format", v);
|
|
||||||
song_window_title_format = '{';
|
song_window_title_format = '{';
|
||||||
song_window_title_format += v;
|
song_window_title_format += v;
|
||||||
song_window_title_format += '}';
|
song_window_title_format += '}';
|
||||||
|
|||||||
20
src/song.cpp
20
src/song.cpp
@@ -25,6 +25,7 @@
|
|||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@@ -492,7 +493,7 @@ std::string MPD::Song::ShowTime(int length)
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::ValidateFormat(const std::string &type, const std::string &s)
|
bool MPD::Song::isFormatOk(const std::string &type, const std::string &s)
|
||||||
{
|
{
|
||||||
int braces = 0;
|
int braces = 0;
|
||||||
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it)
|
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it)
|
||||||
@@ -503,7 +504,22 @@ void MPD::Song::ValidateFormat(const std::string &type, const std::string &s)
|
|||||||
--braces;
|
--braces;
|
||||||
}
|
}
|
||||||
if (braces)
|
if (braces)
|
||||||
FatalError(type + ": number of opening and closing braces does not equal!");
|
{
|
||||||
|
std::cerr << type << ": number of opening and closing braces does not equal!\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = s.find('%'); i != std::string::npos; i = s.find('%', i))
|
||||||
|
{
|
||||||
|
if (isdigit(s[++i]))
|
||||||
|
while (isdigit(s[++i])) { }
|
||||||
|
if (!toGetFunction(s[i]))
|
||||||
|
{
|
||||||
|
std::cerr << type << ": invalid character at position " << IntoStr(s[i]) << ": '" << s[i] << "'\n";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetHashAndSlash()
|
void MPD::Song::SetHashAndSlash()
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ namespace MPD
|
|||||||
Song &operator=(const Song &);
|
Song &operator=(const Song &);
|
||||||
|
|
||||||
static std::string ShowTime(int);
|
static std::string ShowTime(int);
|
||||||
static void ValidateFormat(const std::string &type, const std::string &format);
|
static bool isFormatOk(const std::string &type, const std::string &format);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetHashAndSlash();
|
void SetHashAndSlash();
|
||||||
|
|||||||
Reference in New Issue
Block a user