aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2010-01-18 03:27:27 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2013-01-05 17:17:45 +0100
commit6866019fdec1c345d4f626861c640122a90e0ce8 (patch)
treef064c5c59d7bc2963c594553587dd6a4d952cc79
parent1d4fd42795331fe1cfb8e404f1784cf20f387649 (diff)
downloadusdx-6866019fdec1c345d4f626861c640122a90e0ce8.tar.gz
usdx-6866019fdec1c345d4f626861c640122a90e0ce8.tar.xz
usdx-6866019fdec1c345d4f626861c640122a90e0ce8.zip
added functions for parsing float, int and bool headers
-rw-r--r--src/base/song.cpp57
-rw-r--r--src/base/song.hpp3
2 files changed, 60 insertions, 0 deletions
diff --git a/src/base/song.cpp b/src/base/song.cpp
index f596e480..a12a6657 100644
--- a/src/base/song.cpp
+++ b/src/base/song.cpp
@@ -26,6 +26,7 @@
#include "song.hpp"
#include "lyric_word.hpp"
+#include "utils/locale_independent_float.hpp"
namespace usdx
{
@@ -119,6 +120,62 @@ namespace usdx
return result;
}
+ float Song::get_header_tag_float(const std::string& tag, const bool required)
+ {
+ std::map<std::string, std::string>::iterator it;
+ float result;
+
+ if ((it = custom_header_tags.find(tag)) != custom_header_tags.end()) {
+ result = LocaleIndependentFloat(it->second).get_value();
+ custom_header_tags.erase(it);
+ }
+ else if (required) {
+ LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << get_filename() << "'");
+ throw "Incomplete Song! Missing Tag.";
+ }
+
+ return result;
+ }
+
+ int Song::get_header_tag_int(const std::string& tag, const bool required)
+ {
+ std::map<std::string, std::string>::iterator it;
+ int result;
+
+ if ((it = custom_header_tags.find(tag)) != custom_header_tags.end()) {
+ std::istringstream stream(it->second);
+ custom_header_tags.erase(it);
+ stream >> result;
+ }
+ else if (required) {
+ LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << get_filename() << "'");
+ throw "Incomplete Song! Missing Tag.";
+ }
+
+ return result;
+ }
+
+ bool Song::get_header_tag_bool(const std::string& tag, const bool required)
+ {
+ std::map<std::string, std::string>::iterator it;
+ bool result;
+
+ if ((it = custom_header_tags.find(tag)) != custom_header_tags.end()) {
+ // accept all like (YES, JA, TRUE, 1)
+ result = (it->second[0] == 'j' || it->second[0] == 'J' ||
+ it->second[0] == 'y' || it->second[0] == 'Y' ||
+ it->second[0] == 't' || it->second[0] == 'T' ||
+ it->second[0] == '1');
+ custom_header_tags.erase(it);
+ }
+ else if (required) {
+ LOG4CXX_ERROR(log, "Incomplete Song! Missing '" << tag << "' Tag in: '" << get_filename() << "'");
+ throw "Incomplete Song! Missing Tag.";
+ }
+
+ return result;
+ }
+
LyricLine* Song::get_last_lyric_line(void)
{
if (lyrics.size() > 0) {
diff --git a/src/base/song.hpp b/src/base/song.hpp
index 91d22742..47f2d3a4 100644
--- a/src/base/song.hpp
+++ b/src/base/song.hpp
@@ -80,6 +80,9 @@ namespace usdx
std::map<std::string, std::string> custom_header_tags;
std::string get_header_tag(const std::string& tag, const bool required = false);
+ float get_header_tag_float(const std::string& tag, const bool required = false);
+ int get_header_tag_int(const std::string& tag, const bool required = false);
+ bool get_header_tag_bool(const std::string& tag, const bool required = false);
LyricLine* get_last_lyric_line(void);
LyricLine* create_new_lyric_line(int start);