]> git.lyx.org Git - lyx.git/blob - src/chset.C
white-space changes, removed definitions.h several enum changes because of this,...
[lyx.git] / src / chset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include <fstream>
8
9 #include "chset.h"
10 #include "support/filetools.h"
11 #include "support/LRegex.h"
12 #include "support/LSubstring.h"
13 #include "debug.h"
14
15 bool CharacterSet::loadFile(string const & fname)
16 {
17         map_.clear();
18         name_.clear();
19         
20         if (fname.empty() || fname == "ascii") 
21                 return true;    // ascii 7-bit
22         
23         // open definition file
24         lyxerr[Debug::KBMAP]
25                 << "Reading keymap file " << fname << ".cdef" << endl;
26         string filename = LibFileSearch("kbd", fname.c_str(), "cdef");
27         ifstream ifs(filename.c_str());
28         if (!ifs) {
29                 lyxerr << "Unable to open keymap file" << endl;
30                 return true;            // no definition, use 7-bit ascii
31         }
32         name_ = fname;
33         
34         string str;
35         int n;
36         string line;
37         LRegex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
38         while(getline(ifs, line)) {
39                 if (reg.exact_match(line)) {
40                         LRegex::SubMatches const & sub = reg.exec(line);
41                         n = atoi(line.substr(sub[1].first,
42                                              sub[1].second).c_str());
43                         str = LSubstring(line, sub[2].first, sub[2].second);
44                         if (lyxerr.debugging(Debug::KBMAP))
45                                 lyxerr << "Chardef: " << n
46                                        << " to [" << str << "]" << endl;
47                         map_[str] = n;
48                 }
49         }
50         lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
51         return false;
52 }
53
54
55 bool CharacterSet::encodeString(string & str) const
56 {
57         Cdef::const_iterator cit = map_.find(str);
58         if (cit != map_.end()) return true;
59         return false;
60 }
61
62
63 string const & CharacterSet::getName() const
64 {
65         return name_;
66 }