]> git.lyx.org Git - lyx.git/blobdiff - src/Encoding.cpp
Fix problematic characters in example/template file names
[lyx.git] / src / Encoding.cpp
index 9dde12d1213fc6d06e80ba0d28d27345605e1c39..148ce0b195c44c888bbce672229a8c6d15d528a7 100644 (file)
@@ -59,7 +59,7 @@ MathAlphaSet mathalpha;
 /// The highest code point in UCS4 encoding (1<<20 + 1<<16)
 char_type const max_ucs4 = 0x110000;
 
-} // namespace anon
+} // namespace
 
 
 EncodingException::EncodingException(char_type c)
@@ -264,11 +264,15 @@ vector<char_type> Encoding::symbolsList() const
        vector<char_type> symbols;
        for (char_type c = 0; c < start_encodable_; ++c)
                symbols.push_back(c);
-       //add all encodable characters
+       // add all encodable characters
        copy(encodable_.begin(), encodable_.end(), back_inserter(symbols));
-       // now the ones from the unicodesymbols file
-       for (pair<char_type, CharInfo> const & elem : unicodesymbols)
-               symbols.push_back(elem.first);
+       // now the ones from the unicodesymbols file that are not already there
+       for (pair<char_type, CharInfo> const & elem : unicodesymbols) {
+               if (find(symbols.begin(), symbols.end(), elem.first) == symbols.end())
+                       symbols.push_back(elem.first);
+       }
+       // finally, sort the vector
+       sort(symbols.begin(), symbols.end());
        return symbols;
 }
 
@@ -577,21 +581,29 @@ string const Encodings::TIPAShortcut(char_type c)
 }
 
 
-bool Encodings::isKnownScriptChar(char_type const c, string & preamble)
+string const Encodings::isKnownScriptChar(char_type const c)
 {
        CharInfoMap::const_iterator const it = unicodesymbols.find(c);
 
        if (it == unicodesymbols.end())
-               return false;
+               return string();
+       // FIXME: parse complex textpreamble (may be list or alternatives,
+       //                e.g., "subscript,textgreek" or "textcomp|textgreek")
+       if (it->second.textpreamble() == "textgreek"
+               || it->second.textpreamble() == "textcyrillic")
+               return it->second.textpreamble();
+       return string();
+}
 
-       if (it->second.textpreamble() != "textgreek" && it->second.textpreamble() != "textcyr")
-               return false;
 
-       if (preamble.empty()) {
-               preamble = it->second.textpreamble();
-               return true;
-       }
-       return it->second.textpreamble() == preamble;
+bool Encodings::fontencSupportsScript(string const & fontenc, string const & script)
+{
+       if (script == "textgreek")
+               return (fontenc == "LGR" || fontenc == "TU");
+       if (script == "textcyrillic")
+               return (fontenc == "T2A" || fontenc == "T2B" || fontenc == "T2C"
+                               || fontenc == "X2" || fontenc == "TU");
+       return false;
 }
 
 
@@ -711,16 +723,16 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
                                flags |= CharInfoForce;
                                forced.insert(symbol);
                        } else if (prefixIs(flag, "force=")) {
-                               vector<string> encodings =
+                               vector<string> encs =
                                        getVectorFromString(flag.substr(6), ";");
-                               for (size_t i = 0; i < encodings.size(); ++i)
-                                       forcedselected[encodings[i]].insert(symbol);
+                               for (size_t i = 0; i < encs.size(); ++i)
+                                       forcedselected[encs[i]].insert(symbol);
                                flags |= CharInfoForceSelected;
                        } else if (prefixIs(flag, "force!=")) {
-                               vector<string> encodings =
+                               vector<string> encs =
                                        getVectorFromString(flag.substr(7), ";");
-                               for (size_t i = 0; i < encodings.size(); ++i)
-                                       forcednotselected[encodings[i]].insert(symbol);
+                               for (size_t i = 0; i < encs.size(); ++i)
+                                       forcednotselected[encs[i]].insert(symbol);
                                flags |= CharInfoForceSelected;
                        } else if (flag == "mathalpha") {
                                mathalpha.insert(symbol);