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>
28 using support::libFileSearch;
42 bool CharacterSet::loadFile(string const & fname)
48 if (fname.empty() || fname == "ascii")
51 // open definition file
53 << "Reading character set file " << fname << ".cdef" << endl;
54 support::FileName const filename = libFileSearch("kbd", fname, "cdef");
55 ifstream ifs(filename.toFilesystemEncoding().c_str());
57 lyxerr << "Unable to open character set file" << endl;
58 return true; // no definition, use 7-bit ascii
63 // Ok, I'll be the first to admit that this is probably not
64 // the fastest way to parse the cdef files, but I though it
65 // was a bit neat. Anyway it is wrong to use the lyxlex parse
66 // without the use of a keyword table.
67 regex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
68 while (getline(ifs, line)) {
70 if (regex_match(line, sub, reg)) {
71 int const n = convert<int>(sub.str(1));
72 string const str = sub.str(2);
73 if (lyxerr.debugging(Debug::KBMAP))
74 lyxerr << "Chardef: " << n
75 << " to [" << str << ']' << endl;
79 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
84 pair<bool, int> const CharacterSet::encodeString(string const & str) const
86 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << ']' << endl;
89 Cdef::const_iterator cit = map_.find(str);
90 if (cit != map_.end()) {
94 lyxerr[Debug::KBMAP] << " "
95 << (ret ? "yes we" : "no we don't")
96 << " know [" << str << ']' << endl;
97 return make_pair(ret, val);
101 string const & CharacterSet::getName() const