]> git.lyx.org Git - features.git/commitdiff
*** empty log message ***
authorAndré Pönitz <poenitz@gmx.net>
Mon, 3 Sep 2001 13:18:28 +0000 (13:18 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Mon, 3 Sep 2001 13:18:28 +0000 (13:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2664 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/math_hash.C
src/mathed/math_parser.h

index 1e89500343ecb7c404d70d70ce6ab049986af953..2afc69adeaac357010bb187a9f56b08e341b8889 100644 (file)
@@ -1,3 +1,7 @@
+2001-08-17  André Pönitz  <poenitz@gmx.net>
+
+       * math_hash.C: Use std::map instead of faking it
+
 2001-09-02  Dekel Tsur  <dekelts@tau.ac.il>
 
        * math_hash.C (in_word_set): Initialize symbol table even when
index c8f221d4457ce299ae527d59dad6f6f3939b95e7..8004a2680e6b3190c933ec49a59489d146ad4cc7 100644 (file)
@@ -6,20 +6,12 @@
 #include "support/filetools.h" // LibFileSearch
 #include "support/lyxfunctional.h"
 
-#include <vector>
+#include <map>
 #include <algorithm>
 
-using std::endl;
-
-bool operator<(const latexkeys & a, const latexkeys & b)
-{
-       return string(a.name) < string(b.name);
-}
 
 namespace {
 
-// This lists needs to remain sorted all the time!
-
 struct latexkeys_a {
        ///
        char const * name;
@@ -141,13 +133,39 @@ latexkeys_a wordlist_array[] =
        {"{",  LM_TK_SPECIAL, '{'},
        {"|",  LM_TK_UNDEF, '|'},
        {"}",  LM_TK_SPECIAL, '}'},
-       {"", LM_TK_SPECIAL, 0}
 };
 
 
-std::vector<latexkeys> wordlist;
+std::map<string, latexkeys> wordlist;
+
+
+
+MathTokenEnum tokenEnum(const string & font)
+{
+       if (font == "cmr")
+               return LM_TK_CMR;
+       if (font == "cmsy")
+               return LM_TK_CMSY;
+       if (font == "cmm")
+               return LM_TK_CMM;
+       if (font == "cmex")
+               return LM_TK_CMEX;
+       if (font == "msa")
+               return LM_TK_MSA;
+       if (font == "msb")
+               return LM_TK_MSB;
+       return LM_TK_SYM;
+}
+
+MathSymbolTypes symbolType(const string & type)
+{
+       if (type == "mathrel")
+               return LMB_RELATION;
+       if (type == "mathbin")
+               return LMB_OPERATOR;    
+       return LMB_NONE;
+}
 
-bool initialized = false;
 
 } // namespace anon
 
@@ -156,84 +174,53 @@ void ReadSymbols(string const & filename)
 {
        LyXLex lex(0, 0);
        lex.setFile(filename);
-       while (lex.isOK()) {
+       while (lex.isOK() && lex.next()) {
                latexkeys tmp;
-               string font;
-               string type;
-               
+               tmp.name = lex.getString();
                if (lex.next())
-                       tmp.name = lex.getString();
-               else
-                       break;
-
-               if (lex.next())
-                       font = lex.getString();
+                       tmp.token = tokenEnum(lex.getString());
                if (lex.next())
                        tmp.latex_font_id = lex.getInteger();
                if (lex.next())
                        tmp.id = lex.getInteger();
                if (lex.next())
-                       type = lex.getString();
-
-               if (font == "cmr")
-                       tmp.token = LM_TK_CMR;
-               else if (font == "cmsy")
-                       tmp.token = LM_TK_CMSY;
-               else if (font == "cmm")
-                       tmp.token = LM_TK_CMM;
-               else if (font == "cmex")
-                       tmp.token = LM_TK_CMEX;
-               else if (font == "msa")
-                       tmp.token = LM_TK_MSA;
-               else if (font == "msb")
-                       tmp.token = LM_TK_MSB;
-               else
-                       tmp.token = LM_TK_SYM;
-
-               if (type == "mathrel")
-                       tmp.type = LMB_RELATION;
-               else if (type == "mathbin")
-                       tmp.type = LMB_OPERATOR;
-               else
-                       tmp.type = LMB_NONE;
-
-               wordlist.push_back(tmp);
+                       tmp.type = symbolType(lex.getString());
+               wordlist[tmp.name] = tmp;
        }
 }
 
 
-void InitSymbols()
+void initSymbols()
 {
-       for (latexkeys_a * p = wordlist_array; !string(p->name).empty(); ++p) {
+       unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
+       for (latexkeys_a * p = wordlist_array; p != wordlist_array + n; ++p) {
                latexkeys tmp;
-               tmp.name   = p->name;
-               tmp.token  = p->token;
-               tmp.id     = p->id;
-               tmp.type   = LMB_NONE;
+               tmp.name          = p->name;
+               tmp.token         = p->token;
+               tmp.id            = p->id;
+               tmp.type          = LMB_NONE;
                tmp.latex_font_id = 0;
-               wordlist.push_back(tmp);
+               wordlist[p->name] = tmp;
        }
 
        lyxerr[Debug::MATHED] << "Reading symbols file\n";
        string const file = LibFileSearch(string(), "symbols");
        if (file.empty())
-               lyxerr << "Could not find symbols file" << endl;
+               lyxerr << "Could not find symbols file\n";
        else
                ReadSymbols(file);
-
-       std::sort(wordlist.begin(), wordlist.end());
 }
 
 
 latexkeys const * in_word_set(string const & str)
 {
+       static bool initialized = false;
+
        if (!initialized) {
-               InitSymbols();
+               initSymbols();
                initialized = true;
        }
 
-       std::vector<latexkeys>::iterator it =
-               std::find_if(wordlist.begin(), wordlist.end(),
-                            lyx::compare_memfun(&latexkeys::Name, str));
-       return  (it != wordlist.end()) ? &(*it) : 0;
+       std::map<string, latexkeys>::iterator it = wordlist.find(str);
+       return (it != wordlist.end()) ? &(it->second) : 0;
 }
index e1b167a2d4bffde5fc5f7c8ca16f22e818a7e808..45c89dddab19b76b2533fcf155c6bdebc3c37025 100644 (file)
@@ -28,7 +28,6 @@
 #include "math_defs.h"
 #include "symbol_def.h"
 
-class MathArray;
 class MathMatrixInset;
 class MathMacroTemplate;
 class LyXLex;
@@ -129,8 +128,6 @@ struct latexkeys {
        unsigned char latex_font_id;
        ///
        MathSymbolTypes type;
-       ///
-       string const & Name() const { return name;}
 };