Change from_argb_hex() (which wasn't being used) to from_rgba_hex().
[libsub.git] / src / stl_binary_tables.cc
index 7fdad7b6121852acd55a8c3226e8ba098680466f..2d275df82ce4fca2bae71d03d47fba220c769195 100644 (file)
@@ -19,8 +19,8 @@
 
 #include "stl_binary_tables.h"
 #include "exceptions.h"
+#include "sub_assert.h"
 #include "compose.hpp"
-#include <cassert>
 
 using std::map;
 using std::string;
@@ -33,7 +33,6 @@ code (map<F, STLBinaryCode<E> >& m, F k, E v, string d)
        m[k] = STLBinaryCode<E> (v, d);
 }
 
-
 template <class E, class F>
 E
 file_to_enum (F k, map<F, STLBinaryCode<E> > m, string name)
@@ -56,7 +55,7 @@ enum_to_file (E k, map<F, STLBinaryCode<E> > m)
                }
        }
 
-       assert (false);
+       SUB_ASSERT (false);
        return F ();
 }
 
@@ -72,7 +71,20 @@ enum_to_description (E v, map<F, STLBinaryCode<E> > const & m)
 
        return "";
 }
-             
+
+template <class E, class F>
+boost::optional<E>
+description_to_enum (string d, map<F, STLBinaryCode<E> > const & m)
+{
+       for (typename map<F, STLBinaryCode<E> >::const_iterator i = m.begin(); i != m.end(); ++i) {
+               if (i->second.description == d) {
+                       return i->second.value;
+               }
+       }
+
+       return boost::optional<E> ();
+}
+
 DisplayStandard
 STLBinaryTables::display_standard_file_to_enum (string s) const
 {
@@ -138,13 +150,13 @@ STLBinaryTables::comment_enum_to_file (Comment v) const
 {
        return enum_to_file (v, _comment_map);
 }
-             
+
 string
 STLBinaryTables::display_standard_enum_to_description (DisplayStandard v) const
 {
        return enum_to_description (v, _display_standard_map);
 }
-       
+
 string
 STLBinaryTables::language_group_enum_to_description (LanguageGroup v) const
 {
@@ -181,19 +193,26 @@ STLBinaryTables::comment_enum_to_description (Comment v) const
        return enum_to_description (v, _comment_map);
 }
 
+boost::optional<Language>
+STLBinaryTables::language_description_to_enum (string d) const
+{
+       return description_to_enum (d, _language_map);
+}
+
 STLBinaryTables::STLBinaryTables ()
 {
        code<DisplayStandard, string> (_display_standard_map, " ", DISPLAY_STANDARD_UNDEFINED, "Undefined");
        code<DisplayStandard, string> (_display_standard_map, "0", DISPLAY_STANDARD_OPEN_SUBTITLING, "Open subtitling");
        code<DisplayStandard, string> (_display_standard_map, "1", DISPLAY_STANDARD_LEVEL_1_TELETEXT, "Level 1 teletext");
        code<DisplayStandard, string> (_display_standard_map, "2", DISPLAY_STANDARD_LEVEL_2_TELETEXT, "Level 2 teletext");
-       
+
        code<LanguageGroup, string> (_language_group_map, "00", LANGUAGE_GROUP_LATIN, "Latin");
        code<LanguageGroup, string> (_language_group_map, "01", LANGUAGE_GROUP_LATIN_CYRILLIC, "Latin/Cyrillic");
        code<LanguageGroup, string> (_language_group_map, "02", LANGUAGE_GROUP_LATIN_ARABIC, "Latin/Arabic");
        code<LanguageGroup, string> (_language_group_map, "03", LANGUAGE_GROUP_LATIN_GREEK, "Latin/Greek");
        code<LanguageGroup, string> (_language_group_map, "04", LANGUAGE_GROUP_LATIN_HEBREW, "Latin/Hebrew");
-       
+       code<LanguageGroup, string> (_language_group_map, "U8", LANGUAGE_GROUP_LATIN_HEBREW, "UTF-8");
+
        code<Language, string> (_language_map, "00", LANGUAGE_UNKNOWN, "Unknown");
        code<Language, string> (_language_map, "01", LANGUAGE_ALBANIAN, "Albanian");
        code<Language, string> (_language_map, "02", LANGUAGE_BRETON, "Breton");
@@ -309,7 +328,7 @@ STLBinaryTables::STLBinaryTables ()
        code<Justification, int> (_justification_map, 0, JUSTIFICATION_NONE, "No justification");
        code<Justification, int> (_justification_map, 1, JUSTIFICATION_LEFT, "Left justification");
        code<Justification, int> (_justification_map, 2, JUSTIFICATION_CENTRE, "Centre justification");
-       code<Justification, int> (_justification_map, 3, JUSTIFICATION_CENTRE, "Right justification");
+       code<Justification, int> (_justification_map, 3, JUSTIFICATION_RIGHT, "Right justification");
 
        code<Comment, int> (_comment_map, 0, COMMENT_NO, "Not a comment");
        code<Comment, int> (_comment_map, 1, COMMENT_YES, "Is a comment");