validate correctness of song formats at start
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
# include <sys/stat.h>
|
||||
#endif // WIN32
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "global.h"
|
||||
#include "helpers.h"
|
||||
@@ -61,6 +62,20 @@ namespace
|
||||
key[1] = !two.empty() && two[0] == '\'' ? two[1] : (atoi(two.c_str()) == 0 ? null_key : atoi(two.c_str()));
|
||||
}
|
||||
|
||||
void ValidateSongFormat(const std::string &type, const std::string &s)
|
||||
{
|
||||
int braces = 0;
|
||||
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it)
|
||||
{
|
||||
if (*it == '{')
|
||||
++braces;
|
||||
else if (*it == '}')
|
||||
--braces;
|
||||
}
|
||||
if (braces)
|
||||
throw std::runtime_error(type + ": number of opening and closing braces does not equal!");
|
||||
}
|
||||
|
||||
Border IntoBorder(const std::string &color)
|
||||
{
|
||||
return Border(IntoColor(color));
|
||||
@@ -522,7 +537,12 @@ void ReadConfiguration(ncmpcpp_config &conf)
|
||||
else if (cl.find("song_list_format") != std::string::npos)
|
||||
{
|
||||
if (!v.empty())
|
||||
conf.song_list_format = v;
|
||||
{
|
||||
ValidateSongFormat("song_list_format", v);
|
||||
conf.song_list_format = '{';
|
||||
conf.song_list_format += v;
|
||||
conf.song_list_format += '}';
|
||||
}
|
||||
}
|
||||
else if (cl.find("song_columns_list_format") != std::string::npos)
|
||||
{
|
||||
@@ -532,17 +552,32 @@ void ReadConfiguration(ncmpcpp_config &conf)
|
||||
else if (cl.find("song_status_format") != std::string::npos)
|
||||
{
|
||||
if (!v.empty())
|
||||
conf.song_status_format = v;
|
||||
{
|
||||
ValidateSongFormat("song_status_format", v);
|
||||
conf.song_status_format = '{';
|
||||
conf.song_status_format += v;
|
||||
conf.song_status_format += '}';
|
||||
}
|
||||
}
|
||||
else if (cl.find("song_library_format") != std::string::npos)
|
||||
{
|
||||
if (!v.empty())
|
||||
conf.song_library_format = v;
|
||||
{
|
||||
ValidateSongFormat("song_library_format", v);
|
||||
conf.song_library_format = '{';
|
||||
conf.song_library_format += v;
|
||||
conf.song_library_format += '}';
|
||||
}
|
||||
}
|
||||
else if (cl.find("tag_editor_album_format") != std::string::npos)
|
||||
{
|
||||
if (!v.empty())
|
||||
conf.tag_editor_album_format = v;
|
||||
{
|
||||
ValidateSongFormat("tag_editor_album_format", v);
|
||||
conf.tag_editor_album_format = '{';
|
||||
conf.tag_editor_album_format += v;
|
||||
conf.tag_editor_album_format += '}';
|
||||
}
|
||||
}
|
||||
else if (cl.find("external_editor") != std::string::npos)
|
||||
{
|
||||
@@ -562,12 +597,22 @@ void ReadConfiguration(ncmpcpp_config &conf)
|
||||
else if (cl.find("alternative_header_first_line_format") != std::string::npos)
|
||||
{
|
||||
if (!v.empty())
|
||||
conf.new_header_first_line = v;
|
||||
{
|
||||
ValidateSongFormat("alternative_header_first_line_format", v);
|
||||
conf.new_header_first_line = '{';
|
||||
conf.new_header_first_line += v;
|
||||
conf.new_header_first_line += '}';
|
||||
}
|
||||
}
|
||||
else if (cl.find("alternative_header_second_line_format") != std::string::npos)
|
||||
{
|
||||
if (!v.empty())
|
||||
conf.new_header_second_line = v;
|
||||
{
|
||||
ValidateSongFormat("alternative_header_second_line_format", v);
|
||||
conf.new_header_second_line = '{';
|
||||
conf.new_header_second_line += v;
|
||||
conf.new_header_second_line += '}';
|
||||
}
|
||||
}
|
||||
else if (cl.find("browser_playlist_prefix") != std::string::npos)
|
||||
{
|
||||
@@ -744,7 +789,12 @@ void ReadConfiguration(ncmpcpp_config &conf)
|
||||
else if (cl.find("song_window_title_format") != std::string::npos)
|
||||
{
|
||||
if (!v.empty())
|
||||
conf.song_window_title_format = v;
|
||||
{
|
||||
ValidateSongFormat("song_window_title_format", v);
|
||||
conf.song_window_title_format = '{';
|
||||
conf.song_window_title_format += v;
|
||||
conf.song_window_title_format += '}';
|
||||
}
|
||||
}
|
||||
else if (cl.find("empty_tag") != std::string::npos)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user