2 Copyright (C) 2014 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.
21 #include <boost/optional.hpp>
22 #include <boost/locale.hpp>
23 #include "iso6937_tables.h"
31 using boost::optional;
32 using boost::locale::conv::utf_to_utf;
36 sub::iso6937_to_utf16 (string s)
38 if (iso6937::diacriticals.empty ()) {
39 make_iso6937_tables ();
44 boost::optional<unsigned char> diacritical;
47 while (s[i] != '\0') {
48 unsigned char const u = static_cast<unsigned char> (s[i]);
49 if (u >= 0xc1 && u <= 0xcf) {
51 } else if (diacritical) {
52 o += (*iso6937::diacriticals[diacritical.get()])[u];
55 o += iso6937::main[u];
65 find (map<char, wchar_t> const & m, wchar_t c)
67 for (map<char, wchar_t>::const_iterator i = m.begin(); i != m.end(); ++i) {
73 return optional<char> ();
77 sub::utf16_to_iso6937 (wstring s)
79 if (iso6937::diacriticals.empty ()) {
80 make_iso6937_tables ();
86 for (size_t i = 0; i < s.size(); ++i) {
87 optional<char> c = find (iso6937::main, s[i]);
91 for (map<char, map<char, wchar_t> *>::const_iterator j = iso6937::diacriticals.begin(); j != iso6937::diacriticals.end(); ++j) {
92 c = find (*(j->second), s[i]);