8 #include "support/filetools.h"
9 #include "support/lyxlib.h"
12 #include <boost/regex.hpp>
22 using boost::regex_match;
24 #ifndef USE_INCLUDED_STRING
32 bool CharacterSet::loadFile(string const & fname)
38 if (fname.empty() || fname == "ascii")
41 // open definition file
43 << "Reading character set file " << fname << ".cdef" << endl;
44 string const filename = LibFileSearch("kbd", fname, "cdef");
45 ifstream ifs(filename.c_str());
47 lyxerr << "Unable to open character set file" << endl;
48 return true; // no definition, use 7-bit ascii
53 // Ok, I'll be the first to admit that this is probably not
54 // the fastest way to parse the cdef files, but I though it
55 // was a bit neat. Anyway it is wrong to use the lyxlex parse
56 // without the use of a keyword table.
57 regex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
58 while (getline(ifs, line)) {
59 #ifndef USE_INCLUDED_STRING
64 if (regex_match(STRCONV(line), sub, reg)) {
65 int const n = lyx::atoi(STRCONV(sub.str(1)));
66 string const str = STRCONV(sub.str(2));
67 if (lyxerr.debugging(Debug::KBMAP))
68 lyxerr << "Chardef: " << n
69 << " to [" << str << ']' << endl;
73 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
78 pair<bool, int> const CharacterSet::encodeString(string const & str) const
80 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << ']' << endl;
83 Cdef::const_iterator cit = map_.find(str);
84 if (cit != map_.end()) {
88 lyxerr[Debug::KBMAP] << " "
89 << (ret ? "yes we" : "no we don't")
90 << " know [" << str << ']' << endl;
91 return make_pair(ret, val);
95 string const & CharacterSet::getName() const