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