10 #include "support/filetools.h" // LibFileSearch
11 #include "math_data.h"
12 #include "math_inset.h"
13 #include "math_parser.h"
32 bool correct(MathAtom & at, char c) const;
34 bool read(istream & is);
36 void write(ostream & os) const;
47 bool Correction::read(istream & is)
56 mathed_parse_cell(ar1, s1);
57 mathed_parse_cell(ar3, s3);
58 if (ar1.size() != 1 || ar3.size() != 1)
67 void Correction::write(ostream & os) const
69 os << "from: '" << from1_ << "' and '" << from2_
70 << "' to '" << to_ << "'" << endl;
74 bool Correction::correct(MathAtom & at, char c) const
76 //lyxerr[Debug::MATHED]
77 // << "trying to correct ar: " << at << " from: '" << from1_ << "'" << endl;
80 if (!at->match(from1_))
83 << "match found! subst in " << at
84 << " from: '" << from1_ << "' to '" << to_ << "'" << endl;
90 istream & operator>>(istream & is, Correction & corr)
97 ostream & operator<<(ostream & os, Correction & corr)
109 typedef vector<Correction>::const_iterator const_iterator;
113 void insert(const Correction & corr) { data_.push_back(corr); }
115 bool correct(MathAtom & at, char c) const;
118 vector<Correction> data_;
122 bool Corrections::correct(MathAtom & at, char c) const
124 for (const_iterator it = data_.begin(); it != data_.end(); ++it)
125 if (it->correct(at, c))
131 Corrections theCorrections;
133 void initAutoCorrect()
135 lyxerr[Debug::MATHED] << "reading autocorrect file" << endl;
136 string const file = LibFileSearch(string(), "autocorrect");
138 lyxerr << "Could not find autocorrect file" << endl;
143 ifstream is(file.c_str());
144 while (getline(is, line)) {
145 if (line.size() == 0 || line[0] == '#') {
146 //lyxerr[Debug::MATHED] << "ignoring line '" << line << "'" << endl;
149 istringstream il(line);
150 //lyxerr[Debug::MATHED] << "line '" << line << "'" << endl;
153 //lyxerr[Debug::MATHED] << "parsed: '" << corr << "'" << endl;
154 theCorrections.insert(corr);
158 lyxerr[Debug::MATHED] << "done reading autocorrections." << endl;
165 bool math_autocorrect(MathAtom & at, char c)
167 static bool initialized = false;
174 return theCorrections.correct(at, c);