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)
27 if (fname.empty() || fname == "ascii")
28 return true; // ascii 7-bit
30 // open definition file
32 << "Reading character set file " << fname << ".cdef" << endl;
33 string const filename = LibFileSearch("kbd", fname, "cdef");
34 ifstream ifs(filename.c_str());
36 lyxerr << "Unable to open character set file" << endl;
37 return true; // no definition, use 7-bit ascii
42 // Ok, I'll be the first to admit that this is probably not
43 // the fastest way to parse the cdef files, but I though it
44 // was a bit neat. Anyway it is wrong to use the lyxlex parse
45 // without the use of a keyword table.
46 LRegex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
47 while(getline(ifs, line)) {
48 if (reg.exact_match(line)) {
49 LRegex::SubMatches const & sub = reg.exec(line);
50 int const n = lyx::atoi(line.substr(sub[1].first,
52 string const str = LSubstring(line, sub[2].first,
54 if (lyxerr.debugging(Debug::KBMAP))
55 lyxerr << "Chardef: " << n
56 << " to [" << str << "]" << endl;
60 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
65 pair<bool, int> const CharacterSet::encodeString(string const & str) const
67 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << "]" << endl;
70 Cdef::const_iterator cit = map_.find(str);
71 if (cit != map_.end()) {
75 lyxerr[Debug::KBMAP] << " "
76 << (ret ? "yes we" : "no we don't")
77 << " know [" << str << "]" << endl;
78 return make_pair(ret, val);
82 string const & CharacterSet::getName() const