]> git.lyx.org Git - lyx.git/blobdiff - src/Encoding.cpp
* Doxy: polish html output.
[lyx.git] / src / Encoding.cpp
index 6f009046a3ede0bcf08f0d6e1089cd165d01cf09..71ea8c63e49a944691d5c760bbbc2c7cfa372bbd 100644 (file)
 
 #include "Encoding.h"
 
-#include "debug.h"
 #include "LaTeXFeatures.h"
 #include "Lexer.h"
 #include "LyXRC.h"
 
+#include "support/debug.h"
 #include "support/FileName.h"
 #include "support/lstrings.h"
 #include "support/unicode.h"
 
-#include <sstream>
+#include <boost/cstdint.hpp>
 
-#ifndef CXX_GLOBAL_CSTD
-using std::strtol;
-#endif
-using std::endl;
-using std::string;
+#include <sstream>
 
+using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::FileName;
-
 Encodings encodings;
 
 namespace {
@@ -241,7 +237,7 @@ struct CharInfo {
 };
 
 
-typedef std::map<char_type, CharInfo> CharInfoMap;
+typedef map<char_type, CharInfo> CharInfoMap;
 CharInfoMap unicodesymbols;
 
 
@@ -251,6 +247,18 @@ char_type const max_ucs4 = 0x110000;
 } // namespace anon
 
 
+EncodingException::EncodingException(char_type c)
+       : failed_char(c), par_id(0), pos(0)
+{
+}
+
+
+const char * EncodingException::what() const throw()
+{
+       return "Could not find LaTeX command for a character";
+}
+
+
 Encoding::Encoding(string const & n, string const & l, string const & i,
                   bool f, Encoding::Package p)
        : Name_(n), LatexName_(l), iconvName_(i), fixedwidth_(f), package_(p)
@@ -278,8 +286,8 @@ void Encoding::init() const
                // We do not need to check all UCS4 code points, it is enough
                // if we check all 256 code points of this encoding.
                for (unsigned short j = 0; j < 256; ++j) {
-                       char const c = j;
-                       std::vector<char_type> const ucs4 = eightbit_to_ucs4(&c, 1, iconvName_);
+                       char const c = char(j);
+                       vector<char_type> const ucs4 = eightbit_to_ucs4(&c, 1, iconvName_);
                        if (ucs4.size() == 1) {
                                char_type const c = ucs4[0];
                                CharInfoMap::const_iterator const it = unicodesymbols.find(c);
@@ -293,7 +301,7 @@ void Encoding::init() const
                // therefore we need to check all UCS4 code points.
                // This is expensive!
                for (char_type c = 0; c < max_ucs4; ++c) {
-                       std::vector<char> const eightbit = ucs4_to_eightbit(&c, 1, iconvName_);
+                       vector<char> const eightbit = ucs4_to_eightbit(&c, 1, iconvName_);
                        if (!eightbit.empty()) {
                                CharInfoMap::const_iterator const it = unicodesymbols.find(c);
                                if (it == unicodesymbols.end() || !it->second.force)
@@ -325,10 +333,7 @@ docstring const Encoding::latexChar(char_type c) const
                // c cannot be encoded in this encoding
                CharInfoMap::const_iterator const it = unicodesymbols.find(c);
                if (it == unicodesymbols.end())
-                       lyxerr << "Could not find LaTeX command for character 0x"
-                              << std::hex << c << std::dec
-                              << ".\nLaTeX export will fail."
-                              << endl;
+                       throw EncodingException(c);
                else
                        return it->second.command;
        }
@@ -401,6 +406,25 @@ bool Encodings::isCombiningChar(char_type c)
 }
 
 
+bool Encodings::isKnownScriptChar(char_type const c, string & preamble)
+{
+       CharInfoMap::const_iterator const it = unicodesymbols.find(c);
+
+       if (it == unicodesymbols.end())
+               return false;
+
+       if (it->second.preamble != "textgreek" &&
+           it->second.preamble != "textcyr")
+               return false;
+
+       if (preamble.empty()) {
+               preamble = it->second.preamble;
+               return true;
+       }
+       return it->second.preamble == preamble;
+}
+
+
 Encoding const * Encodings::getFromLyXName(string const & name) const
 {
        EncodingList::const_iterator it = encodinglist.find(name);
@@ -413,7 +437,7 @@ Encoding const * Encodings::getFromLyXName(string const & name) const
 
 Encoding const * Encodings::getFromLaTeXName(string const & name) const
 {
-       // We don't use std::find_if because it makes copies of the pairs in
+       // We don't use find_if because it makes copies of the pairs in
        // the map.
        // This linear search is OK since we don't have many encodings.
        // Users could even optimize it by putting the encodings they use
@@ -443,11 +467,11 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                string flags;
 
                if (symbolslex.next(true)) {
-                       std::istringstream is(symbolslex.getString());
+                       istringstream is(symbolslex.getString());
                        // reading symbol directly does not work if
-                       // char_type == std::wchar_t.
+                       // char_type == wchar_t.
                        boost::uint32_t tmp;
-                       if(!(is >> std::hex >> tmp))
+                       if(!(is >> hex >> tmp))
                                break;
                        symbol = tmp;
                } else
@@ -470,7 +494,7 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                info.force = false;
                while (!flags.empty()) {
                        string flag;
-                       flags = support::split(flags, flag, ',');
+                       flags = split(flags, flag, ',');
                        if (flag == "combining")
                                info.combining = true;
                        else if (flag == "force")
@@ -478,18 +502,16 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                        else
                                lyxerr << "Ignoring unknown flag `" << flag
                                       << "' for symbol `0x"
-                                      << std::hex << symbol << std::dec
+                                      << hex << symbol << dec
                                       << "'." << endl;
                }
 
                if (!info.preamble.empty())
                        info.feature = info.preamble[0] != '\\';
 
-               LYXERR(Debug::INFO)
-                       << "Read unicode symbol " << symbol << " '"
+               LYXERR(Debug::INFO, "Read unicode symbol " << symbol << " '"
                        << to_utf8(info.command) << "' '" << info.preamble
-                       << "' " << info.combining << ' ' << info.feature
-                       << endl;
+                       << "' " << info.combining << ' ' << info.feature);
                unicodesymbols[symbol] = info;
        }
 
@@ -519,27 +541,31 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                        string const iconvname = lex.getString();
                        lex.next();
                        string const width = lex.getString();
-                       bool fixedwidth;
+                       bool fixedwidth = false;
                        if (width == "fixed")
                                fixedwidth = true;
                        else if (width == "variable")
                                fixedwidth = false;
-                       else
+                       else {
                                lex.printError("Encodings::read: "
                                               "Unknown width: `$$Token'");
+                        }
+                        
                        lex.next();
                        string const p = lex.getString();
-                       Encoding::Package package;
+                       Encoding::Package package = Encoding::none;
                        if (p == "none")
-                               package = Encoding::none;
+                                package = Encoding::none;
                        else if (p == "inputenc")
                                package = Encoding::inputenc;
                        else if (p == "CJK")
                                package = Encoding::CJK;
-                       else
+                       else {
                                lex.printError("Encodings::read: "
                                               "Unknown package: `$$Token'");
-                       LYXERR(Debug::INFO) << "Reading encoding " << name << endl;
+                        }
+                        
+                       LYXERR(Debug::INFO, "Reading encoding " << name);
                        encodinglist[name] = Encoding(name, latexname,
                                                      iconvname, fixedwidth,
                                                      package);