]> git.lyx.org Git - lyx.git/blobdiff - src/Lexer.cpp
Allow using \binom without amsmath and add support for \brace and \brack
[lyx.git] / src / Lexer.cpp
index a6418ef040dfd975240daab372b46bc80c443a6e..fd9a1f362c302ce3460d7a2f076a6ab5c05c685b 100644 (file)
 
 #include "Lexer.h"
 
-#include "support/debug.h"
-
 #include "support/convert.h"
+#include "support/debug.h"
+#include "support/FileName.h"
 #include "support/filetools.h"
 #include "support/gzstream.h"
 #include "support/lstrings.h"
 #include "support/lyxalgo.h"
 #include "support/types.h"
-#include "support/unicode.h"
-
-#include <boost/noncopyable.hpp>
 
 #include <functional>
 #include <istream>
 #include <stack>
-#include <sstream>
 #include <vector>
 
 using namespace std;
+using namespace lyx::support;
 
 namespace lyx {
 
-using support::compare_ascii_no_case;
-using support::FileName;
-using support::isStrDbl;
-using support::isStrInt;
-using support::ltrim;
-using support::makeDisplayPath;
-using support::prefixIs;
-using support::split;
-using support::subst;
-using support::trim;
-
-
 //////////////////////////////////////////////////////////////////////
 //
 // Lexer::Pimpl
@@ -57,26 +42,26 @@ using support::trim;
 
 
 ///
-class Lexer::Pimpl : boost::noncopyable {
+class Lexer::Pimpl {
 public:
        ///
        Pimpl(keyword_item * tab, int num);
        ///
-       std::string const getString() const;
+       string const getString() const;
        ///
        docstring const getDocString() const;
        ///
-       void printError(std::string const & message) const;
+       void printError(string const & message) const;
        ///
-       void printTable(std::ostream & os);
+       void printTable(ostream & os);
        ///
        void pushTable(keyword_item * tab, int num);
        ///
        void popTable();
        ///
-       bool setFile(support::FileName const & filename);
+       bool setFile(FileName const & filename);
        ///
-       void setStream(std::istream & i);
+       void setStream(istream & i);
        ///
        void setCommentChar(char c);
        ///
@@ -92,42 +77,46 @@ public:
        /// test if there is a pushed token or the stream is ok
        bool inputAvailable();
        ///
-       void pushToken(std::string const &);
+       void pushToken(string const &);
        /// fb_ is only used to open files, the stream is accessed through is.
-       std::filebuf fb_;
+       filebuf fb_;
 
        /// gz_ is only used to open files, the stream is accessed through is.
        gz::gzstreambuf gz_;
 
        /// the stream that we use.
-       std::istream is;
+       istream is;
        ///
-       std::string name;
+       string name;
        ///
        keyword_item * table;
        ///
        int no_items;
        ///
-       std::string buff;
+       string buff;
        ///
        int status;
        ///
        int lineno;
        ///
-       std::string pushTok;
+       string pushTok;
        ///
        char commentChar;
 private:
+       /// non-copyable
+       Pimpl(Pimpl const &);
+       void operator=(Pimpl const &);
+
        ///
        void verifyTable();
        ///
-       class pushed_table {
+       class PushedTable {
        public:
                ///
-               pushed_table()
+               PushedTable()
                        : table_elem(0), table_siz(0) {}
                ///
-               pushed_table(keyword_item * ki, int siz)
+               PushedTable(keyword_item * ki, int siz)
                        : table_elem(ki), table_siz(siz) {}
                ///
                keyword_item * table_elem;
@@ -135,15 +124,15 @@ private:
                int table_siz;
        };
        ///
-       std::stack<pushed_table> pushed;
+       stack<PushedTable> pushed;
 };
 
 
 
 namespace {
 
-class compare_tags
-       : public std::binary_function<keyword_item, keyword_item, bool> {
+class CompareTags
+       : public binary_function<keyword_item, keyword_item, bool> {
 public:
        // used by lower_bound, sort and sorted
        bool operator()(keyword_item const & a, keyword_item const & b) const
@@ -201,14 +190,14 @@ void Lexer::Pimpl::verifyTable()
 {
        // Check if the table is sorted and if not, sort it.
        if (table
-           && !lyx::sorted(table, table + no_items, compare_tags())) {
+           && !lyx::sorted(table, table + no_items, CompareTags())) {
                lyxerr << "The table passed to Lexer is not sorted!\n"
                       << "Tell the developers to fix it!" << endl;
                // We sort it anyway to avoid problems.
                lyxerr << "\nUnsorted:" << endl;
                printTable(lyxerr);
 
-               sort(table, table + no_items, compare_tags());
+               sort(table, table + no_items, CompareTags());
                lyxerr << "\nSorted:" << endl;
                printTable(lyxerr);
        }
@@ -217,7 +206,7 @@ void Lexer::Pimpl::verifyTable()
 
 void Lexer::Pimpl::pushTable(keyword_item * tab, int num)
 {
-       pushed_table tmppu(table, no_items);
+       PushedTable tmppu(table, no_items);
        pushed.push(tmppu);
 
        table = tab;
@@ -234,7 +223,7 @@ void Lexer::Pimpl::popTable()
                return;
        }
 
-       pushed_table tmp = pushed.top();
+       PushedTable tmp = pushed.top();
        pushed.pop();
        table = tmp.table_elem;
        no_items = tmp.table_siz;
@@ -496,7 +485,7 @@ int Lexer::Pimpl::search_kw(char const * const tag) const
        keyword_item search_tag = { tag, 0 };
        keyword_item * res =
                lower_bound(table, table + no_items,
-                           search_tag, compare_tags());
+                           search_tag, CompareTags());
        // use the compare_ascii_no_case instead of compare_no_case,
        // because in turkish, 'i' is not the lowercase version of 'I',
        // and thus turkish locale breaks parsing of tags.
@@ -584,7 +573,8 @@ bool Lexer::Pimpl::nextToken()
                                } while (c >= ' ' && c != '\\' && is);
                        }
 
-                       if (c == '\\') is.putback(c); // put it back
+                       if (c == '\\')
+                               is.putback(c); // put it back
                        status = LEX_TOKEN;
                }
 
@@ -680,7 +670,7 @@ void Lexer::printError(string const & message) const
 }
 
 
-bool Lexer::setFile(support::FileName const & filename)
+bool Lexer::setFile(FileName const & filename)
 {
        return pimpl_->setFile(filename);
 }
@@ -768,7 +758,8 @@ docstring const Lexer::getDocString() const
 // explicit tokens (JMarc)
 string const Lexer::getLongString(string const & endtoken)
 {
-       string str, prefix;
+       string str;
+       string prefix;
        bool firstline = true;
 
        while (pimpl_->is) { //< eatLine only reads from is, not from pushTok
@@ -786,7 +777,7 @@ string const Lexer::getLongString(string const & endtoken)
 
                string tmpstr = getString();
                if (firstline) {
-                       string::size_type i(tmpstr.find_first_not_of(' '));
+                       size_t i = tmpstr.find_first_not_of(' ');
                        if (i != string::npos)
                                prefix = tmpstr.substr(0, i);
                        firstline = false;
@@ -795,16 +786,14 @@ string const Lexer::getLongString(string const & endtoken)
 
                // further lines in long strings may have the same
                // whitespace prefix as the first line. Remove it.
-               if (prefix.length() && prefixIs(tmpstr, prefix)) {
+               if (prefix.length() && prefixIs(tmpstr, prefix))
                        tmpstr.erase(0, prefix.length() - 1);
-               }
 
                str += ltrim(tmpstr, "\t") + '\n';
        }
 
-       if (!pimpl_->is) {
+       if (!pimpl_->is)
                printError("Long string not ended by `" + endtoken + '\'');
-       }
 
        return str;
 }
@@ -851,7 +840,7 @@ void Lexer::pushToken(string const & pt)
 
 Lexer::operator void const *() const
 {
-       // This behaviour is NOT the same as the std::streams which would
+       // This behaviour is NOT the same as the streams which would
        // use fail() here. However, our implementation of getString() et al.
        // can cause the eof() and fail() bits to be set, even though we
        // haven't tried to read 'em.
@@ -865,7 +854,7 @@ bool Lexer::operator!() const
 }
 
 
-Lexer & Lexer::operator>>(std::string & s)
+Lexer & Lexer::operator>>(string & s)
 {
        if (isOK()) {
                next();
@@ -937,12 +926,15 @@ Lexer & Lexer::operator>>(bool & s)
 }
 
 
-/// quotes a string, e.g. for use in preferences files or as an argument of the "log" dialog
+// quotes a string, e.g. for use in preferences files or as an argument
+// of the "log" dialog
 string const Lexer::quoteString(string const & arg)
 {
-       std::ostringstream os;
-       os << '"' << subst(subst(arg, "\\", "\\\\"), "\"", "\\\"") << '"';
-       return os.str();
+       string res;
+       res += '"';
+       res += subst(subst(arg, "\\", "\\\\"), "\"", "\\\"");
+       res += '"';
+       return res;
 }