lyx_mirror/src/chset.C
Jean-Marc Lasgouttes d41e87f91e Small tweaks
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@320 a592a061-630c-0410-9148-cb99ea01b6c8
1999-11-17 15:05:26 +00:00

68 lines
1.5 KiB
C

#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include <fstream>
using std::ifstream;
#include "chset.h"
#include "support/filetools.h"
#include "support/LRegex.h"
#include "support/LSubstring.h"
#include "debug.h"
bool CharacterSet::loadFile(string const & fname)
{
map_.clear();
name_.clear();
if (fname.empty() || fname == "ascii")
return true; // ascii 7-bit
// open definition file
lyxerr[Debug::KBMAP]
<< "Reading keymap file " << fname << ".cdef" << endl;
string filename = LibFileSearch("kbd", fname.c_str(), "cdef");
ifstream ifs(filename.c_str());
if (!ifs) {
lyxerr << "Unable to open keymap file" << endl;
return true; // no definition, use 7-bit ascii
}
name_ = fname;
string str;
int n;
string line;
LRegex reg("^([12][0-9][0-9])[ \t]+\"([^ ]+)\".*");
while(getline(ifs, line)) {
if (reg.exact_match(line)) {
LRegex::SubMatches const & sub = reg.exec(line);
n = atoi(line.substr(sub[1].first,
sub[1].second).c_str());
str = LSubstring(line, sub[2].first, sub[2].second);
if (lyxerr.debugging(Debug::KBMAP))
lyxerr << "Chardef: " << n
<< " to [" << str << "]" << endl;
map_[str] = n;
}
}
lyxerr[Debug::KBMAP] << "End of parsing of .cdef file." << endl;
return false;
}
bool CharacterSet::encodeString(string & str) const
{
Cdef::const_iterator cit = map_.find(str);
if (cit != map_.end()) return true;
return false;
}
string const & CharacterSet::getName() const
{
return name_;
}