3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
18 #include "support/convert.h"
19 #include "support/filetools.h"
21 #include <boost/regex.hpp>
25 using lyx::support::libFileSearch;
39 bool CharacterSet::loadFile(string const & fname)
45 if (fname.empty() || fname == "ascii")
48 // open definition file
50 << "Reading character set file " << fname << ".cdef" << endl;
51 string const filename = libFileSearch("kbd", fname, "cdef");
52 ifstream ifs(filename.c_str());
54 lyxerr << "Unable to open character set file" << endl;
55 return true; // no definition, use 7-bit ascii
60 // Ok, I'll be the first to admit that this is probably not
61 // the fastest way to parse the cdef files, but I though it
62 // was a bit neat. Anyway it is wrong to use the lyxlex parse
63 // without the use of a keyword table.
64 regex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
65 while (getline(ifs, line)) {
67 if (regex_match(line, sub, reg)) {
68 int const n = convert<int>(sub.str(1));
69 string const str = sub.str(2);
70 if (lyxerr.debugging(Debug::KBMAP))
71 lyxerr << "Chardef: " << n
72 << " to [" << str << ']' << endl;
76 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
81 pair<bool, int> const CharacterSet::encodeString(string const & str) const
83 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << ']' << endl;
86 Cdef::const_iterator cit = map_.find(str);
87 if (cit != map_.end()) {
91 lyxerr[Debug::KBMAP] << " "
92 << (ret ? "yes we" : "no we don't")
93 << " know [" << str << ']' << endl;
94 return make_pair(ret, val);
98 string const & CharacterSet::getName() const