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