From 8c39ec9370c11c0a3eda30c574577198bebe4ab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 3 Sep 2001 13:18:28 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2664 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/ChangeLog | 4 ++ src/mathed/math_hash.C | 111 +++++++++++++++++---------------------- src/mathed/math_parser.h | 3 -- 3 files changed, 53 insertions(+), 65 deletions(-) diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 1e89500343..2afc69adea 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,7 @@ +2001-08-17 André Pönitz + + * math_hash.C: Use std::map instead of faking it + 2001-09-02 Dekel Tsur * math_hash.C (in_word_set): Initialize symbol table even when diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index c8f221d445..8004a2680e 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -6,20 +6,12 @@ #include "support/filetools.h" // LibFileSearch #include "support/lyxfunctional.h" -#include +#include #include -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 wordlist; +std::map 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::iterator it = - std::find_if(wordlist.begin(), wordlist.end(), - lyx::compare_memfun(&latexkeys::Name, str)); - return (it != wordlist.end()) ? &(*it) : 0; + std::map::iterator it = wordlist.find(str); + return (it != wordlist.end()) ? &(it->second) : 0; } diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index e1b167a2d4..45c89dddab 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -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;} };