X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fmathml_editor%2Fsrc%2FTDictionary.cc;h=25f6c9674cc353c5359eea52e67eaa44493ea8da;hb=97c2d258a5c524eb5c4b85208899d80751a2c82f;hp=b0366338838b4ea20dae7910465f0f3a4159df06;hpb=c112706f347e08e7f345131fbc4c3aa0e9ecc7b5;p=helm.git diff --git a/helm/DEVEL/mathml_editor/src/TDictionary.cc b/helm/DEVEL/mathml_editor/src/TDictionary.cc index b03663388..25f6c9674 100644 --- a/helm/DEVEL/mathml_editor/src/TDictionary.cc +++ b/helm/DEVEL/mathml_editor/src/TDictionary.cc @@ -24,8 +24,10 @@ */ #include +#include #include "dom.hh" +#include "config.dirs" #include "TDictionary.hh" #include "TTokenizer.hh" #include "CLoggerConsole.hh" @@ -48,6 +50,12 @@ getURIName(const std::string& uri) else return uri; } +std::string +TDictionary::getDefaultDictionaryPath() +{ + return PKGDATADIR"/dictionary-tex.xml"; +} + void TDictionary::load(const std::string& uri) { @@ -226,11 +234,48 @@ TDictionary::find(const std::string& name) const if (p != entries.end()) return (*p).second; else { - cerr << "ERROR: unknown entry `" << name << "'" << endl; + logger.warning("unknown entry `" + name + "'"); return undefinedEntry; } } +std::string +TDictionary::complete(const std::string prefix, std::list& complete_list) const +{ + bool no_match = true; + std::string new_prefix = ""; + for (Dictionary::const_iterator i = entries.begin(); i != entries.end(); i++) + { + if ((*i).first.find(prefix) == 0) + { + complete_list.push_front((*i).first); + if (no_match) + { + // it's the first match + no_match = false; + new_prefix = (*i).first; + } + else + { + // in this case, new_prefix has been set yet. + std::string s1 = (*i).first.substr(prefix.length()); // s1 is the high part of the matching string + std::string s2 = new_prefix.substr(prefix.length()); // s2 is the high part of new_prefix +#if 0 + long j = 0; // it's the number of common characters + while (s1[j] == s2[j]) j++; +#endif + std::string::const_iterator i1 = s1.begin(); + std::string::const_iterator i2 = s2.begin(); + while (i1 != s1.end() && i2 != s2.end() && *i1 == *i2) i1++, i2++; + new_prefix = prefix + s1.substr(0, i1 - s1.begin()); + //new_prefix = (j) ? prefix + s1.substr(0, i1 - s1.begin()) : prefix; + } + } + } + + return new_prefix; +} + bool TDictionary::Entry::paramDelimited(unsigned i) const {