8 #include "support/filetools.h"
9 #include "support/lyxlib.h"
12 #include <boost/regex.hpp>
22 using boost::regex_match;
25 bool CharacterSet::loadFile(string const & fname)
31 if (fname.empty() || fname == "ascii")
34 // open definition file
36 << "Reading character set file " << fname << ".cdef" << endl;
37 string const filename = LibFileSearch("kbd", fname, "cdef");
38 ifstream ifs(filename.c_str());
40 lyxerr << "Unable to open character set file" << endl;
41 return true; // no definition, use 7-bit ascii
46 // Ok, I'll be the first to admit that this is probably not
47 // the fastest way to parse the cdef files, but I though it
48 // was a bit neat. Anyway it is wrong to use the lyxlex parse
49 // without the use of a keyword table.
50 regex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
51 while (getline(ifs, line)) {
53 if (regex_match(line, sub, reg)) {
54 int const n = lyx::atoi(sub[1]);
55 string const str = sub[2];
56 if (lyxerr.debugging(Debug::KBMAP))
57 lyxerr << "Chardef: " << n
58 << " to [" << str << "]" << endl;
62 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
67 pair<bool, int> const CharacterSet::encodeString(string const & str) const
69 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << "]" << endl;
72 Cdef::const_iterator cit = map_.find(str);
73 if (cit != map_.end()) {
77 lyxerr[Debug::KBMAP] << " "
78 << (ret ? "yes we" : "no we don't")
79 << " know [" << str << "]" << endl;
80 return make_pair(ret, val);
84 string const & CharacterSet::getName() const