3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
15 #include "support/filetools.h"
16 #include "support/lyxlib.h"
19 #include <boost/regex.hpp>
23 using namespace lyx::support;
31 using boost::regex_match;
33 #ifndef USE_INCLUDED_STRING
41 bool CharacterSet::loadFile(string const & fname)
47 if (fname.empty() || fname == "ascii")
50 // open definition file
52 << "Reading character set file " << fname << ".cdef" << endl;
53 string const filename = LibFileSearch("kbd", fname, "cdef");
54 ifstream ifs(filename.c_str());
56 lyxerr << "Unable to open character set file" << endl;
57 return true; // no definition, use 7-bit ascii
62 // Ok, I'll be the first to admit that this is probably not
63 // the fastest way to parse the cdef files, but I though it
64 // was a bit neat. Anyway it is wrong to use the lyxlex parse
65 // without the use of a keyword table.
66 regex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
67 while (getline(ifs, line)) {
68 #ifndef USE_INCLUDED_STRING
73 if (regex_match(STRCONV(line), sub, reg)) {
74 int const n = atoi(STRCONV(sub.str(1)));
75 string const str = STRCONV(sub.str(2));
76 if (lyxerr.debugging(Debug::KBMAP))
77 lyxerr << "Chardef: " << n
78 << " to [" << str << ']' << endl;
82 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
87 pair<bool, int> const CharacterSet::encodeString(string const & str) const
89 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << ']' << endl;
92 Cdef::const_iterator cit = map_.find(str);
93 if (cit != map_.end()) {
97 lyxerr[Debug::KBMAP] << " "
98 << (ret ? "yes we" : "no we don't")
99 << " know [" << str << ']' << endl;
100 return make_pair(ret, val);
104 string const & CharacterSet::getName() const