7 #include "support/filetools.h" // LibFileSearch
9 #include "math_inset.h"
10 #include "math_parser.h"
29 bool correct(MathAtom & at, char c) const;
31 bool read(istream & is);
33 void write(ostream & os) const;
44 bool Correction::read(istream & is)
53 mathed_parse_cell(ar1, s1);
54 mathed_parse_cell(ar3, s3);
55 if (ar1.size() != 1 || ar3.size() != 1)
64 void Correction::write(ostream & os) const
66 os << "from: '" << from1_ << "' and '" << from2_
67 << "' to '" << to_ << '\'' << endl;
71 bool Correction::correct(MathAtom & at, char c) const
73 //lyxerr[Debug::MATHED]
74 // << "trying to correct ar: " << at << " from: '" << from1_ << '\'' << endl;
77 if (!at->match(from1_))
80 << "match found! subst in " << at
81 << " from: '" << from1_ << "' to '" << to_ << '\'' << endl;
87 istream & operator>>(istream & is, Correction & corr)
94 ostream & operator<<(ostream & os, Correction & corr)
106 typedef vector<Correction>::const_iterator const_iterator;
110 void insert(const Correction & corr) { data_.push_back(corr); }
112 bool correct(MathAtom & at, char c) const;
115 vector<Correction> data_;
119 bool Corrections::correct(MathAtom & at, char c) const
121 for (const_iterator it = data_.begin(); it != data_.end(); ++it)
122 if (it->correct(at, c))
128 Corrections theCorrections;
130 void initAutoCorrect()
132 lyxerr[Debug::MATHED] << "reading autocorrect file" << endl;
133 string const file = LibFileSearch(string(), "autocorrect");
135 lyxerr << "Could not find autocorrect file" << endl;
140 ifstream is(file.c_str());
141 while (getline(is, line)) {
142 if (line.size() == 0 || line[0] == '#') {
143 //lyxerr[Debug::MATHED] << "ignoring line '" << line << '\'' << endl;
146 istringstream il(STRCONV(line));
148 //lyxerr[Debug::MATHED] << "line '" << line << '\'' << endl;
151 //lyxerr[Debug::MATHED] << "parsed: '" << corr << '\'' << endl;
152 theCorrections.insert(corr);
156 lyxerr[Debug::MATHED] << "done reading autocorrections." << endl;
163 bool math_autocorrect(MathAtom & at, char c)
165 static bool initialized = false;
172 return theCorrections.correct(at, c);