10 #include "support/filetools.h"
11 #include "support/LRegex.h"
12 #include "support/LSubstring.h"
13 #include "support/lyxlib.h"
22 bool CharacterSet::loadFile(string const & fname)
28 if (fname.empty() || fname == "ascii")
31 // open definition file
33 << "Reading character set file " << fname << ".cdef" << endl;
34 string const filename = LibFileSearch("kbd", fname, "cdef");
35 ifstream ifs(filename.c_str());
37 lyxerr << "Unable to open character set file" << endl;
38 return true; // no definition, use 7-bit ascii
43 // Ok, I'll be the first to admit that this is probably not
44 // the fastest way to parse the cdef files, but I though it
45 // was a bit neat. Anyway it is wrong to use the lyxlex parse
46 // without the use of a keyword table.
47 LRegex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
48 while (getline(ifs, line)) {
49 if (reg.exact_match(line)) {
50 LRegex::SubMatches const & sub = reg.exec(line);
51 int const n = lyx::atoi(line.substr(sub[1].first,
53 string const str = LSubstring(line, sub[2].first,
55 if (lyxerr.debugging(Debug::KBMAP))
56 lyxerr << "Chardef: " << n
57 << " to [" << str << "]" << endl;
61 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
66 pair<bool, int> const CharacterSet::encodeString(string const & str) const
68 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << "]" << endl;
71 Cdef::const_iterator cit = map_.find(str);
72 if (cit != map_.end()) {
76 lyxerr[Debug::KBMAP] << " "
77 << (ret ? "yes we" : "no we don't")
78 << " know [" << str << "]" << endl;
79 return make_pair(ret, val);
83 string const & CharacterSet::getName() const