10 #include "support/filetools.h"
11 #include "support/LRegex.h"
12 #include "support/LSubstring.h"
21 bool CharacterSet::loadFile(string const & fname)
26 if (fname.empty() || fname == "ascii")
27 return true; // ascii 7-bit
29 // open definition file
31 << "Reading character set file " << fname << ".cdef" << endl;
32 string filename = LibFileSearch("kbd", fname.c_str(), "cdef");
33 ifstream ifs(filename.c_str());
35 lyxerr << "Unable to open character set file" << endl;
36 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 n = atoi(line.substr(sub[1].first,
52 sub[1].second).c_str());
53 str = LSubstring(line, sub[2].first, sub[2].second);
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> 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