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