2 Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "iso6937_tables.h"
22 #include <boost/optional.hpp>
23 #include <boost/locale.hpp>
32 using boost::optional;
33 using boost::locale::conv::utf_to_utf;
37 sub::iso6937_to_utf16 (string s)
39 if (iso6937::diacriticals.empty ()) {
40 make_iso6937_tables ();
45 boost::optional<unsigned char> diacritical;
48 while (s[i] != '\0') {
49 unsigned char const u = static_cast<unsigned char> (s[i]);
50 if (u >= 0xc1 && u <= 0xcf) {
52 } else if (diacritical) {
53 o += (*iso6937::diacriticals[diacritical.get()])[u];
56 o += iso6937::main[u];
66 find (map<char, wchar_t> const & m, wchar_t c)
68 for (map<char, wchar_t>::const_iterator i = m.begin(); i != m.end(); ++i) {
74 return optional<char> ();
78 sub::utf16_to_iso6937 (wstring s)
80 if (iso6937::diacriticals.empty ()) {
81 make_iso6937_tables ();
87 for (size_t i = 0; i < s.size(); ++i) {
88 optional<char> c = find (iso6937::main, s[i]);
92 for (map<char, map<char, wchar_t> *>::const_iterator j = iso6937::diacriticals.begin(); j != iso6937::diacriticals.end(); ++j) {
93 c = find (*(j->second), s[i]);
102 if (s[i] == 0x201e) {
103 /* ISO6397 does not support German (lower) quotation mark (UTF 0x201e) so use
104 a normal opening one (0x201c, which is 170 in ISO6937).
107 } else if (s[i] == 0x2013 || s[i] == 0x2014) {
108 /* ISO6397 does not support en- or em-dashes, so use a horizontal bar (0x2015,
109 which is 208 in ISO6937).
112 } else if (s[i] == 0x2010 || s[i] == 0x2011 || s[i] == 0x2012) {
113 /* Similar story with hyphen, non-breaking hyphen, figure dash */