Tweak ISO6937 mapping to put $ sign on 0xa4 (164) (from master).
[libsub.git] / src / stl_binary_writer.cc
index 43b0adffdcaef27c7643ea9212a21808c864376d..f1afa2cca7eab0852c108ffef6cc4ef3e69aa663 100644 (file)
@@ -26,6 +26,7 @@
 #include "iso6937.h"
 #include "stl_util.h"
 #include "compose.hpp"
+#include "sub_assert.h"
 #include <boost/locale.hpp>
 #include <list>
 #include <cmath>
@@ -62,8 +63,8 @@ put_string (char* p, string s)
 static void
 put_string (char* p, unsigned int n, string s)
 {
-       assert (s.length() <= n);
-       
+       SUB_ASSERT (s.length() <= n);
+
        memcpy (p, s.c_str (), s.length ());
        memset (p + s.length(), ' ', n - s.length ());
 }
@@ -71,12 +72,12 @@ put_string (char* p, unsigned int n, string s)
 static void
 put_int_as_string (char* p, int v, unsigned int n)
 {
-       std::stringstream s;
+       locked_stringstream s;
        /* Be careful to ensure we get no thousands separators */
        s.imbue (std::locale::classic ());
        s << setw (n) << setfill ('0');
        s << v;
-       assert (s.str().length() == n);
+       SUB_ASSERT (s.str().length() == n);
        put_string (p, s.str ());
 }
 
@@ -110,20 +111,20 @@ sub::write_stl_binary (
        boost::filesystem::path file_name
        )
 {
-       assert (original_programme_title.size() <= 32);
-       assert (original_episode_title.size() <= 32);
-       assert (translated_programme_title.size() <= 32);
-       assert (translated_episode_title.size() <= 32);
-       assert (translator_name.size() <= 32);
-       assert (translator_contact_details.size() <= 32);
-       assert (creation_date.size() == 6);
-       assert (revision_date.size() == 6);
-       assert (revision_number <= 99);
-       assert (country_of_origin.size() == 3);
-       assert (publisher.size() <= 32);
-       assert (editor_name.size() <= 32);
-       assert (editor_contact_details.size() <= 32);
-       
+       SUB_ASSERT (original_programme_title.size() <= 32);
+       SUB_ASSERT (original_episode_title.size() <= 32);
+       SUB_ASSERT (translated_programme_title.size() <= 32);
+       SUB_ASSERT (translated_episode_title.size() <= 32);
+       SUB_ASSERT (translator_name.size() <= 32);
+       SUB_ASSERT (translator_contact_details.size() <= 32);
+       SUB_ASSERT (creation_date.size() == 6);
+       SUB_ASSERT (revision_date.size() == 6);
+       SUB_ASSERT (revision_number <= 99);
+       SUB_ASSERT (country_of_origin.size() == 3);
+       SUB_ASSERT (publisher.size() <= 32);
+       SUB_ASSERT (editor_name.size() <= 32);
+       SUB_ASSERT (editor_contact_details.size() <= 32);
+
        char* buffer = new char[1024];
        memset (buffer, 0, 1024);
        ofstream output (file_name.string().c_str ());
@@ -144,7 +145,7 @@ sub::write_stl_binary (
                        ++lines;
                }
        }
-       
+
        /* Code page: 850 */
        put_string (buffer + 0, "850");
        /* Disk format code */
@@ -256,12 +257,12 @@ sub::write_stl_binary (
                        put_int_as_int (buffer + 14, tables.justification_enum_to_file (JUSTIFICATION_NONE), 1);
                        /* Comment flag */
                        put_int_as_int (buffer + 15, tables.comment_enum_to_file (COMMENT_NO), 1);
-                       
+
                        /* Text */
                        string text;
                        bool italic = false;
                        bool underline = false;
-                       
+
                        for (list<Block>::const_iterator k = j->blocks.begin(); k != j->blocks.end(); ++k) {
                                if (k->underline && !underline) {
                                        text += "\x82";
@@ -277,20 +278,20 @@ sub::write_stl_binary (
                                        text += "\x81";
                                        italic = false;
                                }
-                               
+
                                text += utf16_to_iso6937 (utf_to_utf<wchar_t> (k->text));
                        }
-                       
+
                        text += "\x8A";
-               
+
                        if (text.length() > 111) {
                                text = text.substr (111);
                        }
-                       
+
                        while (text.length() < 112) {
                                text += "\x8F";
                        }
-                       
+
                        put_string (buffer + 16, text);
                        output.write (buffer, 128);