10 #include "support/filetools.h"
11 #include "support/LRegex.h"
12 #include "support/LSubstring.h"
20 bool CharacterSet::loadFile(string const & fname)
25 if (fname.empty() || fname == "ascii")
26 return true; // ascii 7-bit
28 // open definition file
30 << "Reading character set file " << fname << ".cdef" << endl;
31 string filename = LibFileSearch("kbd", fname.c_str(), "cdef");
32 ifstream ifs(filename.c_str());
34 lyxerr << "Unable to open character set file" << endl;
35 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 n = atoi(line.substr(sub[1].first,
51 sub[1].second).c_str());
52 str = LSubstring(line, sub[2].first, sub[2].second);
53 if (lyxerr.debugging(Debug::KBMAP))
54 lyxerr << "Chardef: " << n
55 << " to [" << str << "]" << endl;
59 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
64 pair<bool, int> CharacterSet::encodeString(string & str) const
66 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << "]" << endl;
69 Cdef::const_iterator cit = map_.find(str);
70 if (cit != map_.end()) {
74 lyxerr[Debug::KBMAP] << " "
75 << (ret ? "yes we" : "no we don't")
76 << " know [" << str << "]" << endl;
77 return make_pair(ret, val);
81 string const & CharacterSet::getName() const