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/filetools.h"
19 #include "support/lyxlib.h"
21 #include <boost/regex.hpp>
25 using lyx::support::atoi;
26 using lyx::support::LibFileSearch;
40 bool CharacterSet::loadFile(string const & fname)
46 if (fname.empty() || fname == "ascii")
49 // open definition file
51 << "Reading character set file " << fname << ".cdef" << endl;
52 string const filename = LibFileSearch("kbd", fname, "cdef");
53 ifstream ifs(filename.c_str());
55 lyxerr << "Unable to open character set file" << endl;
56 return true; // no definition, use 7-bit ascii
61 // Ok, I'll be the first to admit that this is probably not
62 // the fastest way to parse the cdef files, but I though it
63 // was a bit neat. Anyway it is wrong to use the lyxlex parse
64 // without the use of a keyword table.
65 regex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
66 while (getline(ifs, line)) {
68 if (regex_match(line, sub, reg)) {
69 int const n = atoi(sub.str(1));
70 string const str = sub.str(2);
71 if (lyxerr.debugging(Debug::KBMAP))
72 lyxerr << "Chardef: " << n
73 << " to [" << str << ']' << endl;
77 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
82 pair<bool, int> const CharacterSet::encodeString(string const & str) const
84 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << ']' << endl;
87 Cdef::const_iterator cit = map_.find(str);
88 if (cit != map_.end()) {
92 lyxerr[Debug::KBMAP] << " "
93 << (ret ? "yes we" : "no we don't")
94 << " know [" << str << ']' << endl;
95 return make_pair(ret, val);
99 string const & CharacterSet::getName() const