6 #include "support/filetools.h" // LibFileSearch
8 #include "math_inset.h"
9 #include "math_parser.h"
15 using namespace lyx::support;
30 bool correct(MathAtom & at, char c) const;
32 bool read(istream & is);
34 void write(ostream & os) const;
45 bool Correction::read(istream & is)
54 mathed_parse_cell(ar1, s1);
55 mathed_parse_cell(ar3, s3);
56 if (ar1.size() != 1 || ar3.size() != 1)
65 void Correction::write(ostream & os) const
67 os << "from: '" << from1_ << "' and '" << from2_
68 << "' to '" << to_ << '\'' << endl;
72 bool Correction::correct(MathAtom & at, char c) const
74 //lyxerr[Debug::MATHED]
75 // << "trying to correct ar: " << at << " from: '" << from1_ << '\'' << endl;
78 if (!at->match(from1_))
81 << "match found! subst in " << at
82 << " from: '" << from1_ << "' to '" << to_ << '\'' << endl;
88 istream & operator>>(istream & is, Correction & corr)
95 ostream & operator<<(ostream & os, Correction & corr)
107 typedef vector<Correction>::const_iterator const_iterator;
111 void insert(const Correction & corr) { data_.push_back(corr); }
113 bool correct(MathAtom & at, char c) const;
116 vector<Correction> data_;
120 bool Corrections::correct(MathAtom & at, char c) const
122 for (const_iterator it = data_.begin(); it != data_.end(); ++it)
123 if (it->correct(at, c))
129 Corrections theCorrections;
131 void initAutoCorrect()
133 lyxerr[Debug::MATHED] << "reading autocorrect file" << endl;
134 string const file = LibFileSearch(string(), "autocorrect");
136 lyxerr << "Could not find autocorrect file" << endl;
141 ifstream is(file.c_str());
142 while (getline(is, line)) {
143 if (line.size() == 0 || line[0] == '#') {
144 //lyxerr[Debug::MATHED] << "ignoring line '" << line << '\'' << endl;
147 istringstream il(STRCONV(line));
149 //lyxerr[Debug::MATHED] << "line '" << line << '\'' << endl;
152 //lyxerr[Debug::MATHED] << "parsed: '" << corr << '\'' << endl;
153 theCorrections.insert(corr);
157 lyxerr[Debug::MATHED] << "done reading autocorrections." << endl;
164 bool math_autocorrect(MathAtom & at, char c)
166 static bool initialized = false;
173 return theCorrections.correct(at, c);