6 #include "support/filetools.h" // LibFileSearch
8 #include "math_inset.h"
9 #include "math_parser.h"
27 bool correct(MathAtom & at, char c) const;
29 bool read(istream & is);
31 void write(ostream & os) const;
42 bool Correction::read(istream & is)
49 mathed_parse_cell(ar1, s1);
50 mathed_parse_cell(ar3, s3);
51 if (ar1.size() != 1 || s2.size() != 1 || ar3.size() !=1)
60 void Correction::write(ostream & os) const
62 os << "from: '" << from1_ << "' and '" << from2_
63 << "' to '" << to_ << "'" << endl;
67 bool Correction::correct(MathAtom & at, char c) const
69 //lyxerr[Debug::MATHED]
70 // << "trying to correct ar: " << at << " from: '" << from1_ << "'" << endl;
73 if (!at->match(from1_.nucleus()))
76 << "match found! subst in " << at
77 << " from: '" << from1_ << "' to '" << to_ << "'" << endl;
83 istream & operator>>(istream & is, Correction & corr)
90 ostream & operator<<(ostream & os, Correction & corr)
102 typedef vector<Correction>::const_iterator const_iterator;
106 void insert(const Correction & corr) { data_.push_back(corr); }
108 bool correct(MathAtom & at, char c) const;
111 vector<Correction> data_;
115 bool Corrections::correct(MathAtom & at, char c) const
117 for (const_iterator it = data_.begin(); it != data_.end(); ++it)
118 if (it->correct(at, c))
124 Corrections theCorrections;
126 void initAutoCorrect()
128 lyxerr[Debug::MATHED] << "reading autocorrect file" << endl;
129 string const file = LibFileSearch(string(), "autocorrect");
131 lyxerr << "Could not find autocorrect file" << endl;
136 ifstream is(file.c_str());
137 while (getline(is, line)) {
138 if (line.size() == 0 || line[0] == '#') {
139 //lyxerr[Debug::MATHED] << "ignoring line '" << line << "'" << endl;
142 istringstream il(line);
143 //lyxerr[Debug::MATHED] << "line '" << line << "'" << endl;
146 //lyxerr[Debug::MATHED] << "parsed: '" << corr << "'" << endl;
147 theCorrections.insert(corr);
151 lyxerr[Debug::MATHED] << "done reading autocorrections." << endl;
158 bool math_autocorrect(MathAtom & at, char c)
160 static bool initialized = false;
167 return theCorrections.correct(at, c);