X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FEncoding.cpp;h=71ea8c63e49a944691d5c760bbbc2c7cfa372bbd;hb=6b651f2ad9f698c01993dcc6e340682c279f1c55;hp=d828b9d7e62fbfbe7c84af15e1f17191b330db80;hpb=9d0ea8aeff32833a90b3fe64df0c5518a9e241be;p=lyx.git diff --git a/src/Encoding.cpp b/src/Encoding.cpp index d828b9d7e6..71ea8c63e4 100644 --- a/src/Encoding.cpp +++ b/src/Encoding.cpp @@ -27,17 +27,11 @@ #include -#ifndef CXX_GLOBAL_CSTD -using std::strtol; -#endif -using std::endl; -using std::string; - +using namespace std; +using namespace lyx::support; namespace lyx { -using support::FileName; - Encodings encodings; namespace { @@ -243,7 +237,7 @@ struct CharInfo { }; -typedef std::map CharInfoMap; +typedef map CharInfoMap; CharInfoMap unicodesymbols; @@ -253,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) @@ -281,7 +287,7 @@ void Encoding::init() const // if we check all 256 code points of this encoding. for (unsigned short j = 0; j < 256; ++j) { char const c = char(j); - std::vector const ucs4 = eightbit_to_ucs4(&c, 1, iconvName_); + vector 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); @@ -295,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 const eightbit = ucs4_to_eightbit(&c, 1, iconvName_); + vector 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) @@ -327,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; } @@ -434,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 @@ -464,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 @@ -491,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") @@ -499,7 +502,7 @@ 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; }