New test.
[libsub.git] / src / iso6937.cc
index 47ce458aa6c85d2b081fe2b457fa7a7a827f4f27..8409f9b00eabdfcfba37ee6246ccb542ef3801e3 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 */
 
-#include <string>
-#include <boost/optional.hpp>
-#include <boost/locale.hpp>
 #include "iso6937_tables.h"
 #include "iso6937.h"
+#include <boost/optional.hpp>
+#include <boost/locale.hpp>
+#include <string>
+#include <iostream>
 
 using std::string;
 using std::cout;
@@ -38,7 +39,7 @@ sub::iso6937_to_utf16 (string s)
        if (iso6937::diacriticals.empty ()) {
                make_iso6937_tables ();
        }
-       
+
        wstring o;
 
        boost::optional<unsigned char> diacritical;
@@ -79,7 +80,7 @@ sub::utf16_to_iso6937 (wstring s)
        if (iso6937::diacriticals.empty ()) {
                make_iso6937_tables ();
        }
-       
+
        /* XXX: slow */
 
        string o;
@@ -97,8 +98,25 @@ sub::utf16_to_iso6937 (wstring s)
                                }
                        }
                }
+
+               if (s[i] == 0x201e) {
+                       /* ISO6397 does not support German (lower) quotation mark (UTF 0x201e) so use
+                          a normal opening one (0x201c, which is 170 in ISO6937).
+                       */
+                       o += (char) 170;
+               } else if (s[i] == 0x2013 || s[i] == 0x2014) {
+                       /* ISO6397 does not support en- or em-dashes, so use a horizontal bar (0x2015,
+                          which is 208 in ISO6937).
+                       */
+                       o += (char) 208;
+               } else if (s[i] == 0x2010 || s[i] == 0x2011 || s[i] == 0x2012) {
+                       /* Similar story with hyphen, non-breaking hyphen, figure dash */
+                       o += '-';
+               } else if (s[i] == 0x2032) {
+                       /* And prime */
+                       o += '\'';
+               }
        }
 
        return o;
 }
-