6 #include "support/filetools.h" // LibFileSearch
8 #include "math_inset.h"
9 #include "math_parser.h"
28 bool correct(MathAtom & at, char c) const;
30 bool read(istream & is);
32 void write(ostream & os) const;
43 bool Correction::read(istream & is)
52 mathed_parse_cell(ar1, s1);
53 mathed_parse_cell(ar3, s3);
54 if (ar1.size() != 1 || ar3.size() != 1)
63 void Correction::write(ostream & os) const
65 os << "from: '" << from1_ << "' and '" << from2_
66 << "' to '" << to_ << "'" << endl;
70 bool Correction::correct(MathAtom & at, char c) const
72 //lyxerr[Debug::MATHED]
73 // << "trying to correct ar: " << at << " from: '" << from1_ << "'" << endl;
76 if (!at->match(from1_.nucleus()))
79 << "match found! subst in " << at
80 << " from: '" << from1_ << "' to '" << to_ << "'" << endl;
86 istream & operator>>(istream & is, Correction & corr)
93 ostream & operator<<(ostream & os, Correction & corr)
105 typedef vector<Correction>::const_iterator const_iterator;
109 void insert(const Correction & corr) { data_.push_back(corr); }
111 bool correct(MathAtom & at, char c) const;
114 vector<Correction> data_;
118 bool Corrections::correct(MathAtom & at, char c) const
120 for (const_iterator it = data_.begin(); it != data_.end(); ++it)
121 if (it->correct(at, c))
127 Corrections theCorrections;
129 void initAutoCorrect()
131 lyxerr[Debug::MATHED] << "reading autocorrect file" << endl;
132 string const file = LibFileSearch(string(), "autocorrect");
134 lyxerr << "Could not find autocorrect file" << endl;
139 ifstream is(file.c_str());
140 while (getline(is, line)) {
141 if (line.size() == 0 || line[0] == '#') {
142 //lyxerr[Debug::MATHED] << "ignoring line '" << line << "'" << endl;
145 istringstream il(line);
146 //lyxerr[Debug::MATHED] << "line '" << line << "'" << endl;
149 //lyxerr[Debug::MATHED] << "parsed: '" << corr << "'" << endl;
150 theCorrections.insert(corr);
154 lyxerr[Debug::MATHED] << "done reading autocorrections." << endl;
161 bool math_autocorrect(MathAtom & at, char c)
163 static bool initialized = false;
170 return theCorrections.correct(at, c);