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.
18 #include "support/filetools.h"
19 #include "support/lyxlib.h"
21 #include <boost/regex.hpp>
25 using lyx::support::atoi;
26 using lyx::support::LibFileSearch;
37 #ifndef USE_INCLUDED_STRING
44 bool CharacterSet::loadFile(string const & fname)
50 if (fname.empty() || fname == "ascii")
53 // open definition file
55 << "Reading character set file " << fname << ".cdef" << endl;
56 string const filename = LibFileSearch("kbd", fname, "cdef");
57 ifstream ifs(filename.c_str());
59 lyxerr << "Unable to open character set file" << endl;
60 return true; // no definition, use 7-bit ascii
65 // Ok, I'll be the first to admit that this is probably not
66 // the fastest way to parse the cdef files, but I though it
67 // was a bit neat. Anyway it is wrong to use the lyxlex parse
68 // without the use of a keyword table.
69 regex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
70 while (getline(ifs, line)) {
71 #ifndef USE_INCLUDED_STRING
76 if (regex_match(STRCONV(line), sub, reg)) {
77 int const n = atoi(STRCONV(sub.str(1)));
78 string const str = STRCONV(sub.str(2));
79 if (lyxerr.debugging(Debug::KBMAP))
80 lyxerr << "Chardef: " << n
81 << " to [" << str << ']' << endl;
85 lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
90 pair<bool, int> const CharacterSet::encodeString(string const & str) const
92 lyxerr[Debug::KBMAP] << "Checking if we know [" << str << ']' << endl;
95 Cdef::const_iterator cit = map_.find(str);
96 if (cit != map_.end()) {
100 lyxerr[Debug::KBMAP] << " "
101 << (ret ? "yes we" : "no we don't")
102 << " know [" << str << ']' << endl;
103 return make_pair(ret, val);
107 string const & CharacterSet::getName() const