]> git.lyx.org Git - lyx.git/blobdiff - src/Encoding.cpp
Revert 23154.
[lyx.git] / src / Encoding.cpp
index c4319ed66bd406e0a6a3f5c904238b2060366d57..cacb31de4f33be56b80fed475bf416eb3639b2d7 100644 (file)
@@ -279,6 +279,9 @@ Encoding::Encoding(string const & n, string const & l, string const & i,
 
 void Encoding::init() const
 {
+       if (complete_)
+               return;
+
        start_encodable_ = 0;
        // temporarily switch off lyxerr, since we will generate iconv errors
        lyxerr.disable();
@@ -288,12 +291,12 @@ void Encoding::init() const
                for (unsigned short j = 0; j < 256; ++j) {
                        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);
-                               if (it == unicodesymbols.end() || !it->second.force)
-                                       encodable_.insert(c);
-                       }
+                       if (ucs4.size() != 1)
+                               continue;
+                       char_type const uc = ucs4[0];
+                       CharInfoMap::const_iterator const it = unicodesymbols.find(uc);
+                       if (it == unicodesymbols.end() || !it->second.force)
+                               encodable_.insert(uc);
                }
        } else {
                // We do not know how many code points this encoding has, and
@@ -323,30 +326,26 @@ void Encoding::init() const
 docstring const Encoding::latexChar(char_type c) const
 {
        // assure the used encoding is properly initialized
-       if (!complete_)
-               init();
-       BOOST_ASSERT(complete_);
+       init();
 
        if (c < start_encodable_)
                return docstring(1, c);
-       if (encodable_.find(c) == encodable_.end()) {
-               // c cannot be encoded in this encoding
-               CharInfoMap::const_iterator const it = unicodesymbols.find(c);
-               if (it == unicodesymbols.end())
-                       throw EncodingException(c);
-               else
-                       return it->second.command;
-       }
-       return docstring(1, c);
+       if (encodable_.find(c) != encodable_.end())
+               return docstring(1, c);
+
+       // c cannot be encoded in this encoding
+       CharInfoMap::const_iterator const it = unicodesymbols.find(c);
+       if (it == unicodesymbols.end())
+               throw EncodingException(c);
+       else
+               return it->second.command;
 }
 
 
 set<char_type> Encoding::getSymbolsList() const
 {
        // assure the used encoding is properly initialized
-       if (!complete_)
-               init();
-       BOOST_ASSERT(complete_);
+       init();
 
        // first all encodable characters
        CharSet symbols = encodable_;
@@ -355,9 +354,9 @@ set<char_type> Encoding::getSymbolsList() const
                symbols.insert(c);
        // now the ones from the unicodesymbols file
        CharInfoMap::const_iterator const end = unicodesymbols.end();
-       for (CharInfoMap::const_iterator it = unicodesymbols.begin(); it != end; ++it) {
+       CharInfoMap::const_iterator it = unicodesymbols.begin();
+       for (; it != end; ++it)
                symbols.insert(it->first);
-       }
        return symbols;
 }
 
@@ -376,8 +375,7 @@ void Encodings::validate(char_type c, LaTeXFeatures & features)
 
 bool Encodings::isComposeChar_hebrew(char_type c)
 {
-       return c <= 0x05c2 && c >= 0x05b0 &&
-              c != 0x05be && c != 0x05c0;
+       return c <= 0x05c2 && c >= 0x05b0 && c != 0x05be && c != 0x05c0;
 }
 
 
@@ -387,11 +385,9 @@ bool Encodings::isComposeChar_hebrew(char_type c)
 
 bool Encodings::is_arabic_special(char_type c)
 {
-       return (c >= 0x0621 && c <= 0x0625) ||
-               c == 0x0627 || c == 0x0629  ||
-               c == 0x062f || c == 0x0648  ||
-              (c >= 0x0630 && c <= 0x0632) ||
-                       c == 0x0649 || c == 0x0698;
+       return (c >= 0x0621 && c <= 0x0625) || (c >= 0x0630 && c <= 0x0632)
+               || c == 0x0627 || c == 0x0629 || c == 0x062f || c == 0x0648
+               || c == 0x0649 || c == 0x0698;
 }
 
 
@@ -403,8 +399,8 @@ bool Encodings::isComposeChar_arabic(char_type c)
 
 bool Encodings::is_arabic(char_type c)
 {
-       return c >= arabic_start && c <= arabic_end &&
-              arabic_table[c-arabic_start][0];
+       return c >= arabic_start && c <= arabic_end
+               && arabic_table[c-arabic_start][0];
 }
 
 
@@ -434,8 +430,7 @@ bool Encodings::isKnownScriptChar(char_type const c, string & preamble)
        if (it == unicodesymbols.end())
                return false;
 
-       if (it->second.preamble != "textgreek" &&
-           it->second.preamble != "textcyr")
+       if (it->second.preamble != "textgreek" && it->second.preamble != "textcyr")
                return false;
 
        if (preamble.empty()) {
@@ -448,11 +443,8 @@ bool Encodings::isKnownScriptChar(char_type const c, string & preamble)
 
 Encoding const * Encodings::getFromLyXName(string const & name) const
 {
-       EncodingList::const_iterator it = encodinglist.find(name);
-       if (it != encodinglist.end())
-               return &it->second;
-       else
-               return 0;
+       EncodingList::const_iterator const it = encodinglist.find(name);
+       return it != encodinglist.end() ? &it->second : 0;
 }
 
 
@@ -487,28 +479,26 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                CharInfo info;
                string flags;
 
-               if (symbolslex.next(true)) {
-                       istringstream is(symbolslex.getString());
-                       // reading symbol directly does not work if
-                       // char_type == wchar_t.
-                       boost::uint32_t tmp;
-                       if(!(is >> hex >> tmp))
-                               break;
-                       symbol = tmp;
-               } else
+               if (!symbolslex.next(true))
                        break;
-               if (symbolslex.next(true))
-                       info.command = symbolslex.getDocString();
-               else
+
+               istringstream is(symbolslex.getString());
+               // reading symbol directly does not work if
+               // char_type == wchar_t.
+               boost::uint32_t tmp;
+               if(!(is >> hex >> tmp))
                        break;
-               if (symbolslex.next(true))
-                       info.preamble = symbolslex.getString();
-               else
+               symbol = tmp;
+
+               if (!symbolslex.next(true))
                        break;
-               if (symbolslex.next(true))
-                       flags = symbolslex.getString();
-               else
+               info.command = symbolslex.getDocString();
+               if (!symbolslex.next(true))
+                       break;
+               info.preamble = symbolslex.getString();
+               if (!symbolslex.next(true))
                        break;
+               flags = symbolslex.getString();
 
                info.combining = false;
                info.feature = false;